diff --git a/.gitignore b/.gitignore index 314af056f..467138d89 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,6 @@ # project custom build dist -packages/*/lib/ -packages/*/es/ -packages/*/dist/ -packages/*/output/ -packages/*/temp/ -packages/demo/ package-lock.json yarn.lock pnpm-lock.yaml diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts deleted file mode 100644 index 7cd2bfba6..000000000 --- a/packages/core/src/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './preference'; -export * from './hotkey'; diff --git a/packages/core/test/command.test.ts b/packages/core/test/command.test.ts deleted file mode 100644 index bb2e15943..000000000 --- a/packages/core/test/command.test.ts +++ /dev/null @@ -1,326 +0,0 @@ -import { Command } from '../src/command'; - -describe('Command', () => { - let commandInstance; - let mockHandler; - - beforeEach(() => { - commandInstance = new Command(); - mockHandler = jest.fn(); - }); - - describe('registerCommand', () => { - it('should register a command successfully', () => { - const command = { - name: 'testCommand', - handler: mockHandler, - }; - commandInstance.registerCommand(command, { commandScope: 'testScope' }); - - const registeredCommand = commandInstance.listCommands().find(c => c.name === 'testScope:testCommand'); - expect(registeredCommand).toBeDefined(); - expect(registeredCommand.name).toBe('testScope:testCommand'); - }); - - it('should throw an error if commandScope is not provided', () => { - const command = { - name: 'testCommand', - handler: mockHandler, - }; - - expect(() => { - commandInstance.registerCommand(command); - }).toThrow('plugin meta.commandScope is required.'); - }); - - it('should throw an error if command is already registered', () => { - const command = { - name: 'testCommand', - handler: mockHandler, - }; - commandInstance.registerCommand(command, { commandScope: 'testScope' }); - - expect(() => { - commandInstance.registerCommand(command, { commandScope: 'testScope' }); - }).toThrow(`Command 'testCommand' is already registered.`); - }); - }); - - afterEach(() => { - jest.clearAllMocks(); - }); -}); - -describe('unregisterCommand', () => { - let commandInstance; - let mockHandler; - - beforeEach(() => { - commandInstance = new Command(); - mockHandler = jest.fn(); - // 先注册一个命令以便之后注销 - const command = { - name: 'testCommand', - handler: mockHandler, - }; - commandInstance.registerCommand(command, { commandScope: 'testScope' }); - }); - - it('should unregister a command successfully', () => { - const commandName = 'testScope:testCommand'; - expect(commandInstance.listCommands().find(c => c.name === commandName)).toBeDefined(); - - commandInstance.unregisterCommand(commandName); - - expect(commandInstance.listCommands().find(c => c.name === commandName)).toBeUndefined(); - }); - - it('should throw an error if the command is not registered', () => { - const nonExistingCommandName = 'testScope:nonExistingCommand'; - expect(() => { - commandInstance.unregisterCommand(nonExistingCommandName); - }).toThrow(`Command '${nonExistingCommandName}' is not registered.`); - }); - - afterEach(() => { - jest.clearAllMocks(); - }); -}); - -describe('executeCommand', () => { - let commandInstance; - let mockHandler; - - beforeEach(() => { - commandInstance = new Command(); - mockHandler = jest.fn(); - // 注册一个带参数校验的命令 - const command = { - name: 'testCommand', - handler: mockHandler, - parameters: [ - { name: 'param1', propType: 'string' }, - { name: 'param2', propType: 'number' } - ], - }; - commandInstance.registerCommand(command, { commandScope: 'testScope' }); - }); - - it('should execute a command successfully', () => { - const commandName = 'testScope:testCommand'; - const args = { param1: 'test', param2: 42 }; - - commandInstance.executeCommand(commandName, args); - - expect(mockHandler).toHaveBeenCalledWith(args); - }); - - it('should throw an error if the command is not registered', () => { - const nonExistingCommandName = 'testScope:nonExistingCommand'; - expect(() => { - commandInstance.executeCommand(nonExistingCommandName, {}); - }).toThrow(`Command '${nonExistingCommandName}' is not registered.`); - }); - - it('should throw an error if arguments are invalid', () => { - const commandName = 'testScope:testCommand'; - const invalidArgs = { param1: 'test', param2: 'not-a-number' }; // param2 should be a number - - expect(() => { - commandInstance.executeCommand(commandName, invalidArgs); - }).toThrow(`Command '${commandName}' arguments param2 is invalid.`); - }); - - it('should handle errors thrown by the command handler', () => { - const commandName = 'testScope:testCommand'; - const args = { param1: 'test', param2: 42 }; - const errorMessage = 'Command handler error'; - mockHandler.mockImplementation(() => { - throw new Error(errorMessage); - }); - - expect(() => { - commandInstance.executeCommand(commandName, args); - }).toThrow(errorMessage); - }); - - afterEach(() => { - jest.clearAllMocks(); - }); -}); - -describe('batchExecuteCommand', () => { - let commandInstance; - let mockHandler; - let mockExecuteTransaction; - let mockPluginContext; - - beforeEach(() => { - commandInstance = new Command(); - mockHandler = jest.fn(); - mockExecuteTransaction = jest.fn(callback => callback()); - mockPluginContext = { - common: { - utils: { - executeTransaction: mockExecuteTransaction - } - } - }; - - // 注册几个命令 - const command1 = { - name: 'testCommand1', - handler: mockHandler, - }; - const command2 = { - name: 'testCommand2', - handler: mockHandler, - }; - commandInstance.registerCommand(command1, { commandScope: 'testScope' }); - commandInstance.registerCommand(command2, { commandScope: 'testScope' }); - }); - - it('should execute a batch of commands', () => { - const commands = [ - { name: 'testScope:testCommand1', args: { param: 'value1' } }, - { name: 'testScope:testCommand2', args: { param: 'value2' } }, - ]; - - commandInstance.batchExecuteCommand(commands, mockPluginContext); - - expect(mockExecuteTransaction).toHaveBeenCalledTimes(1); - expect(mockHandler).toHaveBeenCalledWith({ param: 'value1' }); - expect(mockHandler).toHaveBeenCalledWith({ param: 'value2' }); - }); - - it('should not execute anything if commands array is empty', () => { - commandInstance.batchExecuteCommand([], mockPluginContext); - - expect(mockExecuteTransaction).not.toHaveBeenCalled(); - expect(mockHandler).not.toHaveBeenCalled(); - }); - - it('should handle errors thrown during command execution', () => { - const errorMessage = 'Command handler error'; - mockHandler.mockImplementation(() => { - throw new Error(errorMessage); - }); - - const commands = [ - { name: 'testScope:testCommand1', args: { param: 'value1' } }, - { name: 'testScope:testCommand2', args: { param: 'value2' } }, - ]; - - expect(() => { - commandInstance.batchExecuteCommand(commands, mockPluginContext); - }).toThrow(errorMessage); - - expect(mockExecuteTransaction).toHaveBeenCalledTimes(1); // Still called once - }); - - afterEach(() => { - jest.clearAllMocks(); - }); -}); - -describe('listCommands', () => { - let commandInstance; - let mockHandler; - - beforeEach(() => { - commandInstance = new Command(); - mockHandler = jest.fn(); - }); - - it('should list all registered commands', () => { - // 注册几个命令 - const command1 = { - name: 'testCommand1', - handler: mockHandler, - description: 'Test Command 1', - parameters: [{ name: 'param1', propType: 'string' }] - }; - const command2 = { - name: 'testCommand2', - handler: mockHandler, - description: 'Test Command 2', - parameters: [{ name: 'param2', propType: 'number' }] - }; - commandInstance.registerCommand(command1, { commandScope: 'testScope' }); - commandInstance.registerCommand(command2, { commandScope: 'testScope' }); - - const listedCommands = commandInstance.listCommands(); - - expect(listedCommands.length).toBe(2); - expect(listedCommands).toEqual(expect.arrayContaining([ - expect.objectContaining({ - name: 'testScope:testCommand1', - description: 'Test Command 1', - parameters: [{ name: 'param1', propType: 'string' }] - }), - expect.objectContaining({ - name: 'testScope:testCommand2', - description: 'Test Command 2', - parameters: [{ name: 'param2', propType: 'number' }] - }) - ])); - }); - - it('should return an empty array if no commands are registered', () => { - const listedCommands = commandInstance.listCommands(); - expect(listedCommands).toEqual([]); - }); - - afterEach(() => { - jest.clearAllMocks(); - }); -}); - -describe('onCommandError', () => { - let commandInstance; - let mockHandler; - let mockErrorHandler1; - let mockErrorHandler2; - - beforeEach(() => { - commandInstance = new Command(); - mockHandler = jest.fn(); - mockErrorHandler1 = jest.fn(); - mockErrorHandler2 = jest.fn(); - - // 注册一个命令,该命令会抛出错误 - const command = { - name: 'testCommand', - handler: () => { - throw new Error('Command execution failed'); - }, - }; - commandInstance.registerCommand(command, { commandScope: 'testScope' }); - }); - - it('should call all registered error handlers when a command throws an error', () => { - const commandName = 'testScope:testCommand'; - commandInstance.onCommandError(mockErrorHandler1); - commandInstance.onCommandError(mockErrorHandler2); - - expect(() => { - commandInstance.executeCommand(commandName, {}); - }).not.toThrow(); - - // 确保所有错误处理函数都被调用,并且传递了正确的参数 - expect(mockErrorHandler1).toHaveBeenCalledWith(commandName, expect.any(Error)); - expect(mockErrorHandler2).toHaveBeenCalledWith(commandName, expect.any(Error)); - }); - - it('should throw the error if no error handlers are registered', () => { - const commandName = 'testScope:testCommand'; - - expect(() => { - commandInstance.executeCommand(commandName, {}); - }).toThrow('Command execution failed'); - }); - - afterEach(() => { - jest.clearAllMocks(); - }); -}); diff --git a/packages/core/tsconfig.declaration.json b/packages/core/tsconfig.declaration.json deleted file mode 100644 index 54e57efbd..000000000 --- a/packages/core/tsconfig.declaration.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "emitDeclarationOnly": true, - "declaration": true, - "outDir": "temp", - "stripInternal": true, - "paths": {} - } -} diff --git a/packages/core/tsconfig.json b/packages/core/tsconfig.json deleted file mode 100644 index 0590f5d80..000000000 --- a/packages/core/tsconfig.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "../../tsconfig.json", - "compilerOptions": { - "outDir": "dist" - }, - "include": ["src", "__tests__", "src/configuration.ts"] -} diff --git a/packages/core/vite.config.ts b/packages/core/vite.config.ts deleted file mode 100644 index 5370172d9..000000000 --- a/packages/core/vite.config.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { defineConfig } from 'vite'; -import baseConfigFn from '../../vite.base.config' - -export default defineConfig(async () => { - return baseConfigFn({ - name: 'LowCodeEditorCore', - }) -}); diff --git a/packages/core/package.json b/packages/engine-core/package.json similarity index 63% rename from packages/core/package.json rename to packages/engine-core/package.json index 254d8b7cb..97347bcdb 100644 --- a/packages/core/package.json +++ b/packages/engine-core/package.json @@ -1,15 +1,14 @@ { - "name": "@alilc/lowcode-core", - "version": "2.0.0-beta.0", - "description": "Core Api for Ali lowCode engine", - "license": "MIT", + "name": "@ali/lowcode-engine-core", + "description": "", "type": "module", - "main": "dist/low-code-editor-core.js", - "module": "dist/low-code-editor-core.js", + "main": "dist/engine-core.js", + "module": "dist/engine-core.js", "types": "dist/index.d.ts", "exports": { ".": { - "import": "./dist/low-code-editor-core.js", + "import": "./dist/engine-core.js", + "require": "./dist/engine-core.cjs", "types": "./dist/index.d.ts" }, "./dist/": { @@ -17,10 +16,6 @@ "require": "./dist/" } }, - "sideEffects": [ - "*.css", - "*.less" - ], "files": [ "dist", "src", @@ -29,22 +24,18 @@ "scripts": { "build:target": "vite build", "build:dts": "tsc -p tsconfig.declaration.json && node ../../scripts/rollup-dts.mjs", - "test": "vitest", - "test:cov": "" + "test": "vitest" }, + "license": "MIT", "dependencies": { "@alilc/lowcode-shared": "workspace:*", "lodash-es": "^4.17.21" }, "devDependencies": { - "@types/lodash-es": "^4.17.12", - "@types/react": "^18.2.0", - "@types/react-dom": "^18.2.0" + "@types/lodash-es": "^4.17.12" }, "peerDependencies": { - "@alilc/lowcode-shared": "workspace:*", - "react": "^18.2.0", - "react-dom": "^18.2.0" + "@alilc/lowcode-shared": "workspace:*" }, "publishConfig": { "access": "public", @@ -52,7 +43,7 @@ }, "repository": { "type": "http", - "url": "https://github.com/alibaba/lowcode-engine/tree/main/packages/editor-core" + "url": "https://github.com/alibaba/lowcode-engine/tree/main/packages/engine-core" }, "gitHead": "2669f179e6f899d395ce1942d0fe04f9c5ed48a6", "bugs": "https://github.com/alibaba/lowcode-engine/issues", diff --git a/packages/engine-core/src/index.ts b/packages/engine-core/src/index.ts new file mode 100644 index 000000000..e69de29bb diff --git a/packages/engine/tsconfig.declaration.json b/packages/engine-core/tsconfig.declaration.json similarity index 100% rename from packages/engine/tsconfig.declaration.json rename to packages/engine-core/tsconfig.declaration.json diff --git a/packages/types/tsconfig.json b/packages/engine-core/tsconfig.json similarity index 100% rename from packages/types/tsconfig.json rename to packages/engine-core/tsconfig.json diff --git a/packages/engine-core/vite.config.ts b/packages/engine-core/vite.config.ts new file mode 100644 index 000000000..e1ed20a61 --- /dev/null +++ b/packages/engine-core/vite.config.ts @@ -0,0 +1,9 @@ +import { defineConfig } from 'vite'; +import baseConfigFn from '../../vite.base.config'; + +export default defineConfig(async () => { + return baseConfigFn({ + name: 'EngineCore', + defaultFormats: ['es', 'cjs'], + }); +}); diff --git a/packages/core/vitest.config.ts b/packages/engine-core/vitest.config.ts similarity index 100% rename from packages/core/vitest.config.ts rename to packages/engine-core/vitest.config.ts diff --git a/packages/engine/package.json b/packages/engine/package.json index bde4a4a2b..7f70d3f18 100644 --- a/packages/engine/package.json +++ b/packages/engine/package.json @@ -29,28 +29,17 @@ }, "license": "MIT", "dependencies": { - "@alifd/next": "^1.27.8", - "@alilc/lowcode-designer": "workspace:*", - "@alilc/lowcode-core": "workspace:*", - "@alilc/lowcode-workbench": "workspace:*", - "@alilc/lowcode-plugin-command": "workspace:*", - "@alilc/lowcode-plugin-designer": "workspace:*", - "@alilc/lowcode-plugin-outline-pane": "workspace:*", - "@alilc/lowcode-utils": "workspace:*", - "@alilc/lowcode-types": "workspace:*", - "classnames": "^2.5.1", - "prop-types": "^15.7.2", + "@alilc/lowcode-shared": "workspace:*", + "lodash-es": "^4.17.21", "react": "^18.2.0", "react-dom": "^18.2.0" }, "devDependencies": { - "@alifd/theme-lowcode-dark": "^0.2.0", - "@alifd/theme-lowcode-light": "^0.2.0", + "@types/lodash-es": "^4.17.12", "@types/react": "^18.2.0", "@types/react-dom": "^18.2.0" }, "peerDependencies": { - "@alifd/next": "^1.27.8", "react": "^18.2.0", "react-dom": "^18.2.0" }, diff --git a/packages/core/src/command.ts b/packages/engine/src/common/command.ts similarity index 100% rename from packages/core/src/command.ts rename to packages/engine/src/common/command.ts diff --git a/packages/engine/src/plugin/context.ts b/packages/engine/src/common/plugin/context.ts similarity index 100% rename from packages/engine/src/plugin/context.ts rename to packages/engine/src/common/plugin/context.ts diff --git a/packages/engine/src/plugin/index.ts b/packages/engine/src/common/plugin/index.ts similarity index 100% rename from packages/engine/src/plugin/index.ts rename to packages/engine/src/common/plugin/index.ts diff --git a/packages/engine/src/plugin/manager.ts b/packages/engine/src/common/plugin/manager.ts similarity index 100% rename from packages/engine/src/plugin/manager.ts rename to packages/engine/src/common/plugin/manager.ts diff --git a/packages/engine/src/plugin/runtime.ts b/packages/engine/src/common/plugin/runtime.ts similarity index 100% rename from packages/engine/src/plugin/runtime.ts rename to packages/engine/src/common/plugin/runtime.ts diff --git a/packages/engine/src/plugin/types.ts b/packages/engine/src/common/plugin/types.ts similarity index 100% rename from packages/engine/src/plugin/types.ts rename to packages/engine/src/common/plugin/types.ts diff --git a/packages/engine/src/plugin/utils.ts b/packages/engine/src/common/plugin/utils.ts similarity index 100% rename from packages/engine/src/plugin/utils.ts rename to packages/engine/src/common/plugin/utils.ts diff --git a/packages/engine/src/index.ts b/packages/engine/src/index.ts index 8824e5d07..5427b666b 100644 --- a/packages/engine/src/index.ts +++ b/packages/engine/src/index.ts @@ -1,6 +1,3 @@ -import { bootstrapModules, createInstance } from '@alilc/lowcode-core'; -import { EngineMain } from './main'; - export async function init( container?: HTMLElement, options?: IPublicTypeEngineOptions, @@ -11,7 +8,4 @@ export async function init( container.id = 'engine'; document.body.appendChild(container); } - - bootstrapModules(); - createInstance(EngineMain).startup(container); } diff --git a/packages/engine/src/main.ts b/packages/engine/src/main.ts index 269dc07c5..54c392d6f 100644 --- a/packages/engine/src/main.ts +++ b/packages/engine/src/main.ts @@ -1,12 +1,11 @@ -import { Provide } from '@alilc/lowcode-core'; -import { IWorkspaceMainService } from './workspace'; +import { InstantiationService } from '@alilc/lowcode-shared'; -@Provide('EngineMain') -export class EngineMain { - constructor(@IWorkspaceMainService private workspaceMainService: IWorkspaceMainService) {} +export class MainEngineApplication { + instantiationService = new InstantiationService(); - startup(container: HTMLElement): void { - console.log('%c [ container ]-9', 'font-size:13px; background:pink; color:#bf2c9f;', container); - this.workspaceMainService.initialize(); + constructor() { + this.instantiationService.bootstrapModules(); } + + startup(container: HTMLElement): void {} } diff --git a/packages/engine/src/services/command/commandService.ts b/packages/engine/src/services/command/commandService.ts new file mode 100644 index 000000000..14a7f1557 --- /dev/null +++ b/packages/engine/src/services/command/commandService.ts @@ -0,0 +1,8 @@ +import { createDecorator, Provide } from '@alilc/lowcode-shared'; + +export interface ICommandService {} + +export const ICommandService = createDecorator('commandService'); + +@Provide(ICommandService) +export class CommandService implements ICommandService {} diff --git a/packages/core/src/configuration.ts b/packages/engine/src/services/configuration/configuration.ts similarity index 96% rename from packages/core/src/configuration.ts rename to packages/engine/src/services/configuration/configuration.ts index 0a2adc19c..06d1abe48 100644 --- a/packages/core/src/configuration.ts +++ b/packages/engine/src/services/configuration/configuration.ts @@ -1,6 +1,6 @@ import { get as lodashGet, isPlainObject, cloneDeep } from 'lodash-es'; -import { type PlainObject } from '@alilc/lowcode-shared/src/types'; -import { invariant } from '@alilc/lowcode-shared/src/utils'; +import { type PlainObject } from '@alilc/lowcode-shared'; +import { invariant } from '@alilc/lowcode-shared'; export class Configuration { private config: Config; diff --git a/packages/engine/src/services/configuration/configurationService.ts b/packages/engine/src/services/configuration/configurationService.ts new file mode 100644 index 000000000..d41400e76 --- /dev/null +++ b/packages/engine/src/services/configuration/configurationService.ts @@ -0,0 +1,8 @@ +import { createDecorator, Provide } from '@alilc/lowcode-shared'; + +export interface IConfigurationService {} + +export const IConfigurationService = createDecorator('configurationService'); + +@Provide(IConfigurationService) +export class ConfigurationService implements IConfigurationService {} diff --git a/packages/engine/src/workspace/impl.ts b/packages/engine/src/workspace/impl.ts deleted file mode 100644 index 7d6bc8d18..000000000 --- a/packages/engine/src/workspace/impl.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Provide } from '@alilc/lowcode-core'; -import { IWorkspaceMainService } from './interface'; - -@Provide('WorkspaceMainService') -export class WorkspaceMainService implements IWorkspaceMainService { - initialize(): void { - console.log('initialize...'); - } -} diff --git a/packages/engine/src/workspace/index.ts b/packages/engine/src/workspace/index.ts deleted file mode 100644 index fc141f790..000000000 --- a/packages/engine/src/workspace/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './interface'; diff --git a/packages/engine/src/workspace/interface.ts b/packages/engine/src/workspace/interface.ts deleted file mode 100644 index d4572f2b7..000000000 --- a/packages/engine/src/workspace/interface.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { createDecorator } from '@alilc/lowcode-core'; - -export interface IWorkspaceMainService { - initialize(): void; -} - -export const IWorkspaceMainService = createDecorator('WorkspaceMainService'); diff --git a/packages/engine/vite.config.ts b/packages/engine/vite.config.ts index 3194fb105..2a0f25449 100644 --- a/packages/engine/vite.config.ts +++ b/packages/engine/vite.config.ts @@ -1,25 +1,26 @@ import { defineConfig, mergeConfig } from 'vite'; -import baseConfigFn from '../../vite.base.config' +import baseConfigFn from '../../vite.base.config'; export default defineConfig(async () => { const baseConfig = await baseConfigFn({ name: 'AliLowCodeEngine', defaultFormats: ['es', 'cjs'], - }) + }); - return mergeConfig(baseConfig, defineConfig({ - build: { - rollupOptions: { - output: { - // for UMD - globals: { - react: 'React', - 'react-dom': 'ReactDOM', - '@alifd/next': 'Next' + return mergeConfig( + baseConfig, + defineConfig({ + build: { + rollupOptions: { + output: { + // for UMD + globals: { + react: 'React', + 'react-dom': 'ReactDOM', + }, }, }, }, - } - })) + }), + ); }); - diff --git a/packages/react-renderer/src/runtime/createComponent.tsx b/packages/react-renderer/src/runtime/createComponent.tsx index 06ba5dfa3..e95e6a949 100644 --- a/packages/react-renderer/src/runtime/createComponent.tsx +++ b/packages/react-renderer/src/runtime/createComponent.tsx @@ -36,30 +36,15 @@ const lowCodeComponentsCache = new Map(); export function getComponentByName( name: string, - { packageManager, boostsManager }: RenderContext, + { packageManager }: RenderContext, componentOptions: ComponentOptions = {}, ): ReactComponent { const result = lowCodeComponentsCache.get(name) || packageManager.getComponent(name); if (isLowCodeComponentPackage(result)) { const { schema, ...metadata } = result; - const { componentsMap, componentsTree, utils, i18n } = schema; - if (componentsMap.length > 0) { - packageManager.resolveComponentMaps(componentsMap); - } - - const boosts = boostsManager.toExpose(); - - utils?.forEach((util) => boosts.util.add(util)); - - if (i18n) { - Object.keys(i18n).forEach((locale) => { - boosts.intl.addTranslations(locale, i18n[locale]); - }); - } - - const lowCodeComponent = createComponent(componentsTree[0], { + const lowCodeComponent = createComponent(schema, { ...componentOptions, displayName: name, modelOptions: { diff --git a/packages/renderer-core/src/index.ts b/packages/renderer-core/src/index.ts index 0c52e214e..39a390f9f 100644 --- a/packages/renderer-core/src/index.ts +++ b/packages/renderer-core/src/index.ts @@ -3,7 +3,7 @@ export { createRenderer } from './main'; export { definePackageLoader } from './services/package'; export { LifecyclePhase } from './services/lifeCycleService'; export { Widget } from './services/widget'; -export * from './utils/node'; +export * from '../../shared/src/utils/node'; export * from './utils/value'; /* --------------- types ---------------- */ diff --git a/packages/renderer-core/src/services/code-runtime/codeRuntime.ts b/packages/renderer-core/src/services/code-runtime/codeRuntime.ts index 6bc82551f..0782d6b57 100644 --- a/packages/renderer-core/src/services/code-runtime/codeRuntime.ts +++ b/packages/renderer-core/src/services/code-runtime/codeRuntime.ts @@ -6,7 +6,7 @@ import { isJSFunction, } from '@alilc/lowcode-shared'; import { type ICodeScope, CodeScope } from './codeScope'; -import { isNode } from '../../utils/node'; +import { isNode } from '../../../../shared/src/utils/node'; import { mapValue } from '../../utils/value'; import { evaluate } from './evaluate'; diff --git a/packages/renderer-core/src/services/code-runtime/codeScope.ts b/packages/renderer-core/src/services/code-runtime/codeScope.ts index 6bf57bcf7..914aa5f47 100644 --- a/packages/renderer-core/src/services/code-runtime/codeScope.ts +++ b/packages/renderer-core/src/services/code-runtime/codeScope.ts @@ -1,5 +1,5 @@ import { type PlainObject } from '@alilc/lowcode-shared'; -import { trustedGlobals } from '../../utils/globals-es2015'; +import { trustedGlobals } from './globals-es2015'; /* * variables who are impossible to be overwritten need to be escaped from proxy scope for performance reasons diff --git a/packages/renderer-core/src/utils/globals-es2015.ts b/packages/renderer-core/src/services/code-runtime/globals-es2015.ts similarity index 100% rename from packages/renderer-core/src/utils/globals-es2015.ts rename to packages/renderer-core/src/services/code-runtime/globals-es2015.ts diff --git a/packages/renderer-core/src/services/lifeCycleService.ts b/packages/renderer-core/src/services/lifeCycleService.ts index 37ce905f0..c84d70e3b 100644 --- a/packages/renderer-core/src/services/lifeCycleService.ts +++ b/packages/renderer-core/src/services/lifeCycleService.ts @@ -1,12 +1,24 @@ import { Provide, createDecorator, EventEmitter, EventDisposable } from '@alilc/lowcode-shared'; +/** + * 生命周期阶段 + */ export const enum LifecyclePhase { + /** + * 开始 + */ Starting = 1, - + /** + * 配置解析完成 + */ OptionsResolved = 2, - + /** + * 已就绪 + */ Ready = 3, - + /** + * 销毁中 + */ Destroying = 4, } diff --git a/packages/renderer-core/tsconfig.json b/packages/renderer-core/tsconfig.json index 039e0b4d1..5784de4ad 100644 --- a/packages/renderer-core/tsconfig.json +++ b/packages/renderer-core/tsconfig.json @@ -3,5 +3,5 @@ "compilerOptions": { "outDir": "dist" }, - "include": ["src"] + "include": ["src", "../shared/src/utils/node.ts"] } diff --git a/packages/shared/src/types/material.ts b/packages/shared/src/types/material.ts index e4eba25e8..06ee15d71 100644 --- a/packages/shared/src/types/material.ts +++ b/packages/shared/src/types/material.ts @@ -1,5 +1,5 @@ import { Package } from './specs/asset-spec'; -import { Project } from './specs/lowcode-spec'; +import { ComponentTreeRoot } from './specs/lowcode-spec'; export interface ProCodeComponent extends Package { package: string; @@ -11,5 +11,5 @@ export interface LowCodeComponent extends Package { id: string; type: 'lowCode'; componentName: string; - schema: Project; + schema: ComponentTreeRoot; } diff --git a/packages/shared/src/types/specs/asset-spec.ts b/packages/shared/src/types/specs/asset-spec.ts index 28cb51e16..98629bb43 100644 --- a/packages/shared/src/types/specs/asset-spec.ts +++ b/packages/shared/src/types/specs/asset-spec.ts @@ -2,7 +2,7 @@ * https://lowcode-engine.cn/site/docs/specs/assets-spec * 低代码引擎资产包协议规范 */ -import { Project } from './lowcode-spec'; +import { ComponentTreeRoot } from './lowcode-spec'; export interface Package { /** @@ -40,7 +40,7 @@ export interface Package { /** * 低代码组件的 schema 内容 */ - schema?: Project; + schema?: ComponentTreeRoot; /** * 当前资源所依赖的其他资源包的 id 列表 */ diff --git a/packages/shared/src/utils/index.ts b/packages/shared/src/utils/index.ts index 19337a60c..ad1a7a4cc 100644 --- a/packages/shared/src/utils/index.ts +++ b/packages/shared/src/utils/index.ts @@ -5,3 +5,4 @@ export * from './type-guards'; export * from './platform'; export * from './callback'; export * from './async'; +export * from './node'; diff --git a/packages/renderer-core/src/utils/node.ts b/packages/shared/src/utils/node.ts similarity index 98% rename from packages/renderer-core/src/utils/node.ts rename to packages/shared/src/utils/node.ts index d77ce2433..cc18ef1f3 100644 --- a/packages/renderer-core/src/utils/node.ts +++ b/packages/shared/src/utils/node.ts @@ -3,7 +3,7 @@ * fork from: https://github.com/Rich-Harris/estree-walker */ -import { type PlainObject, type Spec } from '@alilc/lowcode-shared'; +import { type PlainObject, type Spec } from '../types'; type Node = Spec.JSNode; diff --git a/packages/types/CHANGELOG.md b/packages/types/CHANGELOG.md deleted file mode 100644 index 5513b477a..000000000 --- a/packages/types/CHANGELOG.md +++ /dev/null @@ -1,1535 +0,0 @@ -# Change Log - -All notable changes to this project will be documented in this file. -See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -## [1.0.55](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.54...v1.0.55) (2021-06-17) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.54](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.53...v1.0.54) (2021-06-08) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.53](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.52...v1.0.53) (2021-06-07) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.52](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.51...v1.0.52) (2021-06-07) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.51](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.49...v1.0.51) (2021-06-03) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.49](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.48...v1.0.49) (2021-05-20) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.48](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.48-beta.4...v1.0.48) (2021-05-17) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.48-beta.4](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.48-beta.3...v1.0.48-beta.4) (2021-05-14) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.48-beta.3](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.48-beta.2...v1.0.48-beta.3) (2021-05-13) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.48-beta.2](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.48-beta.1...v1.0.48-beta.2) (2021-05-12) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.48-beta.1](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.48-beta.0...v1.0.48-beta.1) (2021-05-12) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.48-beta.0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.47...v1.0.48-beta.0) (2021-05-11) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.47](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.47-beta.1...v1.0.47) (2021-04-28) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.47-beta.1](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.47-beta.0...v1.0.47-beta.1) (2021-04-28) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.47-beta.0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.46...v1.0.47-beta.0) (2021-04-28) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.46](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.46-beta.0...v1.0.46) (2021-04-27) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.46-beta.0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.45...v1.0.46-beta.0) (2021-04-25) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.45](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.45-beta.1...v1.0.45) (2021-04-23) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.45-beta.1](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.45-beta.0...v1.0.45-beta.1) (2021-04-22) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.45-beta.0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.44...v1.0.45-beta.0) (2021-04-21) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.44](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.44-beta.2...v1.0.44) (2021-04-14) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.44-beta.2](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.44-beta.1...v1.0.44-beta.2) (2021-04-14) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.44-beta.1](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.44-beta.0...v1.0.44-beta.1) (2021-04-14) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.44-beta.0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.43...v1.0.44-beta.0) (2021-04-13) - - -### Bug Fixes - -* componentsMap 中加入低代码组件信息 ([b7c1183](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/b7c11834602d8e4ea84d2dea035a3abf97b33d5c)) - - - - - -## [1.0.43](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.43-beta.0...v1.0.43) (2021-04-13) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.43-beta.0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.42...v1.0.43-beta.0) (2021-04-13) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.42](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.42-beta.1...v1.0.42) (2021-04-06) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.42-beta.1](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.42-beta.0...v1.0.42-beta.1) (2021-04-06) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.42-beta.0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.41...v1.0.42-beta.0) (2021-04-06) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.41](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.41-beta.1...v1.0.41) (2021-04-06) - - -### Bug Fixes - -* bypass dataSource ([3cb331d](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/3cb331dcbeee62959ef0b1614c6c3cb2bd3c1a3e)) - - - - - -## [1.0.41-beta.2](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.41-beta.1...v1.0.41-beta.2) (2021-04-06) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.41-beta.1](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.41-beta.0...v1.0.41-beta.1) (2021-04-06) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.41-beta.0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.40...v1.0.41-beta.0) (2021-04-02) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.40](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.40-beta.1...v1.0.40) (2021-03-31) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.40-beta.1](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.40-beta.0...v1.0.40-beta.1) (2021-03-31) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.40-beta.0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.39-beta.5...v1.0.40-beta.0) (2021-03-31) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.39-beta.5](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.39-beta.4...v1.0.39-beta.5) (2021-03-31) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.39-beta.4](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.39-beta.3...v1.0.39-beta.4) (2021-03-30) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.39-beta.3](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.39-beta.2...v1.0.39-beta.3) (2021-03-22) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.39-beta.2](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.39-beta.1...v1.0.39-beta.2) (2021-03-22) - - -### Bug Fixes - -* renderer-core 在非设计渲染态时, 不应处理 hidden 属性 ([7857096](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/7857096c0f56308195cc9e27de4f549eee72a10e)) - - - - - -## [1.0.39-beta.1](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.38-beta.3...v1.0.39-beta.1) (2021-03-12) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.39-beta.0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.38-beta.3...v1.0.39-beta.0) (2021-03-12) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.38-beta.3](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.38-beta.1...v1.0.38-beta.3) (2021-03-11) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.38-beta.2](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.38-beta.1...v1.0.38-beta.2) (2021-03-11) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.38-beta.1](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.38-beta.0...v1.0.38-beta.1) (2021-03-09) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.38-beta.0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.37...v1.0.38-beta.0) (2021-03-08) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.37](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.37-beta.6...v1.0.37) (2021-03-05) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - - - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.37](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.37-beta.6...v1.0.37) (2021-03-05) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.37-beta.6](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.37-beta.3...v1.0.37-beta.6) (2021-03-03) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.37-beta.5](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.37-beta.4...v1.0.37-beta.5) (2021-02-24) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.37-beta.4](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.37-beta.3...v1.0.37-beta.4) (2021-02-24) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - -## [1.0.37-beta.3](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.37-beta.2...v1.0.37-beta.3) (2021-02-24) - -**Note:** Version bump only for package @ali/lowcode-types - - - - - - -## [1.0.37-beta.2](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.37-beta.1...v1.0.37-beta.2) (2021-02-23) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.37-beta.1](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.36...v1.0.37-beta.1) (2021-02-23) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.36](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.36-beta.0...v1.0.36) (2021-02-04) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.36-beta.0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.35...v1.0.36-beta.0) (2021-02-04) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.35](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.35-beta.1...v1.0.35) (2021-02-03) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.35-beta.1](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.35-beta.0...v1.0.35-beta.1) (2021-02-03) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.35-beta.0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.33...v1.0.35-beta.0) (2021-02-01) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.33](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.33-beta.1...v1.0.33) (2021-01-29) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.33-beta.1](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.33-beta.0...v1.0.33-beta.1) (2021-01-28) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.33-beta.0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.32...v1.0.33-beta.0) (2021-01-28) - - -### Bug Fixes - -* 修复从其他页面粘贴过来的 modal 位置不对 ([158b6a6](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/158b6a6)) - - - - - -## [1.0.32](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.32-beta.2...v1.0.32) (2021-01-26) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.32-beta.2](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.32-beta.0...v1.0.32-beta.2) (2021-01-26) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.32-beta.0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.31...v1.0.32-beta.0) (2021-01-25) - - -### Features - -* meta 增加 hideSelectTools ([e7287d4](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/e7287d4)) -* metadata 增加 canHovering 配置 ([88e128e](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/88e128e)) -* 增加 plugin 的 autoInit 注册方式 ([4f9be73](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/4f9be73)) - - - - - -## [1.0.31](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.31-beta.1...v1.0.31) (2021-01-15) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.31-beta.1](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.30...v1.0.31-beta.1) (2021-01-15) - - -### Bug Fixes - -* 延迟加载内置 setter ([99cbdd5](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/99cbdd5)) - - - - - -## [1.0.31-beta.0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.30...v1.0.31-beta.0) (2021-01-15) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.30](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.30-beta.17...v1.0.30) (2021-01-14) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.30-beta.17](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.30-beta.16...v1.0.30-beta.17) (2021-01-14) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.30-beta.16](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.30-beta.14...v1.0.30-beta.16) (2021-01-14) - - -### Features - -* 将 typings 在顶层导出 ([d2aed7d](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/d2aed7d)) - - - - - -## [1.0.30-beta.15](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.30-beta.14...v1.0.30-beta.15) (2021-01-13) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.30-beta.14](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.30-beta.13...v1.0.30-beta.14) (2021-01-13) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.30-beta.13](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.30-beta.12...v1.0.30-beta.13) (2021-01-13) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.30-beta.12](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.30-beta.11...v1.0.30-beta.12) (2021-01-13) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.30-beta.11](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.30-beta.10...v1.0.30-beta.11) (2021-01-12) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.30-beta.10](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.30-beta.9...v1.0.30-beta.10) (2021-01-12) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.30-beta.9](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.30-beta.8...v1.0.30-beta.9) (2021-01-11) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.30-beta.8](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.30-beta.7...v1.0.30-beta.8) (2021-01-11) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.30-beta.7](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.30-beta.6...v1.0.30-beta.7) (2021-01-11) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.30-beta.6](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.29...v1.0.30-beta.6) (2021-01-09) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.29](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.28-beta.2...v1.0.29) (2021-01-05) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.28-beta.2](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.28-beta.1...v1.0.28-beta.2) (2021-01-04) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.28-beta.1](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.27...v1.0.28-beta.1) (2021-01-04) - - -### Features - -* 🎸 utils 的定义中增加对于 function 类型的支持 ([29b1daf](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/29b1daf)) -* 支持新版的 plugin 机制 ([1e8fc63](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/1e8fc63)) - - - - - -## [1.0.28-beta.0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.27...v1.0.28-beta.0) (2021-01-04) - - -### Features - -* 🎸 utils 的定义中增加对于 function 类型的支持 ([29b1daf](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/29b1daf)) -* 支持新版的 plugin 机制 ([1e8fc63](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/1e8fc63)) - - - - - -## [1.0.27](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.27-beta.2...v1.0.27) (2020-12-24) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.27-beta.2](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.27-beta.1...v1.0.27-beta.2) (2020-12-23) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.27-beta.1](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.27-beta.0...v1.0.27-beta.1) (2020-12-23) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.27-beta.0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.26...v1.0.27-beta.0) (2020-12-23) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.26](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.26-beta.1...v1.0.26) (2020-12-22) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.26-beta.1](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.26-beta.0...v1.0.26-beta.1) (2020-12-22) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.26-beta.0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.25-beta.1...v1.0.26-beta.0) (2020-12-22) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.25-beta.1](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.24-beta.4...v1.0.25-beta.1) (2020-12-15) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.24-beta.4](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.24-beta.3...v1.0.24-beta.4) (2020-12-14) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.24-beta.3](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.24-beta.2...v1.0.24-beta.3) (2020-12-11) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.24-beta.2](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.24-beta.1...v1.0.24-beta.2) (2020-12-10) - - -### Bug Fixes - -* 删除无用代码, 解决 ts 编译报错 ([1f241ea](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/1f241ea)) - - - - - -## [1.0.24-beta.1](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.24-beta.0...v1.0.24-beta.1) (2020-12-09) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.24-beta.0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.23...v1.0.24-beta.0) (2020-12-09) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.23](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.23-beta.2...v1.0.23) (2020-12-08) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.23-beta.5](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.23-beta.4...v1.0.23-beta.5) (2020-12-08) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.23-beta.4](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.23-beta.3...v1.0.23-beta.4) (2020-12-08) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.23-beta.3](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.23-beta.2...v1.0.23-beta.3) (2020-12-08) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.23-beta.2](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.23-beta.1...v1.0.23-beta.2) (2020-12-08) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.23-beta.1](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.13.1-29...v1.0.23-beta.1) (2020-12-07) - - -### Bug Fixes - -* 🐛 use lowcode types ([b11425b](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/b11425b)) -* 🐛 根据低代码规范,数据源的配置中isInit和 type 都是有默认值的,所以应该是可选的 ([4baf0b4](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/4baf0b4)) -* datasource版本错误问题 ([a247878](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/a247878)) -* fix test result ([7f6fbe8](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/7f6fbe8)) -* JSExpression 增加 compiled ([9f51e39](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/9f51e39)) -* miniAppBuildType config(temp) ([584b4c2](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/584b4c2)) -* typo of onResizeEnd and remove ([8df5f05](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/8df5f05)) -* will fetch 按照协议修改 ([b9bf800](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/b9bf800)) - - -### Features - -* 🎸 urlParams 类型的数据源不需要 options, 所以 options 改成可选为好 ([8114c6f](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/8114c6f)) -* 🎸 按照中后台搭建协议规范文档补充 JSFunction 的定义和数据源定义中一些字段 ([8b1d0c7](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/8b1d0c7)) -* 🎸 根据低代码协议文档, 完善UtilsMap的定义 ([7fe4bc0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/7fe4bc0)) -* 🎸 根据低代码协议文档, 将 BlockSchema 也改成继承自 ContainerSchema ([7901c8e](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/7901c8e)) -* 🎸 补充规范中定义的 JSFunction 类型 ([9e32525](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/9e32525)) -* split datasource types ([fd80698](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/fd80698)) -* update datasource engine ([cf3c7db](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/cf3c7db)) -* 合入 trunk-vision 代码 ([ea6bc7a](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/ea6bc7a)) -* 调整 datasource-handlers ([2b9bcb5](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/2b9bcb5)) - - - - - -## [1.0.23-beta.0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.13.1-29...v1.0.23-beta.0) (2020-12-07) - - -### Bug Fixes - -* 🐛 use lowcode types ([b11425b](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/b11425b)) -* 🐛 根据低代码规范,数据源的配置中isInit和 type 都是有默认值的,所以应该是可选的 ([4baf0b4](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/4baf0b4)) -* datasource版本错误问题 ([a247878](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/a247878)) -* fix test result ([7f6fbe8](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/7f6fbe8)) -* JSExpression 增加 compiled ([9f51e39](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/9f51e39)) -* miniAppBuildType config(temp) ([584b4c2](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/584b4c2)) -* typo of onResizeEnd and remove ([8df5f05](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/8df5f05)) -* will fetch 按照协议修改 ([b9bf800](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/b9bf800)) - - -### Features - -* 🎸 urlParams 类型的数据源不需要 options, 所以 options 改成可选为好 ([8114c6f](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/8114c6f)) -* 🎸 按照中后台搭建协议规范文档补充 JSFunction 的定义和数据源定义中一些字段 ([8b1d0c7](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/8b1d0c7)) -* 🎸 根据低代码协议文档, 完善UtilsMap的定义 ([7fe4bc0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/7fe4bc0)) -* 🎸 根据低代码协议文档, 将 BlockSchema 也改成继承自 ContainerSchema ([7901c8e](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/7901c8e)) -* 🎸 补充规范中定义的 JSFunction 类型 ([9e32525](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/9e32525)) -* split datasource types ([fd80698](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/fd80698)) -* update datasource engine ([cf3c7db](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/cf3c7db)) -* 合入 trunk-vision 代码 ([ea6bc7a](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/ea6bc7a)) -* 调整 datasource-handlers ([2b9bcb5](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/2b9bcb5)) - - - - - -## [1.0.20](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@1.0.19...@ali/lowcode-types@1.0.20) (2020-11-16) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.19](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@1.0.18...@ali/lowcode-types@1.0.19) (2020-11-10) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.18](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@1.0.17...@ali/lowcode-types@1.0.18) (2020-11-10) - - -### Bug Fixes - -* typo of onResizeEnd and remove ([8df5f05](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/8df5f05)) - - - - - -## [1.0.17](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@1.0.16...@ali/lowcode-types@1.0.17) (2020-11-05) - - -### Bug Fixes - -* datasource版本错误问题 ([a247878](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/a247878)) - - -### Features - -* split datasource types ([fd80698](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/fd80698)) - - - - - -## [1.0.16](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@1.0.15...@ali/lowcode-types@1.0.16) (2020-11-05) -* 低成本方案支持绝对布局容器 ([a6067e8](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/a6067e8)) - - - - -## [0.12.1-18](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.12.1-17...v0.12.1-18) (2020-10-17) - - - - -## [0.12.1-17](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.12.1-16...v0.12.1-17) (2020-10-14) - - - - -## [0.12.1-16](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.12.1-15...v0.12.1-16) (2020-10-12) - - - - -## [0.12.1-15](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.13.1-1...v0.12.1-15) (2020-10-12) - - - - -## [0.12.1-14](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.12.1-13...v0.12.1-14) (2020-10-10) - - - - -## [0.12.1-13](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.12.1-12...v0.12.1-13) (2020-09-28) - - - - -## [0.12.1-12](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.12.1-11...v0.12.1-12) (2020-09-28) - - - - -## [0.12.1-11](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.12.1-10...v0.12.1-11) (2020-09-27) - - - - -## [0.12.1-10](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.12.1-9...v0.12.1-10) (2020-09-27) - - - - -## [0.12.1-9](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.12.1-8...v0.12.1-9) (2020-09-27) - - - - -## [0.12.1-8](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.12.1-7...v0.12.1-8) (2020-09-27) - - - - -## [0.12.1-7](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.12.1-2...v0.12.1-7) (2020-09-27) - - - - - -## [0.13.1-11](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.13.1-10...v0.13.1-11) (2020-11-02) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [0.13.1-10](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.13.1-9...v0.13.1-10) (2020-10-26) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [0.13.1-9](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.13.1-7...v0.13.1-9) (2020-10-26) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [0.13.1-8](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.13.1-7...v0.13.1-8) (2020-10-26) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [0.13.1-7](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.13.1-6...v0.13.1-7) (2020-10-23) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [0.13.1-6](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.13.1-5...v0.13.1-6) (2020-10-22) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [0.13.1-5](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.13.1-4...v0.13.1-5) (2020-10-20) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [0.13.1-4](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.13.1-3...v0.13.1-4) (2020-10-20) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [0.13.1-3](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.13.1-2...v0.13.1-3) (2020-10-19) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [0.13.1-2](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.13.1-1...v0.13.1-2) (2020-10-19) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [0.13.1-1](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.12.1-3...v0.13.1-1) (2020-10-12) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [0.12.1-3](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.12.1-2...v0.12.1-3) (2020-10-12) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.15](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@1.0.14...@ali/lowcode-types@1.0.15) (2020-11-05) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.14](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@1.0.13...@ali/lowcode-types@1.0.14) (2020-11-04) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.13](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@1.0.12...@ali/lowcode-types@1.0.13) (2020-11-04) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.13](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@1.0.12...@ali/lowcode-types@1.0.13) (2020-11-02) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.12](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@1.0.11...@ali/lowcode-types@1.0.12) (2020-10-20) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.11](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@1.0.10...@ali/lowcode-types@1.0.11) (2020-10-19) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.10](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@1.0.9...@ali/lowcode-types@1.0.10) (2020-09-29) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.9](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@1.0.8...@ali/lowcode-types@1.0.9) (2020-09-28) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.8](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@1.0.8-0...@ali/lowcode-types@1.0.8) (2020-09-28) - - -### Bug Fixes - -* 🐛 根据低代码规范,数据源的配置中isInit和 type 都是有默认值的,所以应该是可选的 ([4baf0b4](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/4baf0b4)) -* 🐛 use lowcode types ([b11425b](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/b11425b)) -* fix test result ([7f6fbe8](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/7f6fbe8)) -* miniAppBuildType config(temp) ([584b4c2](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/584b4c2)) -* currentPage.id 返回 formUuid ([775725d](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/775725d)) -* fix NextTable callback function ([ce77375](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/ce77375)) -* panel visible time ([18ac1fa](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/18ac1fa)) -* supports ([371b84c](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/371b84c)) -* 低代码组件 props 显示 object 问题 ([116498e](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/116498e)) -* 修复 slot 获取初始值异常的 bug ([63b19f1](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/63b19f1)) -* 修复判断动态 setter 的逻辑 ([d195d7f](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/d195d7f)) -* 兼容事件绑定 ([f4c07af](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/f4c07af)) -* 可以降级到历史的 JSBlock 格式 ([af1746b](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/af1746b)) -* 合并master分支 ([bd2c6ad](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/bd2c6ad)) - - -### Features - -* 🎸 按照中后台搭建协议规范文档补充 JSFunction 的定义和数据源定义中一些字段 ([8b1d0c7](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/8b1d0c7)) -* 🎸 补充规范中定义的 JSFunction 类型 ([9e32525](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/9e32525)) -* 🎸 根据低代码协议文档, 将 BlockSchema 也改成继承自 ContainerSchema ([7901c8e](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/7901c8e)) -* 🎸 根据低代码协议文档, 完善UtilsMap的定义 ([7fe4bc0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/7fe4bc0)) -* 🎸 urlParams 类型的数据源不需要 options, 所以 options 改成可选为好 ([8114c6f](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/8114c6f)) -* 🎸 增加icon相关的判断函数 ([89064f5](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/89064f5)) -* add filter reducer ([17c6ed3](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/17c6ed3)) -* merge live mode ([92c3039](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/92c3039)) -* show value state ([bd49e50](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/bd49e50)) -* support plaintext liveediting ([ea62f12](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/ea62f12)) -* support prop.autorun ([c0a5235](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/c0a5235)) -* 修复状态切换失效 ([2e3f60d](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/2e3f60d)) -* 编辑器 hooks 能力实现 ([f3ac23b](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/f3ac23b)) - - - - - -## [1.0.8-0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@0.8.19...@ali/lowcode-types@1.0.8-0) (2020-09-09) - - -### Bug Fixes - -* 合并master分支 ([bd2c6ad](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/bd2c6ad)) -* fix NextTable callback function ([ce77375](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/ce77375)) - - - - - -## [0.8.19](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@0.8.18...@ali/lowcode-types@0.8.19) (2020-09-03) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [0.8.18](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@0.8.17...@ali/lowcode-types@0.8.18) (2020-09-03) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [0.8.17](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@0.8.16...@ali/lowcode-types@0.8.17) (2020-08-24) - -## [1.0.7-0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@1.0.6-0...@ali/lowcode-types@1.0.7-0) (2020-09-02) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.6-0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@0.8.17...@ali/lowcode-types@1.0.6-0) (2020-09-02) - - -### Bug Fixes - -* 合并master分支 ([bd2c6ad](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/bd2c6ad)) -* fix NextTable callback function ([ce77375](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/ce77375)) - - - - - -## [1.0.5-0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@1.0.4-0...@ali/lowcode-types@1.0.5-0) (2020-08-20) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.4-0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@1.0.3-0...@ali/lowcode-types@1.0.4-0) (2020-08-20) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.3-0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@1.0.2-0...@ali/lowcode-types@1.0.3-0) (2020-08-20) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.2-0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@1.0.1-0...@ali/lowcode-types@1.0.2-0) (2020-08-20) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [1.0.1-0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@0.8.16...@ali/lowcode-types@1.0.1-0) (2020-08-20) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -# [1.0.0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@0.13.0...@ali/lowcode-types@1.0.0) (2020-08-17) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -# [0.13.0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@0.12.0...@ali/lowcode-types@0.13.0) (2020-08-17) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -# [0.12.0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@0.10.0...@ali/lowcode-types@0.12.0) (2020-08-17) - -## [0.8.16](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@0.8.15...@ali/lowcode-types@0.8.16) (2020-08-19) - - -### Bug Fixes - -* currentPage.id 返回 formUuid ([775725d](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/775725d)) - - - - - -## [0.8.15](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@0.8.14...@ali/lowcode-types@0.8.15) (2020-08-17) - - -### Bug Fixes - -* 修复判断动态 setter 的逻辑 ([d195d7f](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/d195d7f)) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -# [0.11.0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@0.10.0...@ali/lowcode-types@0.11.0) (2020-08-17) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -# [0.10.0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@0.9.0...@ali/lowcode-types@0.10.0) (2020-08-16) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -# [0.9.0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@0.8.14...@ali/lowcode-types@0.9.0) (2020-08-14) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [0.8.14](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@0.8.13...@ali/lowcode-types@0.8.14) (2020-08-04) - - -### Bug Fixes - -* 修复 slot 获取初始值异常的 bug ([63b19f1](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/63b19f1)) - - - - - -## [0.8.13](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@0.8.12...@ali/lowcode-types@0.8.13) (2020-07-21) - - -### Bug Fixes - -* 兼容事件绑定 ([f4c07af](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/f4c07af)) - - - - - -## [0.8.12](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@0.8.11...@ali/lowcode-types@0.8.12) (2020-07-21) - - -### Bug Fixes - -* 可以降级到历史的 JSBlock 格式 ([af1746b](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/af1746b)) - - - - - -## [0.8.11](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@0.8.10...@ali/lowcode-types@0.8.11) (2020-07-13) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [0.8.10](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@0.8.9...@ali/lowcode-types@0.8.10) (2020-07-12) - - -### Bug Fixes - -* 低代码组件 props 显示 object 问题 ([116498e](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/116498e)) - - - - - -## [0.8.9](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@0.8.7...@ali/lowcode-types@0.8.9) (2020-06-23) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [0.8.7](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@0.8.6...@ali/lowcode-types@0.8.7) (2020-06-23) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [0.8.6](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@0.8.5...@ali/lowcode-types@0.8.6) (2020-06-15) - - -### Features - -* support prop.autorun ([c0a5235](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/c0a5235)) - - - - - -## [0.8.5](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@0.8.4...@ali/lowcode-types@0.8.5) (2020-05-18) - - - - -**Note:** Version bump only for package @ali/lowcode-types - - -## [0.8.4](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@0.8.3...@ali/lowcode-types@0.8.4) (2020-05-15) - - -### Features - -* add filter reducer ([17c6ed3](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/17c6ed3)) - - - - - -## [0.8.3](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@0.8.2...@ali/lowcode-types@0.8.3) (2020-05-13) - - -### Bug Fixes - -* panel visible time ([18ac1fa](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/18ac1fa)) -* supports ([371b84c](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/371b84c)) - - -### Features - -* show value state ([bd49e50](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/bd49e50)) -* support plaintext liveediting ([ea62f12](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/ea62f12)) - - - - - -## [0.8.2](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-types@0.8.1...@ali/lowcode-types@0.8.2) (2020-05-07) - - -### Features - -* 🎸 增加icon相关的判断函数 ([89064f5](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/89064f5)) -* 修复状态切换失效 ([2e3f60d](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/2e3f60d)) - - - - - -## 0.8.1 (2020-04-27) - - - - -**Note:** Version bump only for package @ali/lowcode-types diff --git a/packages/types/package.json b/packages/types/package.json deleted file mode 100644 index c17197fa3..000000000 --- a/packages/types/package.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "name": "@alilc/lowcode-types", - "version": "2.0.0-beta.0", - "description": "Types for Ali lowCode engine", - "type": "module", - "main": "dist/low-code-types.js", - "module": "dist/low-code-types.js", - "types": "dist/index.d.ts", - "exports": { - ".": { - "import": "./dist/low-code-types.js", - "module": "./dist/low-code-types.js", - "types": "./dist/index.d.ts" - }, - "./package.json": "./package.json" - }, - "files": [ - "dist", - "src", - "package.json" - ], - "scripts": { - "build:target": "vite build", - "build:dts": "tsc -p tsconfig.declaration.json && node ../../scripts/rollup-dts.mjs", - "test": "vitest" - }, - "dependencies": { - "@alilc/lowcode-datasource-types": "^1.0.0", - "@alifd/next": "^1.27.8", - "react": "^18.2.0", - "strict-event-emitter-types": "^2.0.0" - }, - "devDependencies": { - "@types/react": "^18.2.0" - }, - "peerDependencies": { - "react": "^18.2.0", - "@alifd/next": "^1.27.8" - }, - "publishConfig": { - "access": "public", - "registry": "https://registry.npmjs.org/" - }, - "repository": { - "type": "http", - "url": "https://github.com/alibaba/lowcode-engine/tree/main/packages/types" - }, - "gitHead": "2669f179e6f899d395ce1942d0fe04f9c5ed48a6", - "bugs": "https://github.com/alibaba/lowcode-engine/issues", - "homepage": "https://github.com/alibaba/lowcode-engine/#readme" -} diff --git a/packages/types/src/activity.ts b/packages/types/src/activity.ts deleted file mode 100644 index 45f821264..000000000 --- a/packages/types/src/activity.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { IPublicTypeNodeSchema } from './shell'; - -export enum ActivityType { - ADDED = 'added', - DELETED = 'deleted', - MODIFIED = 'modified', - COMPOSITE = 'composite', -} - -interface IActivityPayload { - schema: IPublicTypeNodeSchema; - location?: { - parent: { - nodeId: string; - index: number; - }; - }; - prop: any; - oldValue: any; - newValue: any; -} diff --git a/packages/types/src/assets.ts b/packages/types/src/assets.ts deleted file mode 100644 index f0e6d3539..000000000 --- a/packages/types/src/assets.ts +++ /dev/null @@ -1,52 +0,0 @@ -export enum AssetLevel { - // 环境依赖库 比如 react, react-dom - Environment = 1, - // 基础类库,比如 lodash deep fusion antd - Library = 2, - // 主题 - Theme = 3, - // 运行时 - Runtime = 4, - // 业务组件 - Components = 5, - // 应用 & 页面 - App = 6, -} - -export const AssetLevels = [ - AssetLevel.Environment, - AssetLevel.Library, - AssetLevel.Theme, - AssetLevel.Runtime, - AssetLevel.Components, - AssetLevel.App, -]; - -export type URL = string; - -export enum AssetType { - JSUrl = 'jsUrl', - CSSUrl = 'cssUrl', - CSSText = 'cssText', - JSText = 'jsText', - Bundle = 'bundle', -} - -export interface AssetItem { - type: AssetType; - content?: string | null; - device?: string; - level?: AssetLevel; - id?: string; - scriptType?: string; -} - -export type AssetList = Array; - -export type Asset = AssetList | AssetBundle | AssetItem | URL; - -export interface AssetBundle { - type: AssetType.Bundle; - level?: AssetLevel; - assets?: Asset | AssetList | null; -} diff --git a/packages/types/src/code-intermediate.ts b/packages/types/src/code-intermediate.ts deleted file mode 100644 index 656df2e1e..000000000 --- a/packages/types/src/code-intermediate.ts +++ /dev/null @@ -1,14 +0,0 @@ -export interface PackageJSON { - name: string; - version: string; - description?: string; - dependencies: Record; - devDependencies: Record; - scripts?: Record; - engines?: Record; - repository?: { - type: string; - url: string; - }; - private?: boolean; -} diff --git a/packages/types/src/code-result.ts b/packages/types/src/code-result.ts deleted file mode 100644 index 07e9c0795..000000000 --- a/packages/types/src/code-result.ts +++ /dev/null @@ -1,59 +0,0 @@ -/** - * 导出内容结构,文件夹 - * - * @export - * @interface ResultDir - */ -export interface ResultDir { - /** - * 文件夹名称,Root 名称默认为 . - * - * @type {string} - * @memberof ResultDir - */ - name: string; - /** - * 子目录 - * - * @type {ResultDir[]} - * @memberof ResultDir - */ - dirs: ResultDir[]; - /** - * 文件夹内文件 - * - * @type {ResultFile[]} - * @memberof ResultDir - */ - files: ResultFile[]; -} - -/** - * 导出内容,对文件的描述 - * - * @export - * @interface ResultFile - */ -export interface ResultFile { - /** - * 文件名 - * - * @type {string} - * @memberof ResultFile - */ - name: string; - /** - * 文件类型扩展名,例如 .js .less - * - * @type {string} - * @memberof ResultFile - */ - ext: string; - /** - * 文件内容 - * - * @type {string} - * @memberof ResultFile - */ - content: string; -} diff --git a/packages/types/src/editor.ts b/packages/types/src/editor.ts deleted file mode 100644 index 468aedb9f..000000000 --- a/packages/types/src/editor.ts +++ /dev/null @@ -1,147 +0,0 @@ -import { ReactNode, ComponentType } from 'react'; -import { IPublicTypeNpmInfo, IPublicModelEditor } from './shell'; - -export interface EditorConfig { - skeleton?: SkeletonConfig; - theme?: ThemeConfig; - plugins?: PluginsConfig; - hooks?: HooksConfig; - shortCuts?: ShortCutsConfig; - utils?: UtilsConfig; - constants?: ConstantsConfig; - lifeCycles?: LifeCyclesConfig; - i18n?: I18nConfig; -} - -export interface SkeletonConfig { - config: IPublicTypeNpmInfo; - props?: Record; - handler?: (config: EditorConfig) => EditorConfig; -} - -export interface FusionTheme { - package: string; - version: string; -} - -export interface ThemeConfig { - fusion?: FusionTheme; -} - -export interface PluginsConfig { - [key: string]: PluginConfig[]; -} - -export interface PluginConfig { - pluginKey: string; - type: string; - props: { - icon?: string; - title?: string; - width?: number; - height?: number; - visible?: boolean; - disabled?: boolean; - marked?: boolean; - align?: 'left' | 'right' | 'top' | 'bottom'; - onClick?: () => void; - dialogProps?: Record; - balloonProps?: Record; - panelProps?: Record; - linkProps?: Record; - }; - config?: IPublicTypeNpmInfo; - pluginProps?: Record; -} - -export type HooksConfig = HookConfig[]; - -export interface HookConfig { - message: string; - type: 'on' | 'once'; - handler: (this: IPublicModelEditor, editor: IPublicModelEditor, ...args: any[]) => void; -} - -export type ShortCutsConfig = ShortCutConfig[]; - -export interface ShortCutConfig { - keyboard: string; - handler: (editor: IPublicModelEditor, ev: Event, keymaster: any) => void; -} - -export type UtilsConfig = UtilConfig[]; - -export interface UtilConfig { - name: string; - type: 'npm' | 'function'; - content: IPublicTypeNpmInfo | ((...args: []) => any); -} - -export type ConstantsConfig = Record; - -export interface LifeCyclesConfig { - init?: (editor: IPublicModelEditor) => any; - destroy?: (editor: IPublicModelEditor) => any; -} - -export type LocaleType = 'zh-CN' | 'zh-TW' | 'en-US' | 'ja-JP'; - -export interface I18nMessages { - [key: string]: string; -} - -export interface I18nConfig { - 'zh-CN'?: I18nMessages; - 'zh-TW'?: I18nMessages; - 'en-US'?: I18nMessages; - 'ja-JP'?: I18nMessages; -} - -export type I18nFunction = (key: string, params: any) => string; - -export interface Utils { - [key: string]: (...args: any[]) => any; -} - -export interface PluginProps { - editor?: IPublicModelEditor; - config: PluginConfig; - [key: string]: any; -} - -export type Plugin = ReactNode & { - open?: () => boolean | undefined | Promise; - close?: () => boolean | undefined | Promise; -}; - -export type HOCPlugin = ReactNode & { - open: () => Promise; - close: () => Promise; -}; - -export interface PluginSet { - [key: string]: HOCPlugin; -} - -export type PluginClass = ComponentType & { - init?: (editor: IPublicModelEditor) => void; - defaultProps?: { - locale?: LocaleType; - messages?: I18nMessages; - }; -}; - -export interface PluginClassSet { - [key: string]: PluginClass; -} - -export interface PluginStatus { - disabled?: boolean; - visible?: boolean; - marked?: boolean; - locked?: boolean; -} - -export interface PluginStatusSet { - [key: string]: PluginStatus; -} diff --git a/packages/types/src/event/index.ts b/packages/types/src/event/index.ts deleted file mode 100644 index b0a322e13..000000000 --- a/packages/types/src/event/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -import * as Node from './node'; - -export interface EventConfig { - [Node.Prop.InnerChange]: (options: Node.Prop.ChangeOptions) => any; - [Node.Rerender]: (options: Node.RerenderOptions) => void; - [eventName: string]: any; -} - -export { Node }; diff --git a/packages/types/src/event/node.ts b/packages/types/src/event/node.ts deleted file mode 100644 index 34455a176..000000000 --- a/packages/types/src/event/node.ts +++ /dev/null @@ -1,12 +0,0 @@ -import * as Prop from './prop'; - -export { Prop }; - -export interface RerenderOptions { - time: number; - componentName?: string; - type?: string; - nodeCount?: number; -} - -export const Rerender = 'node.edit.rerender.time'; diff --git a/packages/types/src/event/prop.ts b/packages/types/src/event/prop.ts deleted file mode 100644 index 486ae3aef..000000000 --- a/packages/types/src/event/prop.ts +++ /dev/null @@ -1,10 +0,0 @@ -export interface ChangeOptions { - key?: string | number; - prop?: any; - node: Node; - newValue: any; - oldValue: any; -} - -/** Node Prop 变化事件 */ -export const InnerChange = 'node.innerProp.change'; diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts deleted file mode 100644 index 69563e380..000000000 --- a/packages/types/src/index.ts +++ /dev/null @@ -1,12 +0,0 @@ -import * as GlobalEvent from './event'; - -export { GlobalEvent }; - -export * from '@alilc/lowcode-datasource-types'; -export * from './editor'; -export * from './activity'; -export * from './code-intermediate'; -export * from './code-result'; -export * from './assets'; -export * from './shell'; -export * from './shell-model-factory'; diff --git a/packages/types/src/shell-model-factory.ts b/packages/types/src/shell-model-factory.ts deleted file mode 100644 index b6044ced9..000000000 --- a/packages/types/src/shell-model-factory.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { IPublicModelNode, IPublicModelSettingField } from './shell'; - -export interface IShellModelFactory { - // TODO: 需要给 innerNode 提供一个 interface 并用在这里 - createNode(node: any | null | undefined): IPublicModelNode | null; - // TODO: 需要给 InnerSettingField 提供一个 interface 并用在这里 - - createSettingField(prop: any): IPublicModelSettingField; -} diff --git a/packages/types/src/shell/api/canvas.ts b/packages/types/src/shell/api/canvas.ts deleted file mode 100644 index 6cb3df9fc..000000000 --- a/packages/types/src/shell/api/canvas.ts +++ /dev/null @@ -1,73 +0,0 @@ -import { IPublicModelDragon, IPublicModelDropLocation, IPublicModelScrollTarget, IPublicModelScroller, IPublicModelActiveTracker, IPublicModelClipboard } from '../model'; -import { IPublicTypeLocationData, IPublicTypeScrollable } from '../type'; - -/** - * canvas - 画布 API - * @since v1.1.0 - */ -export interface IPublicApiCanvas { - - /** - * 创一个滚动控制器 Scroller,赋予一个视图滚动的基本能力, - * - * a Scroller is a controller that gives a view (IPublicTypeScrollable) the ability scrolling - * to some cordination by api scrollTo. - * - * when a scroller is inited, will need to pass is a scrollable, which has a scrollTarget. - * and when scrollTo(options: { left?: number; top?: number }) is called, scroller will - * move scrollTarget`s top-left corner to (options.left, options.top) that passed in. - * @since v1.1.0 - */ - createScroller(scrollable: IPublicTypeScrollable): IPublicModelScroller; - - /** - * 创建一个 ScrollTarget,与 Scroller 一起发挥作用,详见 createScroller 中的描述 - * - * this works with Scroller, refer to createScroller`s description - * @since v1.1.0 - */ - createScrollTarget(shell: HTMLDivElement): IPublicModelScrollTarget; - - /** - * 创建一个文档插入位置对象,该对象用来描述一个即将插入的节点在文档中的位置 - * - * create a drop location for document, drop location describes a location in document - * @since v1.1.0 - */ - createLocation(locationData: IPublicTypeLocationData): IPublicModelDropLocation; - - /** - * 获取拖拽操作对象的实例 - * - * get dragon instance, you can use this to obtain draging related abilities and lifecycle hooks - * @since v1.1.0 - */ - get dragon(): IPublicModelDragon | null; - - /** - * 获取活动追踪器实例 - * - * get activeTracker instance, which is a singleton running in engine. - * it tracks document`s current focusing node/node[], and notify it`s subscribers that when - * focusing node/node[] changed. - * @since v1.1.0 - */ - get activeTracker(): IPublicModelActiveTracker | null; - - /** - * 是否处于 LiveEditing 状态 - * - * check if canvas is in liveEditing state - * @since v1.1.0 - */ - get isInLiveEditing(): boolean; - - /** - * 获取全局剪贴板实例 - * - * get clipboard instance - * - * @since v1.1.0 - */ - get clipboard(): IPublicModelClipboard; -} diff --git a/packages/types/src/shell/api/command.ts b/packages/types/src/shell/api/command.ts deleted file mode 100644 index 5361c8777..000000000 --- a/packages/types/src/shell/api/command.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { IPublicTypeCommand, IPublicTypeCommandHandlerArgs, IPublicTypeListCommand } from '../type'; - -export interface IPublicApiCommand { - - /** - * 注册一个新命令及其处理函数 - */ - registerCommand(command: IPublicTypeCommand): void; - - /** - * 注销一个已存在的命令 - */ - unregisterCommand(name: string): void; - - /** - * 通过名称和给定参数执行一个命令,会校验参数是否符合命令定义 - */ - executeCommand(name: string, args?: IPublicTypeCommandHandlerArgs): void; - - /** - * 批量执行命令,执行完所有命令后再进行一次重绘,历史记录中只会记录一次 - */ - batchExecuteCommand(commands: { name: string; args?: IPublicTypeCommandHandlerArgs }[]): void; - - /** - * 列出所有已注册的命令 - */ - listCommands(): IPublicTypeListCommand[]; - - /** - * 注册错误处理回调函数 - */ - onCommandError(callback: (name: string, error: Error) => void): void; -} diff --git a/packages/types/src/shell/api/common.ts b/packages/types/src/shell/api/common.ts deleted file mode 100644 index 0c2dc4328..000000000 --- a/packages/types/src/shell/api/common.ts +++ /dev/null @@ -1,96 +0,0 @@ -import { Component, ReactNode } from 'react'; -import { IPublicTypeNodeSchema, IPublicTypeTitleContent } from '../type'; -import { IPublicEnumTransitionType } from '../enum'; - -export interface IPublicApiCommonUtils { - /** - * 是否为合法的 schema 结构 - * check if data is valid NodeSchema - * - * @param {*} data - * @returns {boolean} - */ - isNodeSchema(data: any): boolean; - - /** - * 是否为表单事件类型 - * check if e is a form event - * @param {(KeyboardEvent | MouseEvent)} e - * @returns {boolean} - */ - isFormEvent(e: KeyboardEvent | MouseEvent): boolean; - - /** - * 从 schema 结构中查找指定 id 节点 - * get node schema from a larger schema with node id - * @param {IPublicTypeNodeSchema} schema - * @param {string} nodeId - * @returns {(IPublicTypeNodeSchema | undefined)} - */ - getNodeSchemaById( - schema: IPublicTypeNodeSchema, - nodeId: string, - ): IPublicTypeNodeSchema | undefined; - - // TODO: add comments - getConvertedExtraKey(key: string): string; - - // TODO: add comments - getOriginalExtraKey(key: string): string; - - /** - * 批处理事务,用于优化特定场景的性能 - * excute something in a transaction for performence - * - * @param {() => void} fn - * @param {IPublicEnumTransitionType} type - * @since v1.0.16 - */ - executeTransaction(fn: () => void, type: IPublicEnumTransitionType): void; - - /** - * i18n 相关工具 - * i18n tools - * - * @param {(string | object)} instance - * @returns {{ - * intlNode(id: string, params?: object): ReactNode; - * intl(id: string, params?: object): string; - * getLocale(): string; - * setLocale(locale: string): void; - * }} - * @since v1.0.17 - */ - createIntl(instance: string | object): { - intlNode(id: string, params?: object): ReactNode; - intl(id: string, params?: object): string; - getLocale(): string; - setLocale(locale: string): void; - }; -} - -export interface IPublicApiCommonSkeletonCabin { - /** - * 编辑器框架 View - * get Workbench Component - */ - get Workbench(): Component; -} - -export interface IPublicApiCommonEditorCabin { - /** - * Title 组件 - * @experimental unstable API, pay extra caution when trying to use this - */ - get Tip(): React.ComponentClass; - - /** - * Tip 组件 - * @experimental unstable API, pay extra caution when trying to use this - */ - get Title(): React.ComponentClass<{ - title: IPublicTypeTitleContent | undefined; - match?: boolean; - keywords?: string | null; - }>; -} diff --git a/packages/types/src/shell/api/commonUI.ts b/packages/types/src/shell/api/commonUI.ts deleted file mode 100644 index bed9030a9..000000000 --- a/packages/types/src/shell/api/commonUI.ts +++ /dev/null @@ -1,108 +0,0 @@ -import React, { ReactElement, ComponentProps } from 'react'; -import { - IPublicTypeContextMenuAction, - IPublicTypeHelpTipConfig, - IPublicTypeTipConfig, - IPublicTypeTitleContent, -} from '../type'; -import { - Balloon, - Breadcrumb, - Button, - Card, - Checkbox, - DatePicker, - Dialog, - Dropdown, - Form, - Icon, - Input, - Loading, - Message, - Overlay, - Pagination, - Radio, - Search, - Select, - SplitButton, - Step, - Switch, - Tab, - Table, - Tree, - TreeSelect, - Upload, - Divider, -} from '@alifd/next'; - -type IconProps = ComponentProps; - -export interface IPublicApiCommonUI { - Balloon: typeof Balloon; - Breadcrumb: typeof Breadcrumb; - Button: typeof Button; - Card: typeof Card; - Checkbox: typeof Checkbox; - DatePicker: typeof DatePicker; - Dialog: typeof Dialog; - Dropdown: typeof Dropdown; - Form: typeof Form; - Icon: typeof Icon; - Input: typeof Input; - Loading: typeof Loading; - Message: typeof Message; - Overlay: typeof Overlay; - Pagination: typeof Pagination; - Radio: typeof Radio; - Search: typeof Search; - Select: typeof Select; - SplitButton: typeof SplitButton; - Step: typeof Step; - Switch: typeof Switch; - Tab: typeof Tab; - Table: typeof Table; - Tree: typeof Tree; - TreeSelect: typeof TreeSelect; - Upload: typeof Upload; - Divider: typeof Divider; - - /** - * Title 组件 - */ - get Tip(): React.ComponentClass; - - /** - * HelpTip 组件 - */ - get HelpTip(): React.VFC<{ - help: IPublicTypeHelpTipConfig; - - /** - * 方向 - * @default 'top' - */ - direction: IPublicTypeTipConfig['direction']; - - /** - * 大小 - * @default 'small' - */ - size: IconProps['size']; - }>; - - /** - * Tip 组件 - */ - get Title(): React.ComponentClass<{ - title: IPublicTypeTitleContent | undefined; - match?: boolean; - keywords?: string | null; - }>; - - get ContextMenu(): ((props: { - menus: IPublicTypeContextMenuAction[]; - children: React.ReactElement[] | React.ReactElement; - }) => ReactElement) & { - create(menus: IPublicTypeContextMenuAction[], event: MouseEvent | React.MouseEvent): void; - }; -} diff --git a/packages/types/src/shell/api/event.ts b/packages/types/src/shell/api/event.ts deleted file mode 100644 index 72b173acf..000000000 --- a/packages/types/src/shell/api/event.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { IPublicTypeDisposable } from '../type'; - -export interface IPublicApiEvent { - /** - * 监听事件 - * add monitor to a event - * @param event 事件名称 - * @param listener 事件回调 - */ - on(event: string, listener: (...args: any[]) => void): IPublicTypeDisposable; - - /** - * 监听事件,会在其他回调函数之前执行 - * add monitor to a event - * @param event 事件名称 - * @param listener 事件回调 - */ - prependListener(event: string, listener: (...args: any[]) => void): IPublicTypeDisposable; - - /** - * 取消监听事件 - * cancel a monitor from a event - * @param event 事件名称 - * @param listener 事件回调 - */ - off(event: string, listener: (...args: any[]) => void): void; - - /** - * 触发事件 - * emit a message for a event - * @param event 事件名称 - * @param args 事件参数 - * @returns - */ - emit(event: string, ...args: any[]): void; -} diff --git a/packages/types/src/shell/api/hotkey.ts b/packages/types/src/shell/api/hotkey.ts deleted file mode 100644 index 4c478b5c5..000000000 --- a/packages/types/src/shell/api/hotkey.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { IPublicTypeDisposable, IPublicTypeHotkeyCallback, IPublicTypeHotkeyCallbacks } from '../type'; - -export interface IPublicApiHotkey { - - /** - * 获取当前快捷键配置 - * - * @experimental - * @since v1.1.0 - */ - get callbacks(): IPublicTypeHotkeyCallbacks; - - /** - * 绑定快捷键 - * bind hotkey/hotkeys, - * @param combos 快捷键,格式如:['command + s'] 、['ctrl + shift + s'] 等 - * @param callback 回调函数 - * @param action - */ - bind( - combos: string[] | string, - callback: IPublicTypeHotkeyCallback, - action?: string, - ): IPublicTypeDisposable; - - /** - * 给指定窗口绑定快捷键 - * @param window 窗口的 window 对象 - */ - mount(window: Window): IPublicTypeDisposable; -} diff --git a/packages/types/src/shell/api/index.ts b/packages/types/src/shell/api/index.ts deleted file mode 100644 index 849dd108a..000000000 --- a/packages/types/src/shell/api/index.ts +++ /dev/null @@ -1,14 +0,0 @@ -export * from './common'; -export * from './event'; -export * from './hotkey'; -export * from './material'; -export * from './project'; -export * from './setters'; -export * from './simulator-host'; -export * from './skeleton'; -export * from './plugins'; -export * from './logger'; -export * from './canvas'; -export * from './workspace'; -export * from './commonUI'; -export * from './command'; diff --git a/packages/types/src/shell/api/logger.ts b/packages/types/src/shell/api/logger.ts deleted file mode 100644 index db81aeaae..000000000 --- a/packages/types/src/shell/api/logger.ts +++ /dev/null @@ -1,33 +0,0 @@ -export type LoggerLevel = 'debug' | 'log' | 'info' | 'warn' | 'error'; -export interface ILoggerOptions { - level?: LoggerLevel; - bizName?: string; -} - -export interface IPublicApiLogger { - - /** - * debug info - */ - debug(...args: any | any[]): void; - - /** - * normal info output - */ - info(...args: any | any[]): void; - - /** - * warning info output - */ - warn(...args: any | any[]): void; - - /** - * error info output - */ - error(...args: any | any[]): void; - - /** - * log info output - */ - log(...args: any | any[]): void; -} diff --git a/packages/types/src/shell/api/material.ts b/packages/types/src/shell/api/material.ts deleted file mode 100644 index 1ef9932cc..000000000 --- a/packages/types/src/shell/api/material.ts +++ /dev/null @@ -1,149 +0,0 @@ -import { IPublicTypeAssetsJson, IPublicTypeMetadataTransducer, IPublicTypeComponentAction, IPublicTypeNpmInfo, IPublicTypeDisposable, IPublicTypeContextMenuAction, IPublicTypeContextMenuItem } from '../type'; -import { IPublicModelComponentMeta } from '../model'; -import { ComponentType } from 'react'; - -export interface IPublicApiMaterial { - - /** - * 获取组件 map 结构 - * get map of components - */ - get componentsMap(): { [key: string]: IPublicTypeNpmInfo | ComponentType | object } ; - - /** - * 设置「资产包」结构 - * set data for Assets - * @returns void - */ - setAssets(assets: IPublicTypeAssetsJson): Promise; - - /** - * 获取「资产包」结构 - * get AssetsJson data - * @returns IPublicTypeAssetsJson - */ - getAssets(): IPublicTypeAssetsJson | undefined; - - /** - * 加载增量的「资产包」结构,该增量包会与原有的合并 - * load Assets incrementally, and will merge this with exiting assets - * @param incrementalAssets - * @returns - */ - loadIncrementalAssets(incrementalAssets: IPublicTypeAssetsJson): void; - - /** - * 注册物料元数据管道函数,在物料信息初始化时执行。 - * register transducer to process component meta, which will be - * excuted during component meta`s initialization - * @param transducer - * @param level - * @param id - */ - registerMetadataTransducer( - transducer: IPublicTypeMetadataTransducer, - level?: number, - id?: string | undefined - ): void; - - /** - * 获取所有物料元数据管道函数 - * get all registered metadata transducers - * @returns {IPublicTypeMetadataTransducer[]} - */ - getRegisteredMetadataTransducers(): IPublicTypeMetadataTransducer[]; - - /** - * 获取指定名称的物料元数据 - * get component meta by component name - * @param componentName - * @returns - */ - getComponentMeta(componentName: string): IPublicModelComponentMeta | null; - - /** - * test if the given object is a ComponentMeta instance or not - * @param obj - * @experiemental unstable API, pay extra caution when trying to use it - */ - isComponentMeta(obj: any): boolean; - - /** - * 获取所有已注册的物料元数据 - * get map of all component metas - */ - getComponentMetasMap(): Map; - - /** - * 在设计器辅助层增加一个扩展 action - * - * add an action button in canvas context menu area - * @param action - * @example - * ```ts - * import { plugins } from '@alilc/lowcode-engine'; - * import { IPublicModelPluginContext } from '@alilc/lowcode-types'; - * - * const removeCopyAction = (ctx: IPublicModelPluginContext) => { - * return { - * async init() { - * const { removeBuiltinComponentAction } = ctx.material; - * removeBuiltinComponentAction('copy'); - * } - * } - * }; - * removeCopyAction.pluginName = 'removeCopyAction'; - * await plugins.register(removeCopyAction); - * ``` - */ - addBuiltinComponentAction(action: IPublicTypeComponentAction): void; - - /** - * 移除设计器辅助层的指定 action - * remove a builtin action button from canvas context menu area - * @param name - */ - removeBuiltinComponentAction(name: string): void; - - /** - * 修改已有的设计器辅助层的指定 action - * modify a builtin action button in canvas context menu area - * @param actionName - * @param handle - */ - modifyBuiltinComponentAction( - actionName: string, - handle: (action: IPublicTypeComponentAction) => void, - ): void; - - /** - * 监听 assets 变化的事件 - * add callback for assets changed event - * @param fn - */ - onChangeAssets(fn: () => void): IPublicTypeDisposable; - - /** - * 刷新 componentMetasMap,可触发模拟器里的 components 重新构建 - * @since v1.1.7 - */ - refreshComponentMetasMap(): void; - - /** - * 添加右键菜单项 - * @param action - */ - addContextMenuOption(action: IPublicTypeContextMenuAction): void; - - /** - * 删除特定右键菜单项 - * @param name - */ - removeContextMenuOption(name: string): void; - - /** - * 调整右键菜单项布局 - * @param actions - */ - adjustContextMenuLayout(fn: (actions: IPublicTypeContextMenuItem[]) => IPublicTypeContextMenuItem[]): void; -} diff --git a/packages/types/src/shell/api/plugins.ts b/packages/types/src/shell/api/plugins.ts deleted file mode 100644 index dd99d114f..000000000 --- a/packages/types/src/shell/api/plugins.ts +++ /dev/null @@ -1,63 +0,0 @@ -import { IPublicModelPluginInstance, IPublicTypePlugin } from '../model'; -import { IPublicTypePluginPreferenceValueType } from '../type'; -import { IPublicTypePluginRegisterOptions } from '../type/plugin-register-options'; - -export interface IPluginPreferenceMananger { - // eslint-disable-next-line max-len - getPreferenceValue: ( - key: string, - defaultValue?: IPublicTypePluginPreferenceValueType, - ) => IPublicTypePluginPreferenceValueType | undefined; -} - -export type PluginOptionsType = string | number | boolean | object; - -export interface IPublicApiPlugins { - /** - * 可以通过 plugin api 获取其他插件 export 导出的内容 - */ - [key: string]: any; - - register( - pluginModel: IPublicTypePlugin, - options?: Record, - registerOptions?: IPublicTypePluginRegisterOptions, - ): Promise; - - /** - * 引擎初始化时可以提供全局配置给到各插件,通过这个方法可以获得本插件对应的配置 - * - * use this to get preference config for this plugin when engine.init() called - */ - getPluginPreference( - pluginName: string, - ): Record | null | undefined; - - /** - * 获取指定插件 - * - * get plugin instance by name - */ - get(pluginName: string): IPublicModelPluginInstance | null; - - /** - * 获取所有的插件实例 - * - * get all plugin instances - */ - getAll(): IPublicModelPluginInstance[]; - - /** - * 判断是否有指定插件 - * - * check if plugin with certain name exists - */ - has(pluginName: string): boolean; - - /** - * 删除指定插件 - * - * delete plugin instance by name - */ - delete(pluginName: string): void; -} diff --git a/packages/types/src/shell/api/project.ts b/packages/types/src/shell/api/project.ts deleted file mode 100644 index b01532733..000000000 --- a/packages/types/src/shell/api/project.ts +++ /dev/null @@ -1,147 +0,0 @@ -import { IPublicTypeProjectSchema, IPublicTypeDisposable, IPublicTypeRootSchema, IPublicTypePropsTransducer, IPublicTypeAppConfig } from '../type'; -import { IPublicEnumTransformStage } from '../enum'; -import { IPublicApiSimulatorHost } from './'; -import { IPublicModelDocumentModel } from '../model'; - -export interface IBaseApiProject< - DocumentModel -> { - - /** - * 获取当前的 document - * get current document - */ - get currentDocument(): DocumentModel | null; - - /** - * 获取当前 project 下所有 documents - * get all documents of this project - * @returns - */ - get documents(): DocumentModel[]; - - /** - * 获取模拟器的 host - * get simulator host - */ - get simulatorHost(): IPublicApiSimulatorHost | null; - - /** - * 打开一个 document - * open a document - * @param doc - * @returns - */ - openDocument(doc?: string | IPublicTypeRootSchema | undefined): DocumentModel | null; - - /** - * 创建一个 document - * create a document - * @param data - * @returns - */ - createDocument(data?: IPublicTypeRootSchema): DocumentModel | null; - - /** - * 删除一个 document - * remove a document - * @param doc - */ - removeDocument(doc: DocumentModel): void; - - /** - * 根据 fileName 获取 document - * get a document by filename - * @param fileName - * @returns - */ - getDocumentByFileName(fileName: string): DocumentModel | null; - - /** - * 根据 id 获取 document - * get a document by id - * @param id - * @returns - */ - getDocumentById(id: string): DocumentModel | null; - - /** - * 导出 project - * export project to schema - * @returns - */ - exportSchema(stage: IPublicEnumTransformStage): IPublicTypeProjectSchema; - - /** - * 导入 project schema - * import schema to project - * @param schema 待导入的 project 数据 - */ - importSchema(schema?: IPublicTypeProjectSchema): void; - - /** - * 获取当前的 document - * get current document - * @returns - */ - getCurrentDocument(): DocumentModel | null; - - /** - * 增加一个属性的管道处理函数 - * add a transducer to process prop - * @param transducer - * @param stage - */ - addPropsTransducer( - transducer: IPublicTypePropsTransducer, - stage: IPublicEnumTransformStage, - ): void; - - /** - * 绑定删除文档事件 - * set callback for event onDocumentRemoved - * @param fn - * @since v1.0.16 - */ - onRemoveDocument(fn: (data: { id: string }) => void): IPublicTypeDisposable; - - /** - * 当前 project 内的 document 变更事件 - * set callback for event onDocumentChanged - */ - onChangeDocument(fn: (doc: DocumentModel) => void): IPublicTypeDisposable; - - /** - * 当前 project 的模拟器 ready 事件 - * set callback for event onSimulatorHostReady - */ - onSimulatorHostReady(fn: (host: IPublicApiSimulatorHost) => void): IPublicTypeDisposable; - - /** - * 当前 project 的渲染器 ready 事件 - * set callback for event onSimulatorRendererReady - */ - onSimulatorRendererReady(fn: () => void): IPublicTypeDisposable; - - /** - * 设置多语言语料 - * 数据格式参考 https://github.com/alibaba/lowcode-engine/blob/main/specs/lowcode-spec.md#2434%E5%9B%BD%E9%99%85%E5%8C%96%E5%A4%9A%E8%AF%AD%E8%A8%80%E7%B1%BB%E5%9E%8Baa - * - * set I18n data for this project - * @param value object - * @since v1.0.17 - */ - setI18n(value: object): void; - - /** - * 设置当前项目配置 - * - * set config data for this project - * @param value object - * @since v1.1.4 - */ - setConfig(key: T, value: IPublicTypeAppConfig[T]): void; - setConfig(value: IPublicTypeAppConfig): void; -} - -export interface IPublicApiProject extends IBaseApiProject {} diff --git a/packages/types/src/shell/api/setters.ts b/packages/types/src/shell/api/setters.ts deleted file mode 100644 index 9ff2e8eda..000000000 --- a/packages/types/src/shell/api/setters.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { IPublicTypeRegisteredSetter, IPublicTypeCustomView } from '../type'; - -export interface IPublicApiSetters { - /** - * 获取指定 setter - * get setter by type - * @param type - * @returns - */ - getSetter(type: string): IPublicTypeRegisteredSetter | null; - - /** - * 获取已注册的所有 settersMap - * get map of all registered setters - * @returns - */ - getSettersMap(): Map; - - /** - * 注册一个 setter - * register a setter - * @param typeOrMaps - * @param setter - * @returns - */ - registerSetter( - typeOrMaps: string | { [key: string]: IPublicTypeCustomView | IPublicTypeRegisteredSetter }, - setter?: IPublicTypeCustomView | IPublicTypeRegisteredSetter | undefined - ): void; -} diff --git a/packages/types/src/shell/api/simulator-host.ts b/packages/types/src/shell/api/simulator-host.ts deleted file mode 100644 index 913706795..000000000 --- a/packages/types/src/shell/api/simulator-host.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { IPublicModelNode, IPublicModelSimulatorRender } from '../model'; - -export interface IPublicApiSimulatorHost { - - /** - * 获取 contentWindow - * @experimental unstable api, pay extra caution when trying to use it - */ - get contentWindow(): Window | undefined; - - /** - * 获取 contentDocument - * @experimental unstable api, pay extra caution when trying to use it - */ - get contentDocument(): Document | undefined; - - /** - * @experimental unstable api, pay extra caution when trying to use it - */ - get renderer(): IPublicModelSimulatorRender | undefined; - - /** - * 设置若干用于画布渲染的变量,比如画布大小、locale 等。 - * set config for simulator host, eg. device locale and so on. - * @param key - * @param value - */ - set(key: string, value: any): void; - - /** - * 获取模拟器中设置的变量,比如画布大小、locale 等。 - * set config value by key - * @param key - * @returns - */ - get(key: string): any; - - /** - * 滚动到指定节点 - * scroll to specific node - * @param node - * @since v1.1.0 - */ - scrollToNode(node: IPublicModelNode): void; - - /** - * 刷新渲染画布 - * make simulator render again - */ - rerender(): void; -} diff --git a/packages/types/src/shell/api/skeleton.ts b/packages/types/src/shell/api/skeleton.ts deleted file mode 100644 index 5f2d9c61a..000000000 --- a/packages/types/src/shell/api/skeleton.ts +++ /dev/null @@ -1,177 +0,0 @@ -import { IPublicModelSkeletonItem } from '../model'; -import { - IPublicTypeConfigTransducer, - IPublicTypeDisposable, - IPublicTypeSkeletonConfig, - IPublicTypeWidgetConfigArea, -} from '../type'; - -export interface IPublicApiSkeleton { - /** - * 增加一个面板实例 - * add a new panel - * @param config - * @param extraConfig - * @returns - */ - add( - config: IPublicTypeSkeletonConfig, - extraConfig?: Record, - ): IPublicModelSkeletonItem | undefined; - - /** - * 移除一个面板实例 - * remove a panel - * @param config - * @returns - */ - remove(config: IPublicTypeSkeletonConfig): number | undefined; - - /** - * 获取某个区域下的所有面板实例 - * @param areaName IPublicTypeWidgetConfigArea - */ - getAreaItems( - areaName: IPublicTypeWidgetConfigArea, - ): IPublicModelSkeletonItem[] | undefined; - - /** - * 获取面板实例 - * @param name 面板名称 - * @since v1.1.10 - */ - getPanel(name: string): IPublicModelSkeletonItem | undefined; - - /** - * 展示指定 Panel 实例 - * show panel by name - * @param name - */ - showPanel(name: string): void; - - /** - * 隐藏面板 - * hide panel by name - * @param name - */ - hidePanel(name: string): void; - - /** - * 展示指定 Widget 实例 - * show widget by name - * @param name - */ - showWidget(name: string): void; - - /** - * 将 widget 启用 - * enable widget by name - * @param name - */ - enableWidget(name: string): void; - - /** - * 隐藏指定 widget 实例 - * hide widget by name - * @param name - */ - hideWidget(name: string): void; - - /** - * 将 widget 禁用掉,禁用后,所有鼠标事件都会被禁止掉。 - * disable widget,and make it not responding any click event. - * @param name - */ - disableWidget(name: string): void; - - /** - * 显示某个 Area - * show area - * @param areaName name of area - */ - showArea(areaName: string): void; - - /** - * 隐藏某个 Area - * hide area - * @param areaName name of area - */ - hideArea(areaName: string): void; - - /** - * 监听 Panel 实例显示事件 - * set callback for panel shown event - * @param listener - * @returns - */ - onShowPanel( - listener: (paneName?: string, panel?: IPublicModelSkeletonItem) => void, - ): IPublicTypeDisposable; - - /** - * 监听 Panel 实例隐藏事件 - * set callback for panel hidden event - * @param listener - * @returns - */ - onHidePanel( - listener: (paneName?: string, panel?: IPublicModelSkeletonItem) => void, - ): IPublicTypeDisposable; - - /** - * 监听 Widget 实例 Disable 事件 - * @param listener - */ - onDisableWidget( - listener: (paneName?: string, panel?: IPublicModelSkeletonItem) => void, - ): IPublicTypeDisposable; - - /** - * 监听 Widget 实例 Enable 事件 - * @param listener - */ - onEnableWidget( - listener: (paneName?: string, panel?: IPublicModelSkeletonItem) => void, - ): IPublicTypeDisposable; - - /** - * 监听 Widget 显示事件 - * set callback for widget shown event - * @param listener - * @returns - */ - onShowWidget( - listener: (paneName?: string, panel?: IPublicModelSkeletonItem) => void, - ): IPublicTypeDisposable; - - /** - * 监听 Widget 隐藏事件 - * set callback for widget hidden event - * @param listener - * @returns - */ - onHideWidget( - listener: (paneName?: string, panel?: IPublicModelSkeletonItem) => void, - ): IPublicTypeDisposable; - - /** - * 注册一个面板的配置转换器(transducer)。 - * Registers a configuration transducer for a panel. - * @param {IPublicTypeConfigTransducer} transducer - * - 要注册的转换器函数。该函数接受一个配置对象(类型为 IPublicTypeSkeletonConfig)作为输入,并返回修改后的配置对象。 - * - The transducer function to be registered. This function takes a configuration object (of type IPublicTypeSkeletonConfig) as input and returns a modified configuration object. - * - * @param {number} level - * - 转换器的优先级。优先级较高的转换器会先执行。 - * - The priority level of the transducer. Transducers with higher priority levels are executed first. - * - * @param {string} [id] - * - (可选)转换器的唯一标识符。用于在需要时引用或操作特定的转换器。 - * - (Optional) A unique identifier for the transducer. Used for referencing or manipulating a specific transducer when needed. - */ - registerConfigTransducer( - transducer: IPublicTypeConfigTransducer, - level: number, - id?: string, - ): void; -} diff --git a/packages/types/src/shell/api/workspace.ts b/packages/types/src/shell/api/workspace.ts deleted file mode 100644 index 93b4d1c23..000000000 --- a/packages/types/src/shell/api/workspace.ts +++ /dev/null @@ -1,73 +0,0 @@ -import { IPublicModelWindow } from '../model'; -import { - IPublicApiPlugins, - IPublicApiSkeleton, - IPublicModelResource, - IPublicResourceList, - IPublicTypeDisposable, - IPublicTypeResourceType, -} from '..'; - -export interface IPublicApiWorkspace< - Plugins = IPublicApiPlugins, - Skeleton = IPublicApiSkeleton, - ModelWindow = IPublicModelWindow, - Resource = IPublicModelResource, -> { - /** 是否启用 workspace 模式 */ - isActive: boolean; - - /** 当前设计器窗口 */ - window: ModelWindow | null; - - plugins: Plugins; - - skeleton: Skeleton; - - /** 当前设计器的编辑窗口 */ - windows: ModelWindow[]; - - /** 获取资源树列表 */ - get resourceList(): IPublicModelResource[]; - - /** 设置资源树列表 */ - setResourceList(resourceList: IPublicResourceList): void; - - /** 资源树列表更新事件 */ - onResourceListChange(fn: (resourceList: IPublicResourceList) => void): IPublicTypeDisposable; - - /** 注册资源 */ - registerResourceType(resourceTypeModel: IPublicTypeResourceType): void; - - /** 打开视图窗口 */ - openEditorWindow(resource: Resource, sleep?: boolean): Promise; - - /** 通过视图 id 打开窗口 */ - openEditorWindowById(id: string): void; - - /** - * 移除视图窗口 - */ - removeEditorWindow(resource: Resource): void; - - /** 通过视图 id 移除窗口 */ - removeEditorWindowById(id: string): void; - - /** 窗口新增/删除的事件 */ - onChangeWindows(fn: () => void): IPublicTypeDisposable; - - /** active 窗口变更事件 */ - onChangeActiveWindow(fn: () => void): IPublicTypeDisposable; - - /** - * active 视图变更事件 - * @since v1.1.7 - */ - onChangeActiveEditorView(fn: () => void): IPublicTypeDisposable; - - /** - * window 下的所有视图 renderer ready 事件 - * @since v1.1.7 - */ - onWindowRendererReady(fn: () => void): IPublicTypeDisposable; -} diff --git a/packages/types/src/shell/enum/context-menu.ts b/packages/types/src/shell/enum/context-menu.ts deleted file mode 100644 index 190dc039d..000000000 --- a/packages/types/src/shell/enum/context-menu.ts +++ /dev/null @@ -1,7 +0,0 @@ -export enum IPublicEnumContextMenuType { - SEPARATOR = 'separator', - // 'menuItem' - MENU_ITEM = 'menuItem', - // 'nodeTree' - NODE_TREE = 'nodeTree', -} diff --git a/packages/types/src/shell/enum/drag-object-type.ts b/packages/types/src/shell/enum/drag-object-type.ts deleted file mode 100644 index 8e7bbccf3..000000000 --- a/packages/types/src/shell/enum/drag-object-type.ts +++ /dev/null @@ -1,4 +0,0 @@ -export enum IPublicEnumDragObjectType { - Node = 'node', - NodeData = 'nodedata', -} diff --git a/packages/types/src/shell/enum/event-names.ts b/packages/types/src/shell/enum/event-names.ts deleted file mode 100644 index 563ac7fe6..000000000 --- a/packages/types/src/shell/enum/event-names.ts +++ /dev/null @@ -1,9 +0,0 @@ -/** - * 所有公开可用的事件名定义 - * All public event names - * names should be like 'namespace.modelName.whatHappened' - * - */ -// eslint-disable-next-line no-shadow -export enum IPublicEnumEventNames { -} diff --git a/packages/types/src/shell/enum/index.ts b/packages/types/src/shell/enum/index.ts deleted file mode 100644 index d746976fb..000000000 --- a/packages/types/src/shell/enum/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -export * from './event-names'; -export * from './transition-type'; -export * from './transform-stage'; -export * from './drag-object-type'; -export * from './prop-value-changed-type'; -export * from './plugin-register-level'; -export * from './context-menu'; diff --git a/packages/types/src/shell/enum/plugin-register-level.ts b/packages/types/src/shell/enum/plugin-register-level.ts deleted file mode 100644 index 3ec37cb3a..000000000 --- a/packages/types/src/shell/enum/plugin-register-level.ts +++ /dev/null @@ -1,6 +0,0 @@ -export enum IPublicEnumPluginRegisterLevel { - Default = 'default', - Workspace = 'workspace', - Resource = 'resource', - EditorView = 'editorView', -} diff --git a/packages/types/src/shell/enum/prop-value-changed-type.ts b/packages/types/src/shell/enum/prop-value-changed-type.ts deleted file mode 100644 index 4ba20beaf..000000000 --- a/packages/types/src/shell/enum/prop-value-changed-type.ts +++ /dev/null @@ -1,10 +0,0 @@ -export enum IPublicEnumPropValueChangedType { - /** - * normal set value - */ - SET_VALUE = 'SET_VALUE', - /** - * value changed caused by sub-prop value change - */ - SUB_VALUE_CHANGE = 'SUB_VALUE_CHANGE' -} diff --git a/packages/types/src/shell/enum/transform-stage.ts b/packages/types/src/shell/enum/transform-stage.ts deleted file mode 100644 index ba0a4e8ec..000000000 --- a/packages/types/src/shell/enum/transform-stage.ts +++ /dev/null @@ -1,8 +0,0 @@ -export enum IPublicEnumTransformStage { - Render = 'render', - Serilize = 'serilize', - Save = 'save', - Clone = 'clone', - Init = 'init', - Upgrade = 'upgrade', -} diff --git a/packages/types/src/shell/enum/transition-type.ts b/packages/types/src/shell/enum/transition-type.ts deleted file mode 100644 index 90322c18b..000000000 --- a/packages/types/src/shell/enum/transition-type.ts +++ /dev/null @@ -1,4 +0,0 @@ -export const enum IPublicEnumTransitionType { - /** 节点更新后重绘处理 */ - REPAINT, -} diff --git a/packages/types/src/shell/index.ts b/packages/types/src/shell/index.ts deleted file mode 100644 index 534c1fae1..000000000 --- a/packages/types/src/shell/index.ts +++ /dev/null @@ -1,5 +0,0 @@ - -export * from './type'; -export * from './api'; -export * from './model'; -export * from './enum'; diff --git a/packages/types/src/shell/model/active-tracker.ts b/packages/types/src/shell/model/active-tracker.ts deleted file mode 100644 index ac116a947..000000000 --- a/packages/types/src/shell/model/active-tracker.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { IPublicTypeActiveTarget } from '../type'; -import { IPublicModelNode } from './node'; - -export interface IPublicModelActiveTracker { - - /** - * @since 1.1.7 - */ - target: IPublicTypeActiveTarget | null; - - onChange(fn: (target: IPublicTypeActiveTarget) => void): () => void; - - track(node: IPublicModelNode): void; -} diff --git a/packages/types/src/shell/model/clipboard.ts b/packages/types/src/shell/model/clipboard.ts deleted file mode 100644 index 3c57373b2..000000000 --- a/packages/types/src/shell/model/clipboard.ts +++ /dev/null @@ -1,25 +0,0 @@ - -export interface IPublicModelClipboard { - - /** - * 给剪贴板赋值 - * set data to clipboard - * - * @param {*} data - * @since v1.1.0 - */ - setData(data: any): void; - - /** - * 设置剪贴板数据设置的回调 - * set callback for clipboard provide paste data - * - * @param {KeyboardEvent} keyboardEvent - * @param {(data: any, clipboardEvent: ClipboardEvent) => void} cb - * @since v1.1.0 - */ - waitPasteData( - keyboardEvent: KeyboardEvent, - cb: (data: any, clipboardEvent: ClipboardEvent) => void, - ): void; -} diff --git a/packages/types/src/shell/model/component-meta.ts b/packages/types/src/shell/model/component-meta.ts deleted file mode 100644 index 88dbfe6af..000000000 --- a/packages/types/src/shell/model/component-meta.ts +++ /dev/null @@ -1,115 +0,0 @@ -import { IPublicTypeNodeSchema, IPublicTypeNodeData, IPublicTypeIconType, IPublicTypeTransformedComponentMetadata, IPublicTypeI18nData, IPublicTypeNpmInfo, IPublicTypeAdvanced, IPublicTypeFieldConfig, IPublicTypeComponentAction } from '../type'; -import { ReactElement } from 'react'; -import { IPublicModelNode } from './node'; - -export interface IPublicModelComponentMeta< - Node = IPublicModelNode -> { - - /** - * 组件名 - * component name - */ - get componentName(): string; - - /** - * 是否是「容器型」组件 - * is container node or not - */ - get isContainer(): boolean; - - /** - * 是否是最小渲染单元。 - * 当组件需要重新渲染时: - * 若为最小渲染单元,则只渲染当前组件, - * 若不为最小渲染单元,则寻找到上层最近的最小渲染单元进行重新渲染,直至根节点。 - * - * check if this is a mininal render unit. - * when a rerender is needed for a component: - * case 'it`s a mininal render unit': only render itself. - * case 'it`s not a mininal render unit': find a mininal render unit to render in - * its ancesters until root node is reached. - */ - get isMinimalRenderUnit(): boolean; - - /** - * 是否为「模态框」组件 - * check if this is a modal component or not. - */ - get isModal(): boolean; - - /** - * 获取用于设置面板显示用的配置 - * get configs for Settings Panel - */ - get configure(): IPublicTypeFieldConfig[]; - - /** - * 标题 - * title for this component - */ - get title(): string | IPublicTypeI18nData | ReactElement; - - /** - * 图标 - * icon config for this component - */ - get icon(): IPublicTypeIconType; - - /** - * 组件 npm 信息 - * npm informations - */ - get npm(): IPublicTypeNpmInfo; - - /** - * 当前组件的可用 Action - * available actions - */ - get availableActions(): IPublicTypeComponentAction[]; - - /** - * 组件元数据中高级配置部分 - * configure.advanced - * @since v1.1.0 - */ - get advanced(): IPublicTypeAdvanced; - - /** - * 设置 npm 信息 - * set method for npm inforamtion - * @param npm - */ - setNpm(npm: IPublicTypeNpmInfo): void; - - /** - * 获取元数据 - * get component metadata - */ - getMetadata(): IPublicTypeTransformedComponentMetadata; - - /** - * 检测当前对应节点是否可被放置在父节点中 - * check if the current node could be placed in parent node - * @param my 当前节点 - * @param parent 父节点 - */ - checkNestingUp(my: Node | IPublicTypeNodeData, parent: any): boolean; - - /** - * 检测目标节点是否可被放置在父节点中 - * check if the target node(s) could be placed in current node - * @param my 当前节点 - * @param parent 父节点 - */ - checkNestingDown( - my: Node | IPublicTypeNodeData, - target: IPublicTypeNodeSchema | Node | IPublicTypeNodeSchema[], - ): boolean; - - /** - * 刷新元数据,会触发元数据的重新解析和刷新 - * refresh metadata - */ - refreshMetadata(): void; -} diff --git a/packages/types/src/shell/model/detecting.ts b/packages/types/src/shell/model/detecting.ts deleted file mode 100644 index ec6320ad2..000000000 --- a/packages/types/src/shell/model/detecting.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { IPublicModelNode } from './'; -import { IPublicTypeDisposable } from '../type'; - -export interface IPublicModelDetecting { - - /** - * 是否启用 - * check if current detecting is enabled - * @since v1.1.0 - */ - get enable(): boolean; - - /** - * 当前 hover 的节点 - * get current hovering node - * @since v1.0.16 - */ - get current(): Node | null; - - /** - * hover 指定节点 - * capture node with nodeId - * @param id 节点 id - */ - capture(id: string): void; - - /** - * hover 离开指定节点 - * release node with nodeId - * @param id 节点 id - */ - release(id: string): void; - - /** - * 清空 hover 态 - * clear all hover state - */ - leave(): void; - - /** - * hover 节点变化事件 - * set callback which will be called when hovering object changed. - * @since v1.1.0 - */ - onDetectingChange(fn: (node: Node | null) => void): IPublicTypeDisposable; -} diff --git a/packages/types/src/shell/model/document-model.ts b/packages/types/src/shell/model/document-model.ts deleted file mode 100644 index 1266fe498..000000000 --- a/packages/types/src/shell/model/document-model.ts +++ /dev/null @@ -1,248 +0,0 @@ -import { - IPublicTypeRootSchema, - IPublicTypeDragNodeDataObject, - IPublicTypeDragNodeObject, - IPublicTypePropChangeOptions, - IPublicTypeDisposable, -} from '../type'; -import { IPublicEnumTransformStage } from '../enum'; -import { IPublicApiProject } from '../api'; -import { - IPublicModelDropLocation, - IPublicModelDetecting, - IPublicModelNode, - IPublicModelSelection, - IPublicModelHistory, - IPublicModelModalNodesManager, -} from './'; -import { IPublicTypeNodeData, IPublicTypeNodeSchema, IPublicTypeOnChangeOptions } from '../type'; - -export interface IPublicModelDocumentModel< - Selection = IPublicModelSelection, - History = IPublicModelHistory, - Node = IPublicModelNode, - DropLocation = IPublicModelDropLocation, - ModalNodesManager = IPublicModelModalNodesManager, - Project = IPublicApiProject, -> { - /** - * 节点选中区模型实例 - * instance of selection - */ - selection: Selection; - - /** - * 画布节点 hover 区模型实例 - * instance of detecting - */ - detecting: IPublicModelDetecting; - - /** - * 操作历史模型实例 - * instance of history - */ - history: History; - - /** - * id - */ - get id(): string; - - set id(id); - - /** - * 获取当前文档所属的 project - * get project which this documentModel belongs to - * @returns - */ - get project(): Project; - - /** - * 获取文档的根节点 - * root node of this documentModel - * @returns - */ - get root(): Node | null; - - get focusNode(): Node | null; - - set focusNode(node: Node | null); - - /** - * 获取文档下所有节点 - * @returns - */ - get nodesMap(): Map; - - /** - * 模态节点管理 - * get instance of modalNodesManager - */ - get modalNodesManager(): ModalNodesManager | null; - - /** - * 根据 nodeId 返回 Node 实例 - * get node by nodeId - * @param nodeId - * @returns - */ - getNodeById(nodeId: string): Node | null; - - /** - * 导入 schema - * import schema data - * @param schema - */ - importSchema(schema: IPublicTypeRootSchema): void; - - /** - * 导出 schema - * export schema - * @param stage - * @returns - */ - exportSchema(stage: IPublicEnumTransformStage): IPublicTypeRootSchema | undefined; - - /** - * 插入节点 - * insert a node - */ - insertNode( - parent: Node, - thing: Node | IPublicTypeNodeData, - at?: number | null | undefined, - copy?: boolean | undefined, - ): Node | null; - - /** - * 创建一个节点 - * create a node - * @param data - * @returns - */ - createNode(data: S): T | null; - - /** - * 移除指定节点/节点id - * remove a node by node instance or nodeId - * @param idOrNode - */ - removeNode(idOrNode: string | Node): void; - - /** - * componentsMap of documentModel - * @param extraComps - * @returns - */ - getComponentsMap(extraComps?: string[]): any; - - /** - * 检查拖拽放置的目标节点是否可以放置该拖拽对象 - * check if dragOjbect can be put in this dragTarget - * @param dropTarget 拖拽放置的目标节点 - * @param dragObject 拖拽的对象 - * @returns boolean 是否可以放置 - * @since v1.0.16 - */ - checkNesting( - dropTarget: Node, - dragObject: IPublicTypeDragNodeObject | IPublicTypeDragNodeDataObject, - ): boolean; - - /** - * 当前 document 新增节点事件 - * set callback for event on node is created for a document - */ - onAddNode(fn: (node: Node) => void): IPublicTypeDisposable; - - /** - * 当前 document 新增节点事件,此时节点已经挂载到 document 上 - * set callback for event on node is mounted to canvas - */ - onMountNode(fn: (payload: { node: Node }) => void): IPublicTypeDisposable; - - /** - * 当前 document 删除节点事件 - * set callback for event on node is removed - */ - onRemoveNode(fn: (node: Node) => void): IPublicTypeDisposable; - - /** - * 当前 document 的 hover 变更事件 - * - * set callback for event on detecting changed - */ - onChangeDetecting(fn: (node: Node) => void): IPublicTypeDisposable; - - /** - * 当前 document 的选中变更事件 - * set callback for event on selection changed - */ - onChangeSelection(fn: (ids: string[]) => void): IPublicTypeDisposable; - - /** - * 当前 document 的节点显隐状态变更事件 - * set callback for event on visibility changed for certain node - * @param fn - */ - onChangeNodeVisible(fn: (node: Node, visible: boolean) => void): IPublicTypeDisposable; - - /** - * 当前 document 的节点 children 变更事件 - * @param fn - */ - onChangeNodeChildren(fn: (info: IPublicTypeOnChangeOptions) => void): IPublicTypeDisposable; - - /** - * 当前 document 节点属性修改事件 - * @param fn - */ - onChangeNodeProp(fn: (info: IPublicTypePropChangeOptions) => void): IPublicTypeDisposable; - - /** - * import schema event - * @param fn - * @since v1.0.15 - */ - onImportSchema(fn: (schema: IPublicTypeRootSchema) => void): IPublicTypeDisposable; - - /** - * 判断是否当前节点处于被探测状态 - * check is node being detected - * @param node - * @since v1.1.0 - */ - isDetectingNode(node: Node): boolean; - - /** - * 获取当前的 DropLocation 信息 - * get current drop location - * @since v1.1.0 - */ - get dropLocation(): DropLocation | null; - - /** - * 设置当前的 DropLocation 信息 - * set current drop location - * @since v1.1.0 - */ - set dropLocation(loc: DropLocation | null); - - /** - * 设置聚焦节点变化的回调 - * triggered focused node is set mannually from plugin - * @param fn - * @since v1.1.0 - */ - onFocusNodeChanged( - fn: (doc: IPublicModelDocumentModel, focusNode: Node) => void, - ): IPublicTypeDisposable; - - /** - * 设置 DropLocation 变化的回调 - * triggered when drop location changed - * @param fn - * @since v1.1.0 - */ - onDropLocationChanged(fn: (doc: IPublicModelDocumentModel) => void): IPublicTypeDisposable; -} diff --git a/packages/types/src/shell/model/drag-object.ts b/packages/types/src/shell/model/drag-object.ts deleted file mode 100644 index 92d92eca3..000000000 --- a/packages/types/src/shell/model/drag-object.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { IPublicEnumDragObjectType } from '../enum'; -import { IPublicTypeNodeSchema } from '../type'; -import { IPublicModelNode } from './node'; - -export class IPublicModelDragObject { - type: IPublicEnumDragObjectType.Node | IPublicEnumDragObjectType.NodeData; - - data: IPublicTypeNodeSchema | IPublicTypeNodeSchema[] | null; - - nodes: (IPublicModelNode | null)[] | null; -} diff --git a/packages/types/src/shell/model/dragon.ts b/packages/types/src/shell/model/dragon.ts deleted file mode 100644 index 917149faf..000000000 --- a/packages/types/src/shell/model/dragon.ts +++ /dev/null @@ -1,70 +0,0 @@ -/* eslint-disable max-len */ -import { IPublicTypeDisposable, IPublicTypeDragNodeDataObject, IPublicTypeDragObject } from '../type'; -import { IPublicModelDragObject, IPublicModelLocateEvent, IPublicModelNode } from './'; - -export interface IPublicModelDragon< - Node = IPublicModelNode, - LocateEvent = IPublicModelLocateEvent -> { - - /** - * 是否正在拖动 - * is dragging or not - */ - get dragging(): boolean; - - /** - * 绑定 dragstart 事件 - * bind a callback function which will be called on dragging start - * @param func - * @returns - */ - onDragstart(func: (e: LocateEvent) => any): IPublicTypeDisposable; - - /** - * 绑定 drag 事件 - * bind a callback function which will be called on dragging - * @param func - * @returns - */ - onDrag(func: (e: LocateEvent) => any): IPublicTypeDisposable; - - /** - * 绑定 dragend 事件 - * bind a callback function which will be called on dragging end - * @param func - * @returns - */ - onDragend(func: (o: { dragObject: IPublicModelDragObject; copy?: boolean }) => any): IPublicTypeDisposable; - - /** - * 设置拖拽监听的区域 shell,以及自定义拖拽转换函数 boost - * set a html element as shell to dragon as monitoring target, and - * set boost function which is used to transform a MouseEvent to type - * IPublicTypeDragNodeDataObject. - * @param shell 拖拽监听的区域 - * @param boost 拖拽转换函数 - */ - from(shell: Element, boost: (e: MouseEvent) => IPublicTypeDragNodeDataObject | null): any; - - /** - * 发射拖拽对象 - * boost your dragObject for dragging(flying) - * - * @param dragObject 拖拽对象 - * @param boostEvent 拖拽初始时事件 - */ - boost(dragObject: IPublicTypeDragObject, boostEvent: MouseEvent | DragEvent, fromRglNode?: Node): void; - - /** - * 添加投放感应区 - * add sensor area - */ - addSensor(sensor: any): void; - - /** - * 移除投放感应 - * remove sensor area - */ - removeSensor(sensor: any): void; -} diff --git a/packages/types/src/shell/model/drop-location.ts b/packages/types/src/shell/model/drop-location.ts deleted file mode 100644 index e25522bce..000000000 --- a/packages/types/src/shell/model/drop-location.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { IPublicTypeLocationDetail } from '../type'; -import { IPublicModelLocateEvent, IPublicModelNode } from './'; - -export interface IPublicModelDropLocation { - - /** - * 拖拽位置目标 - * get target of dropLocation - */ - get target(): IPublicModelNode | null; - - /** - * 拖拽放置位置详情 - * get detail of dropLocation - */ - get detail(): IPublicTypeLocationDetail; - - /** - * 拖拽放置位置对应的事件 - * get event of dropLocation - */ - get event(): IPublicModelLocateEvent; - - /** - * 获取一份当前对象的克隆 - * get a clone object of current dropLocation - */ - clone(event: IPublicModelLocateEvent): IPublicModelDropLocation; -} diff --git a/packages/types/src/shell/model/editor-view.ts b/packages/types/src/shell/model/editor-view.ts deleted file mode 100644 index ccdfe5cca..000000000 --- a/packages/types/src/shell/model/editor-view.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { IPublicModelPluginContext } from './plugin-context'; - -export interface IPublicModelEditorView extends IPublicModelPluginContext { - viewName: string; - - viewType: 'editor' | 'webview'; -} diff --git a/packages/types/src/shell/model/editor.ts b/packages/types/src/shell/model/editor.ts deleted file mode 100644 index f8c5c1d76..000000000 --- a/packages/types/src/shell/model/editor.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { EventEmitter } from 'events'; -import StrictEventEmitter from 'strict-event-emitter-types'; -import * as GlobalEvent from '../../event'; -import { IPublicApiEvent } from '../api'; -import { IPublicTypeEditorValueKey, IPublicTypeEditorGetOptions, IPublicTypeEditorGetResult, IPublicTypeEditorRegisterOptions, IPublicTypeAssetsJson } from '../type'; - -export interface IPublicModelEditor - extends StrictEventEmitter { - get: ( - keyOrType: KeyOrType, - opt?: IPublicTypeEditorGetOptions - ) => IPublicTypeEditorGetResult | undefined; - - has: (keyOrType: IPublicTypeEditorValueKey) => boolean; - - set: (key: IPublicTypeEditorValueKey, data: any) => void | Promise; - - /** - * 获取 keyOrType 一次 - */ - onceGot: ( - keyOrType: KeyOrType - ) => Promise>; - - /** - * 获取 keyOrType 多次 - */ - onGot: ( - keyOrType: KeyOrType, - fn: (data: IPublicTypeEditorGetResult) => void - ) => () => void; - - /** - * 监听 keyOrType 变化 - */ - onChange: ( - keyOrType: KeyOrType, - fn: (data: IPublicTypeEditorGetResult) => void - ) => () => void; - - register: ( - data: any, - key?: IPublicTypeEditorValueKey, - options?: IPublicTypeEditorRegisterOptions - ) => void; - - get eventBus(): IPublicApiEvent; - - setAssets(assets: IPublicTypeAssetsJson): void; -} diff --git a/packages/types/src/shell/model/engine-config.ts b/packages/types/src/shell/model/engine-config.ts deleted file mode 100644 index c9473cd12..000000000 --- a/packages/types/src/shell/model/engine-config.ts +++ /dev/null @@ -1,66 +0,0 @@ -import { IPublicTypeDisposable } from '../type'; -import { IPublicModelPreference } from './'; - -export interface IPublicModelEngineConfig { - - /** - * 判断指定 key 是否有值 - * check if config has certain key configed - * @param key - * @returns - */ - has(key: string): boolean; - - /** - * 获取指定 key 的值 - * get value by key - * @param key - * @param defaultValue - * @returns - */ - get(key: string, defaultValue?: any): any; - - /** - * 设置指定 key 的值 - * set value for certain key - * @param key - * @param value - */ - set(key: string, value: any): void; - - /** - * 批量设值,set 的对象版本 - * set multiple config key-values - * @param config - */ - setConfig(config: { [key: string]: any }): void; - - /** - * 获取指定 key 的值,若此时还未赋值,则等待,若已有值,则直接返回值 - * 注:此函数返回 Promise 实例,只会执行(fullfill)一次 - * wait until value of certain key is set, will only be - * triggered once. - * @param key - * @returns - */ - onceGot(key: string): Promise; - - /** - * 获取指定 key 的值,函数回调模式,若多次被赋值,回调会被多次调用 - * set callback for event of value set for some key - * this will be called each time the value is set - * @param key - * @param fn - * @returns - */ - onGot(key: string, fn: (data: any) => void): IPublicTypeDisposable; - - /** - * 获取全局 Preference, 用于管理全局浏览器侧用户 Preference,如 Panel 是否钉住 - * get global user preference manager, which can be use to store - * user`s preference in user localstorage, such as a panel is pinned or not. - * @returns {IPublicModelPreference} - * @since v1.1.0 - */ - getPreference(): IPublicModelPreference; -} diff --git a/packages/types/src/shell/model/exclusive-group.ts b/packages/types/src/shell/model/exclusive-group.ts deleted file mode 100644 index b930a1344..000000000 --- a/packages/types/src/shell/model/exclusive-group.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { IPublicModelNode, IPublicTypeTitleContent } from '..'; - -export interface IPublicModelExclusiveGroup< - Node = IPublicModelNode, -> { - readonly id: string | undefined; - readonly title: IPublicTypeTitleContent | undefined; - get firstNode(): Node | null; - setVisible(node: Node): void; -} diff --git a/packages/types/src/shell/model/history.ts b/packages/types/src/shell/model/history.ts deleted file mode 100644 index 9d75295ab..000000000 --- a/packages/types/src/shell/model/history.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { IPublicTypeDisposable } from '../type'; - -export interface IPublicModelHistory { - - /** - * 历史记录跳转到指定位置 - * go to a specific history - * @param cursor - */ - go(cursor: number): void; - - /** - * 历史记录后退 - * go backward in history - */ - back(): void; - - /** - * 历史记录前进 - * go forward in history - */ - forward(): void; - - /** - * 保存当前状态 - * do save current change as a record in history - */ - savePoint(): void; - - /** - * 当前是否是「保存点」,即是否有状态变更但未保存 - * check if there is unsaved change for history - */ - isSavePoint(): boolean; - - /** - * 获取 state,判断当前是否为「可回退」、「可前进」的状态 - * get flags in number which indicat current change state - * - * | 1 | 1 | 1 | - * | -------- | -------- | -------- | - * | modified | redoable | undoable | - * eg. - * 7 means : modified && redoable && undoable - * 5 means : modified && undoable - */ - getState(): number; - - /** - * 监听 state 变更事件 - * monitor on stateChange event - * @param func - */ - onChangeState(func: () => any): IPublicTypeDisposable; - - /** - * 监听历史记录游标位置变更事件 - * monitor on cursorChange event - * @param func - */ - onChangeCursor(func: () => any): IPublicTypeDisposable; -} diff --git a/packages/types/src/shell/model/index.ts b/packages/types/src/shell/model/index.ts deleted file mode 100644 index 2b7636ab7..000000000 --- a/packages/types/src/shell/model/index.ts +++ /dev/null @@ -1,33 +0,0 @@ -export * from './component-meta'; -export * from './detecting'; -export * from './document-model'; -export * from './drag-object'; -export * from './dragon'; -export * from './drop-location'; -export * from './history'; -export * from './locate-event'; -export * from './modal-nodes-manager'; -export * from './node-children'; -export * from './node'; -export * from './prop'; -export * from './props'; -export * from './selection'; -export * from './setting-top-entry'; -export * from '../type/plugin'; -export * from './window'; -export * from './scroll-target'; -export * from './scroller'; -export * from './active-tracker'; -export * from './exclusive-group'; -export * from './plugin-context'; -export * from './engine-config'; -export * from './editor'; -export * from './preference'; -export * from './plugin-instance'; -export * from './sensor'; -export * from './resource'; -export * from './clipboard'; -export * from './setting-field'; -export * from './editor-view'; -export * from './skeleton-item'; -export * from './simulator-render'; diff --git a/packages/types/src/shell/model/locate-event.ts b/packages/types/src/shell/model/locate-event.ts deleted file mode 100644 index bb64ab15e..000000000 --- a/packages/types/src/shell/model/locate-event.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { IPublicModelDocumentModel, IPublicModelDragObject } from './'; - -export interface IPublicModelLocateEvent { - - get type(): string; - - /** - * 浏览器窗口坐标系 - */ - readonly globalX: number; - readonly globalY: number; - - /** - * 原始事件 - */ - readonly originalEvent: MouseEvent | DragEvent; - - /** - * 浏览器事件响应目标 - */ - target?: Element | null; - - canvasX?: number; - - canvasY?: number; - - /** - * 事件订正标识,初始构造时,从发起端构造,缺少 canvasX,canvasY, 需要经过订正才有 - */ - fixed?: true; - - /** - * 激活或目标文档 - */ - documentModel?: IPublicModelDocumentModel | null; - - get dragObject(): IPublicModelDragObject | null; -} diff --git a/packages/types/src/shell/model/modal-nodes-manager.ts b/packages/types/src/shell/model/modal-nodes-manager.ts deleted file mode 100644 index 07656c070..000000000 --- a/packages/types/src/shell/model/modal-nodes-manager.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { IPublicModelNode } from './'; - -export interface IPublicModelModalNodesManager { - - /** - * 设置模态节点,触发内部事件 - * set modal nodes, trigger internal events - */ - setNodes(): void; - - /** - * 获取模态节点(们) - * get modal nodes - */ - getModalNodes(): Node[]; - - /** - * 获取当前可见的模态节点 - * get current visible modal node - */ - getVisibleModalNode(): Node | null; - - /** - * 隐藏模态节点(们) - * hide modal nodes - */ - hideModalNodes(): void; - - /** - * 设置指定节点为可见态 - * set specfic model node as visible - * @param node Node - */ - setVisible(node: Node): void; - - /** - * 设置指定节点为不可见态 - * set specfic model node as invisible - * @param node Node - */ - setInvisible(node: Node): void; -} diff --git a/packages/types/src/shell/model/node-children.ts b/packages/types/src/shell/model/node-children.ts deleted file mode 100644 index 6f0d4b8f1..000000000 --- a/packages/types/src/shell/model/node-children.ts +++ /dev/null @@ -1,177 +0,0 @@ -import { IPublicTypeNodeSchema, IPublicTypeNodeData } from '../type'; -import { IPublicEnumTransformStage } from '../enum'; -import { IPublicModelNode } from './'; - -export interface IPublicModelNodeChildren< - Node = IPublicModelNode -> { - - /** - * 返回当前 children 实例所属的节点实例 - * get owner node of this nodeChildren - */ - get owner(): Node | null; - - /** - * children 内的节点实例数 - * get count of child nodes - */ - get size(): number; - - /** - * 是否为空 - * - * @returns - */ - get isEmptyNode(): boolean; - - /** - * judge if it is not empty - */ - get notEmptyNode(): boolean; - - /** - * 删除指定节点 - * - * delete the node - * @param node - */ - delete(node: Node): boolean; - - /** - * 插入一个节点 - * - * insert a node at specific position - * @param node 待插入节点 - * @param at 插入下标 - * @returns - */ - insert(node: Node, at?: number | null): void; - - /** - * 返回指定节点的下标 - * - * get index of node in current children - * @param node - * @returns - */ - indexOf(node: Node): number; - - /** - * 类似数组 splice 操作 - * - * provide the same function with {Array.prototype.splice} - * @param start - * @param deleteCount - * @param node - */ - splice(start: number, deleteCount: number, node?: Node): any; - - /** - * 返回指定下标的节点 - * - * get node with index - * @param index - * @returns - */ - get(index: number): Node | null; - - /** - * 是否包含指定节点 - * - * check if node exists in current children - * @param node - * @returns - */ - has(node: Node): boolean; - - /** - * 类似数组的 forEach - * - * provide the same function with {Array.prototype.forEach} - * @param fn - */ - forEach(fn: (node: Node, index: number) => void): void; - - /** - * 类似数组的 reverse - * - * provide the same function with {Array.prototype.reverse} - */ - reverse(): Node[]; - - /** - * 类似数组的 map - * - * provide the same function with {Array.prototype.map} - * @param fn - */ - map(fn: (node: Node, index: number) => T): T[] | null; - - /** - * 类似数组的 every - * provide the same function with {Array.prototype.every} - * @param fn - */ - every(fn: (node: Node, index: number) => boolean): boolean; - - /** - * 类似数组的 some - * provide the same function with {Array.prototype.some} - * @param fn - */ - some(fn: (node: Node, index: number) => boolean): boolean; - - /** - * 类似数组的 filter - * provide the same function with {Array.prototype.filter} - * @param fn - */ - filter(fn: (node: Node, index: number) => boolean): any; - - /** - * 类似数组的 find - * provide the same function with {Array.prototype.find} - * @param fn - */ - find(fn: (node: Node, index: number) => boolean): Node | null | undefined; - - /** - * 类似数组的 reduce - * - * provide the same function with {Array.prototype.reduce} - * @param fn - */ - reduce(fn: (acc: any, cur: Node) => any, initialValue: any): void; - - /** - * 导入 schema - * - * import schema - * @param data - */ - importSchema(data?: IPublicTypeNodeData | IPublicTypeNodeData[]): void; - - /** - * 导出 schema - * - * export schema - * @param stage - */ - exportSchema(stage: IPublicEnumTransformStage): IPublicTypeNodeSchema; - - /** - * 执行新增、删除、排序等操作 - * - * excute remove/add/sort operations - * @param remover - * @param adder - * @param sorter - */ - mergeChildren( - remover: (node: Node, idx: number) => boolean, - adder: (children: Node[]) => IPublicTypeNodeData[] | null, - sorter: (firstNode: Node, secondNode: Node) => number - ): any; - -} diff --git a/packages/types/src/shell/model/node.ts b/packages/types/src/shell/model/node.ts deleted file mode 100644 index 0347099fc..000000000 --- a/packages/types/src/shell/model/node.ts +++ /dev/null @@ -1,451 +0,0 @@ -import { ReactElement } from 'react'; -import { IPublicTypeNodeSchema, IPublicTypeIconType, IPublicTypeI18nData, IPublicTypeCompositeValue, IPublicTypePropsMap, IPublicTypePropsList } from '../type'; -import { IPublicEnumTransformStage } from '../enum'; -import { IPublicModelNodeChildren, IPublicModelComponentMeta, IPublicModelProp, IPublicModelProps, IPublicModelSettingTopEntry, IPublicModelDocumentModel, IPublicModelExclusiveGroup } from './'; - -export interface IBaseModelNode< - Document = IPublicModelDocumentModel, - Node = IPublicModelNode, - NodeChildren = IPublicModelNodeChildren, - ComponentMeta = IPublicModelComponentMeta, - SettingTopEntry = IPublicModelSettingTopEntry, - Props = IPublicModelProps, - Prop = IPublicModelProp, - ExclusiveGroup = IPublicModelExclusiveGroup -> { - - /** - * 节点 id - * node id - */ - id: string; - - /** - * 节点标题 - * title of node - */ - get title(): string | IPublicTypeI18nData | ReactElement; - - /** - * 是否为「容器型」节点 - * check if node is a container type node - * @since v1.1.0 - */ - get isContainerNode(): boolean; - - /** - * 是否为根节点 - * check if node is root in the tree - * @since v1.1.0 - */ - get isRootNode(): boolean; - - /** - * 是否为空节点(无 children 或者 children 为空) - * check if current node is empty, which means no children or children is empty - * @since v1.1.0 - */ - get isEmptyNode(): boolean; - - /** - * 是否为 Page 节点 - * check if node is Page - * @since v1.1.0 - */ - get isPageNode(): boolean; - - /** - * 是否为 Component 节点 - * check if node is Component - * @since v1.1.0 - */ - get isComponentNode(): boolean; - - /** - * 是否为「模态框」节点 - * check if node is Modal - * @since v1.1.0 - */ - get isModalNode(): boolean; - - /** - * 是否为插槽节点 - * check if node is a Slot - * @since v1.1.0 - */ - get isSlotNode(): boolean; - - /** - * 是否为父类/分支节点 - * check if node a parental node - * @since v1.1.0 - */ - get isParentalNode(): boolean; - - /** - * 是否为叶子节点 - * check if node is a leaf node in tree - * @since v1.1.0 - */ - get isLeafNode(): boolean; - - /** - * 获取当前节点的锁定状态 - * check if current node is locked - * @since v1.0.16 - */ - get isLocked(): boolean; - - /** - * 设置为磁贴布局节点 - * @since v1.1.0 - */ - set isRGLContainerNode(flag: boolean); - - /** - * 获取磁贴布局节点设置状态 - * @returns Boolean - * @since v1.1.0 - */ - get isRGLContainerNode(); - - /** - * 下标 - * index - */ - get index(): number | undefined; - - /** - * 图标 - * get icon of this node - */ - get icon(): IPublicTypeIconType; - - /** - * 节点所在树的层级深度,根节点深度为 0 - * depth level of this node, value of root node is 0 - */ - get zLevel(): number; - - /** - * 节点 componentName - * componentName - */ - get componentName(): string; - - /** - * 节点的物料元数据 - * get component meta of this node - */ - get componentMeta(): ComponentMeta | null; - - /** - * 获取节点所属的文档模型对象 - * get documentModel of this node - */ - get document(): Document | null; - - /** - * 获取当前节点的前一个兄弟节点 - * get previous sibling of this node - */ - get prevSibling(): Node | null | undefined; - - /** - * 获取当前节点的后一个兄弟节点 - * get next sibling of this node - */ - get nextSibling(): Node | null | undefined; - - /** - * 获取当前节点的父亲节点 - * get parent of this node - */ - get parent(): Node | null; - - /** - * 获取当前节点的孩子节点模型 - * get children of this node - */ - get children(): NodeChildren | null; - - /** - * 节点上挂载的插槽节点们 - * get slots of this node - */ - get slots(): Node[]; - - /** - * 当前节点为插槽节点时,返回节点对应的属性实例 - * return coresponding prop when this node is a slot node - */ - get slotFor(): Prop | null | undefined; - - /** - * 返回节点的属性集 - * get props - */ - get props(): Props | null; - - /** - * 返回节点的属性集 - * get props data - */ - get propsData(): IPublicTypePropsMap | IPublicTypePropsList | null; - - /** - * get conditionGroup - */ - get conditionGroup(): ExclusiveGroup | null; - - /** - * 获取符合搭建协议 - 节点 schema 结构 - * get schema of this node - * @since v1.1.0 - */ - get schema(): IPublicTypeNodeSchema; - - /** - * 获取对应的 setting entry - * get setting entry of this node - * @since v1.1.0 - */ - get settingEntry(): SettingTopEntry; - - /** - * 返回节点的尺寸、位置信息 - * get rect information for this node - */ - getRect(): DOMRect | null; - - /** - * 是否有挂载插槽节点 - * check if current node has slots - */ - hasSlots(): boolean; - - /** - * 是否设定了渲染条件 - * check if current node has condition value set - */ - hasCondition(): boolean; - - /** - * 是否设定了循环数据 - * check if loop is set for this node - */ - hasLoop(): boolean; - - /** - * 获取指定 path 的属性模型实例 - * get prop by path - * @param path 属性路径,支持 a / a.b / a.0 等格式 - * @param createIfNone 如果不存在,是否新建,默认为 true - */ - getProp(path: string | number, createIfNone?: boolean): Prop | null; - - /** - * 获取指定 path 的属性模型实例值 - * get prop value by path - * @param path 属性路径,支持 a / a.b / a.0 等格式 - */ - getPropValue(path: string): any; - - /** - * 获取指定 path 的属性模型实例, - * 注:导出时,不同于普通属性,该属性并不挂载在 props 之下,而是与 props 同级 - * - * get extra prop by path, an extra prop means a prop not exists in the `props` - * but as siblint of the `props` - * @param path 属性路径,支持 a / a.b / a.0 等格式 - * @param createIfNone 当没有属性的时候,是否创建一个属性 - */ - getExtraProp(path: string, createIfNone?: boolean): Prop | null; - - /** - * 获取指定 path 的属性模型实例, - * 注:导出时,不同于普通属性,该属性并不挂载在 props 之下,而是与 props 同级 - * - * get extra prop value by path, an extra prop means a prop not exists in the `props` - * but as siblint of the `props` - * @param path 属性路径,支持 a / a.b / a.0 等格式 - * @returns - */ - getExtraPropValue(path: string): any; - - /** - * 设置指定 path 的属性模型实例值 - * set value for prop with path - * @param path 属性路径,支持 a / a.b / a.0 等格式 - * @param value 值 - */ - setPropValue(path: string | number, value: IPublicTypeCompositeValue): void; - - /** - * 设置指定 path 的属性模型实例值 - * set value for extra prop with path - * @param path 属性路径,支持 a / a.b / a.0 等格式 - * @param value 值 - */ - setExtraPropValue(path: string, value: IPublicTypeCompositeValue): void; - - /** - * 导入节点数据 - * import node schema - * @param data - */ - importSchema(data: IPublicTypeNodeSchema): void; - - /** - * 导出节点数据 - * export schema from this node - * @param stage - * @param options - */ - exportSchema(stage: IPublicEnumTransformStage, options?: any): IPublicTypeNodeSchema; - - /** - * 在指定位置之前插入一个节点 - * insert a node befor current node - * @param node - * @param ref - * @param useMutator - */ - insertBefore( - node: Node, - ref?: Node | undefined, - useMutator?: boolean, - ): void; - - /** - * 在指定位置之后插入一个节点 - * insert a node after this node - * @param node - * @param ref - * @param useMutator - */ - insertAfter( - node: Node, - ref?: Node | undefined, - useMutator?: boolean, - ): void; - - /** - * 替换指定节点 - * replace a child node with data provided - * @param node 待替换的子节点 - * @param data 用作替换的节点对象或者节点描述 - * @returns - */ - replaceChild(node: Node, data: any): Node | null; - - /** - * 将当前节点替换成指定节点描述 - * replace current node with a new node schema - * @param schema - */ - replaceWith(schema: IPublicTypeNodeSchema): any; - - /** - * 选中当前节点实例 - * select current node - */ - select(): void; - - /** - * 设置悬停态 - * set hover value for current node - * @param flag - */ - hover(flag: boolean): void; - - /** - * 设置节点锁定状态 - * set lock value for current node - * @param flag - * @since v1.0.16 - */ - lock(flag?: boolean): void; - - /** - * 删除当前节点实例 - * remove current node - */ - remove(): void; - - /** - * 执行新增、删除、排序等操作 - * excute remove/add/sort operations on node`s children - * - * @since v1.1.0 - */ - mergeChildren( - remover: (node: Node, idx: number) => boolean, - adder: (children: Node[]) => any, - sorter: (firstNode: Node, secondNode: Node) => number - ): any; - - /** - * 当前节点是否包含某子节点 - * check if current node contains another node as a child - * @param node - * @since v1.1.0 - */ - contains(node: Node): boolean; - - /** - * 是否可执行某 action - * check if current node can perform certain aciton with actionName - * @param actionName action 名字 - * @since v1.1.0 - */ - canPerformAction(actionName: string): boolean; - - /** - * 当前节点是否可见 - * check if current node is visible - * @since v1.1.0 - */ - get visible(): boolean; - - /** - * 设置当前节点是否可见 - * set visible value for current node - * @since v1.1.0 - */ - set visible(value: boolean); - - /** - * 获取该节点的 ConditionalVisible 值 - * check if current node ConditionalVisible - * @since v1.1.0 - */ - isConditionalVisible(): boolean | undefined; - - /** - * 设置该节点的 ConditionalVisible 为 true - * make this node as conditionalVisible === true - * @since v1.1.0 - */ - setConditionalVisible(): void; - - /** - * 获取节点实例对应的 dom 节点 - */ - getDOMNode(): HTMLElement; - - /** - * 获取磁贴相关信息 - */ - getRGL(): { - isContainerNode: boolean; - isEmptyNode: boolean; - isRGLContainerNode: boolean; - isRGLNode: boolean; - isRGL: boolean; - rglNode: Node | null; - }; -} - -export interface IPublicModelNode extends - IBaseModelNode {} diff --git a/packages/types/src/shell/model/plugin-context.ts b/packages/types/src/shell/model/plugin-context.ts deleted file mode 100644 index dd3471a16..000000000 --- a/packages/types/src/shell/model/plugin-context.ts +++ /dev/null @@ -1,124 +0,0 @@ -import { - IPublicApiSkeleton, - IPublicApiHotkey, - IPublicApiSetters, - IPublicApiMaterial, - IPublicApiEvent, - IPublicApiProject, - IPublicApiCommon, - IPublicApiLogger, - IPublicApiCanvas, - IPluginPreferenceMananger, - IPublicApiPlugins, - IPublicApiWorkspace, - IPublicApiCommonUI, - IPublicApiCommand, -} from '../api'; -import { IPublicEnumPluginRegisterLevel } from '../enum'; -import { IPublicModelEngineConfig, IPublicModelWindow } from './'; - -export interface IPublicModelPluginContext { - - /** - * 可通过该对象读取插件初始化配置 - * by using this, init options can be accessed from inside plugin - */ - preference: IPluginPreferenceMananger; - - /** - * skeleton API - * @tutorial https://lowcode-engine.cn/site/docs/api/skeleton - */ - get skeleton(): IPublicApiSkeleton; - - /** - * hotkey API - * @tutorial https://lowcode-engine.cn/site/docs/api/hotkey - */ - get hotkey(): IPublicApiHotkey; - - /** - * setter API - * @tutorial https://lowcode-engine.cn/site/docs/api/setters - */ - get setters(): IPublicApiSetters; - - /** - * config API - * @tutorial https://lowcode-engine.cn/site/docs/api/config - */ - get config(): IPublicModelEngineConfig; - - /** - * material API - * @tutorial https://lowcode-engine.cn/site/docs/api/material - */ - get material(): IPublicApiMaterial; - - /** - * event API - * this event works globally, can be used between plugins and engine. - * @tutorial https://lowcode-engine.cn/site/docs/api/event - */ - get event(): IPublicApiEvent; - - /** - * project API - * @tutorial https://lowcode-engine.cn/site/docs/api/project - */ - get project(): IPublicApiProject; - - /** - * common API - * @tutorial https://lowcode-engine.cn/site/docs/api/common - */ - get common(): IPublicApiCommon; - - /** - * plugins API - * @tutorial https://lowcode-engine.cn/site/docs/api/plugins - */ - get plugins(): IPublicApiPlugins; - - /** - * logger API - * @tutorial https://lowcode-engine.cn/site/docs/api/logger - */ - get logger(): IPublicApiLogger; - - /** - * this event works within current plugin, on an emit locally. - * @tutorial https://lowcode-engine.cn/site/docs/api/event - */ - get pluginEvent(): IPublicApiEvent; - - /** - * canvas API - * @tutorial https://lowcode-engine.cn/site/docs/api/canvas - */ - get canvas(): IPublicApiCanvas; - - /** - * workspace API - * @tutorial https://lowcode-engine.cn/site/docs/api/workspace - */ - get workspace(): IPublicApiWorkspace; - - /** - * commonUI API - * @tutorial https://lowcode-engine.cn/site/docs/api/commonUI - */ - get commonUI(): IPublicApiCommonUI; - - get command(): IPublicApiCommand; - - /** - * 插件注册层级 - * @since v1.1.7 - */ - get registerLevel(): IPublicEnumPluginRegisterLevel; - - get isPluginRegisteredInWorkspace(): boolean; - - get editorWindow(): IPublicModelWindow; -} diff --git a/packages/types/src/shell/model/plugin-instance.ts b/packages/types/src/shell/model/plugin-instance.ts deleted file mode 100644 index 88904205d..000000000 --- a/packages/types/src/shell/model/plugin-instance.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { IPublicTypePluginMeta } from '../type/plugin-meta'; - -export interface IPublicModelPluginInstance { - - /** - * 是否 disable - * current plugin instance is disabled or not - */ - disabled: boolean; - - /** - * 插件名称 - * plugin name - */ - get pluginName(): string; - - /** - * 依赖信息,依赖的其他插件 - * depenency info - */ - get dep(): string[]; - - /** - * 插件配置元数据 - * meta info of this plugin - */ - get meta(): IPublicTypePluginMeta; -} diff --git a/packages/types/src/shell/model/preference.ts b/packages/types/src/shell/model/preference.ts deleted file mode 100644 index e200dae9d..000000000 --- a/packages/types/src/shell/model/preference.ts +++ /dev/null @@ -1,18 +0,0 @@ - -export interface IPublicModelPreference { - - /** - * set value from local storage by module and key - */ - set(key: string, value: any, module?: string): void; - - /** - * get value from local storage by module and key - */ - get(key: string, module: string): any; - - /** - * check if local storage contain certain key - */ - contains(key: string, module: string): boolean; -} diff --git a/packages/types/src/shell/model/prop.ts b/packages/types/src/shell/model/prop.ts deleted file mode 100644 index 81b6c016d..000000000 --- a/packages/types/src/shell/model/prop.ts +++ /dev/null @@ -1,72 +0,0 @@ -import { IPublicEnumTransformStage } from '../enum'; -import { IPublicTypeCompositeValue, IPublicTypeNodeData } from '../type'; -import { IPublicModelNode } from './'; - -export interface IPublicModelProp< - Node = IPublicModelNode -> { - - /** - * id - */ - get id(): string; - - /** - * key 值 - * get key of prop - */ - get key(): string | number | undefined; - - /** - * 返回当前 prop 的路径 - * get path of current prop - */ - get path(): string[]; - - /** - * 返回所属的节点实例 - * get node instance, which this prop belongs to - */ - get node(): Node | null; - - /** - * 当本 prop 代表一个 Slot 时,返回对应的 slotNode - * return the slot node (only if the current prop represents a slot) - * @since v1.1.0 - */ - get slotNode(): Node | undefined | null; - - /** - * 是否是 Prop , 固定返回 true - * check if it is a prop or not, and of course always return true - * @experimental - */ - get isProp(): boolean; - - /** - * 设置值 - * set value for this prop - * @param val - */ - setValue(val: IPublicTypeCompositeValue | IPublicTypeNodeData | IPublicTypeNodeData[]): void; - - /** - * 获取值 - * get value of this prop - */ - getValue(): any; - - /** - * 移除值 - * remove value of this prop - * @since v1.0.16 - */ - remove(): void; - - /** - * 导出值 - * export schema - * @param stage - */ - exportSchema(stage: IPublicEnumTransformStage): IPublicTypeCompositeValue; -} diff --git a/packages/types/src/shell/model/props.ts b/packages/types/src/shell/model/props.ts deleted file mode 100644 index 07b57a78c..000000000 --- a/packages/types/src/shell/model/props.ts +++ /dev/null @@ -1,89 +0,0 @@ -import { IPublicTypeCompositeValue } from '../type'; -import { IPublicModelNode, IPublicModelProp } from './'; - -export interface IBaseModelProps< - Prop -> { - - /** - * id - */ - get id(): string; - - /** - * 返回当前 props 的路径 - * return path of current props - */ - get path(): string[]; - - /** - * 返回所属的 node 实例 - */ - get node(): IPublicModelNode | null; - - /** - * 获取指定 path 的属性模型实例 - * get prop by path - * @param path 属性路径,支持 a / a.b / a.0 等格式 - */ - getProp(path: string): Prop | null; - - /** - * 获取指定 path 的属性模型实例值 - * get value of prop by path - * @param path 属性路径,支持 a / a.b / a.0 等格式 - */ - getPropValue(path: string): any; - - /** - * 获取指定 path 的属性模型实例, - * 注:导出时,不同于普通属性,该属性并不挂载在 props 之下,而是与 props 同级 - * get extra prop by path - * @param path 属性路径,支持 a / a.b / a.0 等格式 - */ - getExtraProp(path: string): Prop | null; - - /** - * 获取指定 path 的属性模型实例值 - * 注:导出时,不同于普通属性,该属性并不挂载在 props 之下,而是与 props 同级 - * get value of extra prop by path - * @param path 属性路径,支持 a / a.b / a.0 等格式 - */ - getExtraPropValue(path: string): any; - - /** - * 设置指定 path 的属性模型实例值 - * set value of prop by path - * @param path 属性路径,支持 a / a.b / a.0 等格式 - * @param value 值 - */ - setPropValue(path: string, value: IPublicTypeCompositeValue): void; - - /** - * 设置指定 path 的属性模型实例值 - * set value of extra prop by path - * @param path 属性路径,支持 a / a.b / a.0 等格式 - * @param value 值 - */ - setExtraPropValue(path: string, value: IPublicTypeCompositeValue): void; - - /** - * 当前 props 是否包含某 prop - * check if the specified key is existing or not. - * @param key - * @since v1.1.0 - */ - has(key: string): boolean; - - /** - * 添加一个 prop - * add a key with given value - * @param value - * @param key - * @since v1.1.0 - */ - add(value: IPublicTypeCompositeValue, key?: string | number | undefined): any; - -} - -export interface IPublicModelProps extends IBaseModelProps {} diff --git a/packages/types/src/shell/model/resource.ts b/packages/types/src/shell/model/resource.ts deleted file mode 100644 index 9de2d6755..000000000 --- a/packages/types/src/shell/model/resource.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { ComponentType, ReactElement } from 'react'; - -export interface IBaseModelResource< - Resource -> { - get title(): string | undefined; - - get id(): string | undefined; - - get icon(): ReactElement | undefined | ComponentType; - - get options(): Record; - - get name(): string | undefined; - - get type(): string | undefined; - - get category(): string | undefined; - - get children(): Resource[]; - - get viewName(): string | undefined; - - get description(): string | undefined; - - get config(): { - [key: string]: any; - } | undefined; -} - -export type IPublicModelResource = IBaseModelResource; diff --git a/packages/types/src/shell/model/scroll-target.ts b/packages/types/src/shell/model/scroll-target.ts deleted file mode 100644 index 1dbbaeeda..000000000 --- a/packages/types/src/shell/model/scroll-target.ts +++ /dev/null @@ -1,9 +0,0 @@ - -export interface IPublicModelScrollTarget { - get left(): number; - get top(): number; - scrollTo(options: { left?: number; top?: number }): void; - scrollToXY(x: number, y: number): void; - get scrollHeight(): number; - get scrollWidth(): number; -} diff --git a/packages/types/src/shell/model/scroller.ts b/packages/types/src/shell/model/scroller.ts deleted file mode 100644 index 22a57b6fd..000000000 --- a/packages/types/src/shell/model/scroller.ts +++ /dev/null @@ -1,8 +0,0 @@ -export interface IPublicModelScroller { - - scrollTo(options: { left?: number; top?: number }): void; - - cancel(): void; - - scrolling(point: { globalX: number; globalY: number }): void; -} diff --git a/packages/types/src/shell/model/selection.ts b/packages/types/src/shell/model/selection.ts deleted file mode 100644 index 317a49837..000000000 --- a/packages/types/src/shell/model/selection.ts +++ /dev/null @@ -1,85 +0,0 @@ -import { IPublicModelNode } from './'; -import { IPublicTypeDisposable } from '../type'; - -export interface IPublicModelSelection< - Node = IPublicModelNode -> { - - /** - * 返回选中的节点 id - * get ids of selected nodes - */ - get selected(): string[]; - - /** - * 返回选中的节点(如多个节点只返回第一个) - * return selected Node instance,return the first one if multiple nodes are selected - * @since v1.1.0 - */ - get node(): Node | null; - - /** - * 选中指定节点(覆盖方式) - * select node with id, this will override current selection - * @param id - */ - select(id: string): void; - - /** - * 批量选中指定节点们 - * select node with ids, this will override current selection - * - * @param ids - */ - selectAll(ids: string[]): void; - - /** - * 移除选中的指定节点 - * remove node from selection with node id - * @param id - */ - remove(id: string): void; - - /** - * 清除所有选中节点 - * clear current selection - */ - clear(): void; - - /** - * 判断是否选中了指定节点 - * check if node with specific id is selected - * @param id - */ - has(id: string): boolean; - - /** - * 选中指定节点(增量方式) - * add node with specific id to selection - * @param id - */ - add(id: string): void; - - /** - * 获取选中的节点实例 - * get selected nodes - */ - getNodes(): Node[]; - - /** - * 获取选区的顶层节点 - * get seleted top nodes - * for example: - * getNodes() returns [A, subA, B], then - * getTopNodes() will return [A, B], subA will be removed - * @since v1.0.16 - */ - getTopNodes(includeRoot?: boolean): Node[]; - - /** - * 注册 selection 变化事件回调 - * set callback which will be called when selection is changed - * @since v1.1.0 - */ - onSelectionChange(fn: (ids: string[]) => void): IPublicTypeDisposable; -} diff --git a/packages/types/src/shell/model/sensor.ts b/packages/types/src/shell/model/sensor.ts deleted file mode 100644 index b563cddb1..000000000 --- a/packages/types/src/shell/model/sensor.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { IPublicTypeNodeInstance } from '../type/node-instance'; -import { - IPublicModelLocateEvent, - IPublicModelDropLocation, - IPublicTypeComponentInstance, - IPublicModelNode, -} from '..'; - -/** - * 拖拽敏感板 - */ -export interface IPublicModelSensor< - Node = IPublicModelNode -> { - - /** - * 是否可响应,比如面板被隐藏,可设置该值 false - */ - readonly sensorAvailable: boolean; - - /** - * 给事件打补丁 - */ - fixEvent(e: IPublicModelLocateEvent): IPublicModelLocateEvent; - - /** - * 定位并激活 - */ - locate(e: IPublicModelLocateEvent): IPublicModelDropLocation | undefined | null; - - /** - * 是否进入敏感板区域 - */ - isEnter(e: IPublicModelLocateEvent): boolean; - - /** - * 取消激活 - */ - deactiveSensor(): void; - - /** - * 获取节点实例 - */ - getNodeInstanceFromElement?: (e: Element | null) => IPublicTypeNodeInstance | null; -} diff --git a/packages/types/src/shell/model/setting-field.ts b/packages/types/src/shell/model/setting-field.ts deleted file mode 100644 index 06d8375f6..000000000 --- a/packages/types/src/shell/model/setting-field.ts +++ /dev/null @@ -1,198 +0,0 @@ -import { IPublicTypeCustomView, IPublicTypeCompositeValue, IPublicTypeSetterType, IPublicTypeSetValueOptions, IPublicTypeFieldConfig, IPublicTypeFieldExtraProps, IPublicTypeDisposable } from '../type'; -import { IPublicModelNode, IPublicModelComponentMeta, IPublicModelSettingTopEntry } from './'; - -export interface IBaseModelSettingField< - SettingTopEntry, - SettingField, - ComponentMeta, - Node -> { - - /** - * 获取设置属性的父设置属性 - */ - readonly parent: SettingTopEntry | SettingField; - - /** - * 获取设置属性的 isGroup - */ - get isGroup(): boolean; - - /** - * 获取设置属性的 id - */ - get id(): string; - - /** - * 获取设置属性的 name - */ - get name(): string | number | undefined; - - /** - * 获取设置属性的 key - */ - get key(): string | number | undefined; - - /** - * 获取设置属性的 path - */ - get path(): (string | number)[]; - - /** - * 获取设置属性的 title - */ - get title(): string; - - /** - * 获取设置属性的 setter - */ - get setter(): IPublicTypeSetterType | null; - - /** - * 获取设置属性的 expanded - */ - get expanded(): boolean; - - /** - * 获取设置属性的 extraProps - */ - get extraProps(): IPublicTypeFieldExtraProps; - - get props(): SettingTopEntry; - - /** - * 获取设置属性对应的节点实例 - */ - get node(): Node | null; - - /** - * 获取顶级设置属性 - */ - get top(): SettingTopEntry; - - /** - * 是否是 SettingField 实例 - */ - get isSettingField(): boolean; - - /** - * componentMeta - */ - get componentMeta(): ComponentMeta | null; - - /** - * 获取设置属性的 items - */ - get items(): Array; - - /** - * 设置 key 值 - * @param key - */ - setKey(key: string | number): void; - - /** - * 设置值 - * @param val 值 - */ - setValue(val: IPublicTypeCompositeValue, extraOptions?: IPublicTypeSetValueOptions): void; - - /** - * 设置子级属性值 - * @param propName 子属性名 - * @param value 值 - */ - setPropValue(propName: string | number, value: any): void; - - /** - * 清空指定属性值 - * @param propName - */ - clearPropValue(propName: string | number): void; - - /** - * 获取配置的默认值 - * @returns - */ - getDefaultValue(): any; - - /** - * 获取值 - * @returns - */ - getValue(): any; - - /** - * 获取子级属性值 - * @param propName 子属性名 - * @returns - */ - getPropValue(propName: string | number): any; - - /** - * 获取顶层附属属性值 - */ - getExtraPropValue(propName: string): any; - - /** - * 设置顶层附属属性值 - */ - setExtraPropValue(propName: string, value: any): void; - - /** - * 获取设置属性集 - * @returns - */ - getProps(): SettingTopEntry; - - /** - * 是否绑定了变量 - * @returns - */ - isUseVariable(): boolean; - - /** - * 设置绑定变量 - * @param flag - */ - setUseVariable(flag: boolean): void; - - /** - * 创建一个设置 field 实例 - * @param config - * @returns - */ - createField(config: IPublicTypeFieldConfig): SettingField; - - /** - * 获取值,当为变量时,返回 mock - * @returns - */ - getMockOrValue(): any; - - /** - * 销毁当前 field 实例 - */ - purge(): void; - - /** - * 移除当前 field 实例 - */ - remove(): void; - - /** - * 设置 autorun - * @param action - * @returns - */ - onEffect(action: () => void): IPublicTypeDisposable; -} - -export interface IPublicModelSettingField extends IBaseModelSettingField< - IPublicModelSettingTopEntry, - IPublicModelSettingField, - IPublicModelComponentMeta, - IPublicModelNode -> { - -} diff --git a/packages/types/src/shell/model/setting-top-entry.ts b/packages/types/src/shell/model/setting-top-entry.ts deleted file mode 100644 index 1c3d6c2f1..000000000 --- a/packages/types/src/shell/model/setting-top-entry.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { IPublicModelNode, IPublicModelSettingField } from './'; - -export interface IPublicModelSettingTopEntry< - Node = IPublicModelNode, - SettingField = IPublicModelSettingField -> { - - /** - * 返回所属的节点实例 - */ - get node(): Node | null; - - /** - * 获取子级属性对象 - * @param propName - * @returns - */ - get(propName: string | number): SettingField | null; - - /** - * 获取指定 propName 的值 - * @param propName - * @returns - */ - getPropValue(propName: string | number): any; - - /** - * 设置指定 propName 的值 - * @param propName - * @param value - */ - setPropValue(propName: string | number, value: any): void; - - /** - * 清除指定 propName 的值 - * @param propName - */ - clearPropValue(propName: string | number): void; -} diff --git a/packages/types/src/shell/model/simulator-render.ts b/packages/types/src/shell/model/simulator-render.ts deleted file mode 100644 index 8cf3a03c5..000000000 --- a/packages/types/src/shell/model/simulator-render.ts +++ /dev/null @@ -1,14 +0,0 @@ -export interface IPublicModelSimulatorRender { - - /** - * 画布组件列表 - */ - components: { - [key: string]: any; - }; - - /** - * 触发画布重新渲染 - */ - rerender: () => void; -} diff --git a/packages/types/src/shell/model/skeleton-item.ts b/packages/types/src/shell/model/skeleton-item.ts deleted file mode 100644 index 55d1c2a24..000000000 --- a/packages/types/src/shell/model/skeleton-item.ts +++ /dev/null @@ -1,21 +0,0 @@ -/** - * @since 1.1.7 - */ -export interface IPublicModelSkeletonItem { - name: string; - - visible: boolean; - - disable(): void; - - enable(): void; - - hide(): void; - - show(): void; - - /** - * @since v1.1.10 - */ - toggle(): void; -} diff --git a/packages/types/src/shell/model/window.ts b/packages/types/src/shell/model/window.ts deleted file mode 100644 index ea9ec90c5..000000000 --- a/packages/types/src/shell/model/window.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { ReactElement } from 'react'; -import { IPublicTypeDisposable, IPublicTypeNodeSchema } from '../type'; -import { IPublicModelResource } from './resource'; -import { IPublicModelEditorView } from './editor-view'; - -export interface IPublicModelWindow< - Resource = IPublicModelResource -> { - - /** 窗口 id */ - id: string; - - /** 窗口标题 */ - title?: string; - - /** 窗口 icon */ - icon?: ReactElement; - - /** 窗口资源类型 */ - resource?: Resource; - - /** - * 窗口当前视图 - * @since v1.1.7 - */ - currentEditorView: IPublicModelEditorView | null; - - /** - * 窗口全部视图实例 - * @since v1.1.7 - */ - editorViews: IPublicModelEditorView[]; - - /** 当前窗口导入 schema */ - importSchema(schema: IPublicTypeNodeSchema): void; - - /** 修改当前窗口视图类型 */ - changeViewType(viewName: string): void; - - /** 调用当前窗口视图保存钩子 */ - save(): Promise; - - /** 窗口视图变更事件 */ - onChangeViewType(fn: (viewName: string) => void): IPublicTypeDisposable; - - /** - * 窗口视图保存事件 - * @since 1.1.7 - */ - onSave(fn: () => void): IPublicTypeDisposable; -} diff --git a/packages/types/src/shell/type/action-content-object.ts b/packages/types/src/shell/type/action-content-object.ts deleted file mode 100644 index cf3e0c048..000000000 --- a/packages/types/src/shell/type/action-content-object.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { IPublicModelNode } from '../model'; -import { IPublicTypeIconType, TipContent } from './'; - -/** - * 动作描述 - */ -export interface IPublicTypeActionContentObject { - - /** - * 图标 - */ - icon?: IPublicTypeIconType; - - /** - * 描述 - */ - title?: TipContent; - - /** - * 执行动作 - */ - action?: (currentNode: IPublicModelNode) => void; -} diff --git a/packages/types/src/shell/type/active-target.ts b/packages/types/src/shell/type/active-target.ts deleted file mode 100644 index 97845160b..000000000 --- a/packages/types/src/shell/type/active-target.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { IPublicModelNode } from '../model'; -import { IPublicTypeLocationDetail, IPublicTypeComponentInstance } from './'; - -export interface IPublicTypeActiveTarget { - node: IPublicModelNode; - detail?: IPublicTypeLocationDetail; - instance?: IPublicTypeComponentInstance; -} diff --git a/packages/types/src/shell/type/advanced.ts b/packages/types/src/shell/type/advanced.ts deleted file mode 100644 index 6c57bcbb3..000000000 --- a/packages/types/src/shell/type/advanced.ts +++ /dev/null @@ -1,69 +0,0 @@ -import { ComponentType, ReactElement } from 'react'; -import { - IPublicTypeNodeData, - IPublicTypeCallbacks, - IPublicTypeLiveTextEditingConfig, -} from './'; -import { IPublicModelNode } from '../model'; - -/** - * 高级特性配置 - */ -export interface IPublicTypeAdvanced { - /** - * 配置 callbacks 可捕获引擎抛出的一些事件,例如 onNodeAdd、onResize 等 - * callbacks/hooks which can be used to do - * things on some special ocations like onNodeAdd or onResize - */ - callbacks?: IPublicTypeCallbacks; - - /** - * 拖入容器时,自动带入 children 列表 - */ - initialChildren?: - | IPublicTypeNodeData[] - | ((target: IPublicModelNode) => IPublicTypeNodeData[]); - - /** - * 样式 及 位置,handle 上必须有明确的标识以便事件路由判断,或者主动设置事件独占模式 - * NWSE 是交给引擎计算放置位置,ReactElement 必须自己控制初始位置 - * - * 用于配置设计器中组件 resize 操作工具的样式和内容 - * - hover 时控制柄高亮 - * - mousedown 时请求独占 - * - dragstart 请求通用 resizing 控制 请求 hud 显示 - * - drag 时 计算并设置效果,更新控制柄位置 - */ - getResizingHandlers?: (currentNode: any) => - | Array<{ - type: 'N' | 'W' | 'S' | 'E' | 'NW' | 'NE' | 'SE' | 'SW'; - content?: ReactElement; - propTarget?: string; - appearOn?: 'mouse-enter' | 'mouse-hover' | 'selected' | 'always'; - }> - | ReactElement[]; - - /** - * 是否绝对布局容器,还未进入协议 - * @experimental not in spec yet - */ - isAbsoluteLayoutContainer?: boolean; - - /** - * hide bem tools when selected - * @experimental not in spec yet - */ - hideSelectTools?: boolean; - - /** - * Live Text Editing:如果 children 内容是纯文本,支持双击直接编辑 - * @experimental not in spec yet - */ - liveTextEditing?: IPublicTypeLiveTextEditingConfig[]; - - /** - * TODO: 补充文档 - * @experimental not in spec yet - */ - view?: ComponentType; -} diff --git a/packages/types/src/shell/type/app-config.ts b/packages/types/src/shell/type/app-config.ts deleted file mode 100644 index 2bcb5f47a..000000000 --- a/packages/types/src/shell/type/app-config.ts +++ /dev/null @@ -1,18 +0,0 @@ -export interface IPublicTypeAppConfig { - sdkVersion?: string; - historyMode?: string; - targetRootID?: string; - layout?: IPublicTypeLayout; - theme?: IPublicTypeTheme; -} - -interface IPublicTypeTheme { - package: string; - version: string; - primary: string; -} - -interface IPublicTypeLayout { - componentName?: string; - props?: Record; -} diff --git a/packages/types/src/shell/type/assets-json.ts b/packages/types/src/shell/type/assets-json.ts deleted file mode 100644 index 22482a7b3..000000000 --- a/packages/types/src/shell/type/assets-json.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { IPublicTypeComponentSort, IPublicTypePackage, IPublicTypeRemoteComponentDescription, IPublicTypeComponentDescription } from './'; - -/** - * 资产包协议 - */ - -export interface IPublicTypeAssetsJson { - /** - * 资产包协议版本号 - */ - version: string; - /** - * 大包列表,external 与 package 的概念相似,融合在一起 - */ - packages?: IPublicTypePackage[]; - /** - * 所有组件的描述协议列表所有组件的列表 - */ - components: Array; - /** - * 用于描述组件面板中的 tab 和 category - */ - sort?: IPublicTypeComponentSort; -} diff --git a/packages/types/src/shell/type/block-schema.ts b/packages/types/src/shell/type/block-schema.ts deleted file mode 100644 index 118a4f8c7..000000000 --- a/packages/types/src/shell/type/block-schema.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { IPublicTypeContainerSchema } from './'; - -/** - * 区块容器 - * @see https://lowcode-engine.cn/lowcode - */ - -export interface IPublicTypeBlockSchema extends IPublicTypeContainerSchema { - componentName: 'Block'; -} diff --git a/packages/types/src/shell/type/command.ts b/packages/types/src/shell/type/command.ts deleted file mode 100644 index 1bda10116..000000000 --- a/packages/types/src/shell/type/command.ts +++ /dev/null @@ -1,59 +0,0 @@ -import { IPublicTypePropType } from './prop-types'; - -// 定义命令处理函数的参数类型 -export interface IPublicTypeCommandHandlerArgs { - [key: string]: any; -} - -// 定义命令参数的接口 -export interface IPublicTypeCommandParameter { - - /** - * 参数名称 - */ - name: string; - - /** - * 参数类型或详细类型描述 - */ - propType: string | IPublicTypePropType; - - /** - * 参数描述 - */ - description: string; - - /** - * 参数默认值(可选) - */ - defaultValue?: any; -} - -// 定义单个命令的接口 -export interface IPublicTypeCommand { - - /** - * 命令名称 - * 命名规则:commandName - * 使用规则:commandScope:commandName (commandScope 在插件 meta 中定义,用于区分不同插件的命令) - */ - name: string; - - /** - * 命令参数 - */ - parameters?: IPublicTypeCommandParameter[]; - - /** - * 命令描述 - */ - description?: string; - - /** - * 命令处理函数 - */ - handler: (args: any) => void; -} - -export interface IPublicTypeListCommand extends Pick { -} diff --git a/packages/types/src/shell/type/component-action.ts b/packages/types/src/shell/type/component-action.ts deleted file mode 100644 index f86324e7a..000000000 --- a/packages/types/src/shell/type/component-action.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { ReactNode } from 'react'; -import { IPublicTypeActionContentObject } from './'; - -/** - * @todo 工具条动作 - */ - -export interface IPublicTypeComponentAction { - - /** - * behaviorName - */ - name: string; - - /** - * 菜单名称 - */ - content: string | ReactNode | IPublicTypeActionContentObject; - - /** - * 子集 - */ - items?: IPublicTypeComponentAction[]; - - /** - * 显示与否 - * always: 无法禁用 - */ - condition?: boolean | ((currentNode: any) => boolean) | 'always'; - - /** - * 显示在工具条上 - */ - important?: boolean; -} diff --git a/packages/types/src/shell/type/component-description.ts b/packages/types/src/shell/type/component-description.ts deleted file mode 100644 index 7ee7f5f00..000000000 --- a/packages/types/src/shell/type/component-description.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { IPublicTypeComponentMetadata, IPublicTypeReference } from './'; - -/** - * 本地物料描述 - */ - -export interface IPublicTypeComponentDescription extends IPublicTypeComponentMetadata { - /** - * @todo 待补充文档 @jinchan - */ - keywords: string[]; - /** - * 替代 npm 字段的升级版本 - */ - reference?: IPublicTypeReference; -} diff --git a/packages/types/src/shell/type/component-instance.ts b/packages/types/src/shell/type/component-instance.ts deleted file mode 100644 index bf7a8c040..000000000 --- a/packages/types/src/shell/type/component-instance.ts +++ /dev/null @@ -1,6 +0,0 @@ - -import { Component as ReactComponent } from 'react'; -/** - * 组件实例定义 - */ -export type IPublicTypeComponentInstance = Element | ReactComponent | object; diff --git a/packages/types/src/shell/type/component-metadata.ts b/packages/types/src/shell/type/component-metadata.ts deleted file mode 100644 index 7a706f2de..000000000 --- a/packages/types/src/shell/type/component-metadata.ts +++ /dev/null @@ -1,96 +0,0 @@ -import { IPublicTypeIconType, IPublicTypeNpmInfo, IPublicTypeFieldConfig, IPublicTypeI18nData, IPublicTypeComponentSchema, IPublicTypeTitleContent, IPublicTypePropConfig, IPublicTypeConfigure, IPublicTypeSnippet } from './'; - -/** - * 组件 meta 配置 - */ - -export interface IPublicTypeComponentMetadata { - - /** 其他扩展协议 */ - [key: string]: any; - - /** - * 组件名 - */ - componentName: string; - - /** - * unique id - */ - uri?: string; - - /** - * title or description - */ - title?: IPublicTypeTitleContent; - - /** - * svg icon for component - */ - icon?: IPublicTypeIconType; - - /** - * 组件标签 - */ - tags?: string[]; - - /** - * 组件描述 - */ - description?: string; - - /** - * 组件文档链接 - */ - docUrl?: string; - - /** - * 组件快照 - */ - screenshot?: string; - - /** - * 组件研发模式 - */ - devMode?: 'proCode' | 'lowCode'; - - /** - * npm 源引入完整描述对象 - */ - npm?: IPublicTypeNpmInfo; - - /** - * 组件属性信息 - */ - props?: IPublicTypePropConfig[]; - - /** - * 编辑体验增强 - */ - configure?: IPublicTypeFieldConfig[] | IPublicTypeConfigure; - - /** - * @todo 待补充文档 - */ - schema?: IPublicTypeComponentSchema; - - /** - * 可用片段 - */ - snippets?: IPublicTypeSnippet[]; - - /** - * 一级分组 - */ - group?: string | IPublicTypeI18nData; - - /** - * 二级分组 - */ - category?: string | IPublicTypeI18nData; - - /** - * 组件优先级排序 - */ - priority?: number; -} diff --git a/packages/types/src/shell/type/component-schema.ts b/packages/types/src/shell/type/component-schema.ts deleted file mode 100644 index 41daae5c3..000000000 --- a/packages/types/src/shell/type/component-schema.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { IPublicTypeContainerSchema } from './'; - -/** - * 低代码业务组件容器 - * @see https://lowcode-engine.cn/lowcode - */ - -export interface IPublicTypeComponentSchema extends IPublicTypeContainerSchema { - componentName: 'Component'; -} diff --git a/packages/types/src/shell/type/component-sort.ts b/packages/types/src/shell/type/component-sort.ts deleted file mode 100644 index add821ea9..000000000 --- a/packages/types/src/shell/type/component-sort.ts +++ /dev/null @@ -1,14 +0,0 @@ -/** - * 用于描述组件面板中的 tab 和 category - */ - -export interface IPublicTypeComponentSort { - /** - * 用于描述组件面板的 tab 项及其排序,例如:["精选组件", "原子组件"] - */ - groupList?: string[]; - /** - * 组件面板中同一个 tab 下的不同区间用 category 区分,category 的排序依照 categoryList 顺序排列; - */ - categoryList?: string[]; -} diff --git a/packages/types/src/shell/type/composite-value.ts b/packages/types/src/shell/type/composite-value.ts deleted file mode 100644 index e7aea645e..000000000 --- a/packages/types/src/shell/type/composite-value.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { IPublicTypeJSONValue, IPublicTypeJSExpression, IPublicTypeJSFunction, IPublicTypeJSSlot, IPublicTypeCompositeArray, IPublicTypeCompositeObject } from './'; - -/** - * 复合类型 - */ -export type IPublicTypeCompositeValue = IPublicTypeJSONValue | - IPublicTypeJSExpression | - IPublicTypeJSFunction | - IPublicTypeJSSlot | - IPublicTypeCompositeArray | - IPublicTypeCompositeObject; diff --git a/packages/types/src/shell/type/config-transducer.ts b/packages/types/src/shell/type/config-transducer.ts deleted file mode 100644 index 64c33a5c4..000000000 --- a/packages/types/src/shell/type/config-transducer.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { IPublicTypeSkeletonConfig } from '.'; - -export interface IPublicTypeConfigTransducer { - (prev: IPublicTypeSkeletonConfig): IPublicTypeSkeletonConfig; - - level?: number; - - id?: string; -} diff --git a/packages/types/src/shell/type/configure.ts b/packages/types/src/shell/type/configure.ts deleted file mode 100644 index 44fd1ffe6..000000000 --- a/packages/types/src/shell/type/configure.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { IPublicTypeComponentConfigure, ConfigureSupport, IPublicTypeFieldConfig, IPublicTypeAdvanced } from './'; - -/** - * 编辑体验配置 - */ -export interface IPublicTypeConfigure { - - /** - * 属性面板配置 - */ - props?: IPublicTypeFieldConfig[]; - - /** - * 组件能力配置 - */ - component?: IPublicTypeComponentConfigure; - - /** - * 通用扩展面板支持性配置 - */ - supports?: ConfigureSupport; - - /** - * 高级特性配置 - */ - advanced?: IPublicTypeAdvanced; -} diff --git a/packages/types/src/shell/type/container-schema.ts b/packages/types/src/shell/type/container-schema.ts deleted file mode 100644 index 416788f86..000000000 --- a/packages/types/src/shell/type/container-schema.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { InterpretDataSource as DataSource } from '@alilc/lowcode-datasource-types'; -import { - IPublicTypeJSExpression, - IPublicTypeJSFunction, - IPublicTypeCompositeObject, - IPublicTypeCompositeValue, - IPublicTypeNodeSchema, -} from './'; - -/** - * 容器结构描述 - */ -export interface IPublicTypeContainerSchema extends IPublicTypeNodeSchema { - /** - * 'Block' | 'Page' | 'Component'; - */ - componentName: string; - /** - * 文件名称 - */ - fileName: string; - /** - * @todo 待文档定义 - */ - meta?: Record; - /** - * 容器初始数据 - */ - state?: { - [key: string]: IPublicTypeCompositeValue; - }; - /** - * 自定义方法设置 - */ - methods?: { - [key: string]: IPublicTypeJSExpression | IPublicTypeJSFunction; - }; - /** - * 生命周期对象 - */ - lifeCycles?: { - // @todo 生命周期对象建议改为闭合集合 - [key: string]: IPublicTypeJSExpression | IPublicTypeJSFunction; - }; - /** - * 样式文件 - */ - css?: string; - /** - * 异步数据源配置 - */ - dataSource?: DataSource; - /** - * 低代码业务组件默认属性 - */ - defaultProps?: IPublicTypeCompositeObject; -} diff --git a/packages/types/src/shell/type/context-menu.ts b/packages/types/src/shell/type/context-menu.ts deleted file mode 100644 index 608e657aa..000000000 --- a/packages/types/src/shell/type/context-menu.ts +++ /dev/null @@ -1,69 +0,0 @@ -import { IPublicEnumContextMenuType } from '../enum'; -import { IPublicModelNode } from '../model'; -import { IPublicTypeI18nData } from './i18n-data'; -import { IPublicTypeHelpTipConfig } from './widget-base-config'; - -export interface IPublicTypeContextMenuItem - extends Omit< - IPublicTypeContextMenuAction, - 'condition' | 'disabled' | 'items' - > { - disabled?: boolean; - - items?: Omit[]; -} - -export interface IPublicTypeContextMenuAction { - /** - * 动作的唯一标识符 - * Unique identifier for the action - */ - name: string; - - /** - * 显示的标题,可以是字符串或国际化数据 - * Display title, can be a string or internationalized data - */ - title?: string | IPublicTypeI18nData; - - /** - * 菜单项类型 - * Menu item type - * @see IPublicEnumContextMenuType - * @default IPublicEnumContextMenuType.MENU_ITEM - */ - type?: IPublicEnumContextMenuType; - - /** - * 点击时执行的动作,可选 - * Action to execute on click, optional - */ - action?: (nodes?: IPublicModelNode[], event?: MouseEvent) => void; - - /** - * 子菜单项或生成子节点的函数,可选,仅支持两级 - * Sub-menu items or function to generate child node, optional - */ - items?: - | Omit[] - | (( - nodes?: IPublicModelNode[], - ) => Omit[]); - - /** - * 显示条件函数 - * Function to determine display condition - */ - condition?: (nodes?: IPublicModelNode[]) => boolean; - - /** - * 禁用条件函数,可选 - * Function to determine disabled condition, optional - */ - disabled?: (nodes?: IPublicModelNode[]) => boolean; - - /** - * 帮助提示,可选 - */ - help?: IPublicTypeHelpTipConfig; -} diff --git a/packages/types/src/shell/type/custom-view.ts b/packages/types/src/shell/type/custom-view.ts deleted file mode 100644 index 076fd83a3..000000000 --- a/packages/types/src/shell/type/custom-view.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { ComponentType, ReactElement } from 'react'; - -export type IPublicTypeCustomView = ReactElement | ComponentType; diff --git a/packages/types/src/shell/type/disposable.ts b/packages/types/src/shell/type/disposable.ts deleted file mode 100644 index 7aaaeb7a0..000000000 --- a/packages/types/src/shell/type/disposable.ts +++ /dev/null @@ -1,3 +0,0 @@ -export interface IPublicTypeDisposable { - (): void; -} diff --git a/packages/types/src/shell/type/dom-text.ts b/packages/types/src/shell/type/dom-text.ts deleted file mode 100644 index 3bb227f2d..000000000 --- a/packages/types/src/shell/type/dom-text.ts +++ /dev/null @@ -1 +0,0 @@ -export type IPublicTypeDOMText = string; diff --git a/packages/types/src/shell/type/drag-any-object.ts b/packages/types/src/shell/type/drag-any-object.ts deleted file mode 100644 index 93269945f..000000000 --- a/packages/types/src/shell/type/drag-any-object.ts +++ /dev/null @@ -1,5 +0,0 @@ - -export interface IPublicTypeDragAnyObject { - type: string; - [key: string]: any; -} diff --git a/packages/types/src/shell/type/drag-node-data-object.ts b/packages/types/src/shell/type/drag-node-data-object.ts deleted file mode 100644 index 8c6980c51..000000000 --- a/packages/types/src/shell/type/drag-node-data-object.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { IPublicTypeNodeSchema } from './'; -import { IPublicEnumDragObjectType } from '../enum'; - -export interface IPublicTypeDragNodeDataObject { - type: IPublicEnumDragObjectType.NodeData; - data: IPublicTypeNodeSchema | IPublicTypeNodeSchema[]; - thumbnail?: string; - description?: string; - [extra: string]: any; -} diff --git a/packages/types/src/shell/type/drag-node-object.ts b/packages/types/src/shell/type/drag-node-object.ts deleted file mode 100644 index 21f14b2bc..000000000 --- a/packages/types/src/shell/type/drag-node-object.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { IPublicModelNode } from '..'; -import { IPublicEnumDragObjectType } from '../enum'; - -export interface IPublicTypeDragNodeObject { - type: IPublicEnumDragObjectType.Node; - nodes: Node[]; -} diff --git a/packages/types/src/shell/type/drag-object.ts b/packages/types/src/shell/type/drag-object.ts deleted file mode 100644 index 1df6ce107..000000000 --- a/packages/types/src/shell/type/drag-object.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { IPublicTypeDragNodeDataObject, IPublicTypeDragNodeObject, IPublicTypeDragAnyObject } from './'; - -// eslint-disable-next-line max-len -export type IPublicTypeDragObject = IPublicTypeDragNodeObject | IPublicTypeDragNodeDataObject | IPublicTypeDragAnyObject; diff --git a/packages/types/src/shell/type/dynamic-props.ts b/packages/types/src/shell/type/dynamic-props.ts deleted file mode 100644 index 1d87a6567..000000000 --- a/packages/types/src/shell/type/dynamic-props.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { IPublicModelSettingField } from '../model'; - -export type IPublicTypeDynamicProps = (target: IPublicModelSettingField) => Record; diff --git a/packages/types/src/shell/type/dynamic-setter.ts b/packages/types/src/shell/type/dynamic-setter.ts deleted file mode 100644 index f2bbf59fb..000000000 --- a/packages/types/src/shell/type/dynamic-setter.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { IPublicModelSettingPropEntry, IPublicTypeCustomView } from '..'; -import { IPublicTypeSetterConfig } from './setter-config'; - -export type IPublicTypeDynamicSetter = ( - target: IPublicModelSettingPropEntry, -) => string | IPublicTypeSetterConfig | IPublicTypeCustomView; diff --git a/packages/types/src/shell/type/editor-get-options.ts b/packages/types/src/shell/type/editor-get-options.ts deleted file mode 100644 index ed5477057..000000000 --- a/packages/types/src/shell/type/editor-get-options.ts +++ /dev/null @@ -1,5 +0,0 @@ - -export interface IPublicTypeEditorGetOptions { - forceNew?: boolean; - sourceCls?: new (...args: any[]) => any; -} diff --git a/packages/types/src/shell/type/editor-get-result.ts b/packages/types/src/shell/type/editor-get-result.ts deleted file mode 100644 index af3639ac0..000000000 --- a/packages/types/src/shell/type/editor-get-result.ts +++ /dev/null @@ -1,4 +0,0 @@ - -export type IPublicTypeEditorGetResult = T extends undefined ? ClsType extends { - prototype: infer R; -} ? R : any : T; diff --git a/packages/types/src/shell/type/editor-register-options.ts b/packages/types/src/shell/type/editor-register-options.ts deleted file mode 100644 index 385346581..000000000 --- a/packages/types/src/shell/type/editor-register-options.ts +++ /dev/null @@ -1,19 +0,0 @@ -/** - * duck-typed power-di - * - * @see https://www.npmjs.com/package/power-di - */ -export interface IPublicTypeEditorRegisterOptions { - - /** - * default: true - */ - singleton?: boolean; - - /** - * if data a class, auto new a instance. - * if data a function, auto run(lazy). - * default: true - */ - autoNew?: boolean; -} diff --git a/packages/types/src/shell/type/editor-value-key.ts b/packages/types/src/shell/type/editor-value-key.ts deleted file mode 100644 index 8c0d3c6c9..000000000 --- a/packages/types/src/shell/type/editor-value-key.ts +++ /dev/null @@ -1,2 +0,0 @@ - -export type IPublicTypeEditorValueKey = (new (...args: any[]) => any) | symbol | string; diff --git a/packages/types/src/shell/type/editor-view-config.ts b/packages/types/src/shell/type/editor-view-config.ts deleted file mode 100644 index 701a600fb..000000000 --- a/packages/types/src/shell/type/editor-view-config.ts +++ /dev/null @@ -1,11 +0,0 @@ -export interface IPublicEditorViewConfig { - - /** 视图初始化钩子 */ - init?: () => Promise; - - /** 资源保存时,会调用视图的钩子 */ - save?: () => Promise; - - /** viewType 类型为 'webview' 时渲染的地址 */ - url?: () => Promise; -} diff --git a/packages/types/src/shell/type/editor-view.ts b/packages/types/src/shell/type/editor-view.ts deleted file mode 100644 index e05f8be00..000000000 --- a/packages/types/src/shell/type/editor-view.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { IPublicEditorViewConfig } from './editor-view-config'; - -export interface IPublicTypeEditorView { - - /** 资源名字 */ - viewName: string; - - /** 资源类型 */ - viewType?: 'editor' | 'webview'; - - (ctx: any, options: any): IPublicEditorViewConfig; -} diff --git a/packages/types/src/shell/type/engine-options.ts b/packages/types/src/shell/type/engine-options.ts deleted file mode 100644 index 0bcd1be02..000000000 --- a/packages/types/src/shell/type/engine-options.ts +++ /dev/null @@ -1,181 +0,0 @@ -import { RequestHandlersMap } from '@alilc/lowcode-datasource-types'; -import { ComponentType } from 'react'; - -export interface IPublicTypeEngineOptions { - - /** - * 是否开启 condition 的能力,默认在设计器中不管 condition 是啥都正常展示 - * when this is true, node that configured as conditional not renderring - * will not display in canvas. - * @default false - */ - enableCondition?: boolean; - - /** - * TODO: designMode 无法映射到文档渲染模块 - * - * 设计模式,live 模式将会实时展示变量值,默认值:'design' - * - * @default 'design' - * @experimental - */ - designMode?: 'design' | 'live'; - - /** - * 设备类型,默认值:'default' - * @default 'default' - */ - device?: 'default' | 'mobile' | string; - - /** - * 指定初始化的 deviceClassName,挂载到画布的顶层节点上 - */ - deviceClassName?: string; - - /** - * 语言,默认值:'zh-CN' - * @default 'zh-CN' - */ - locale?: string; - - /** - * 渲染器类型,默认值:'react' - */ - renderEnv?: 'react' | string; - - /** - * 设备类型映射器,处理设计器与渲染器中 device 的映射 - */ - deviceMapper?: { - transform: (originalDevice: string) => string; - }; - - /** - * 开启严格插件模式,默认值:STRICT_PLUGIN_MODE_DEFAULT , 严格模式下,插件将无法通过 engineOptions 传递自定义配置项 - * enable strict plugin mode, default value: false - * under strict mode, customed engineOption is not accepted. - */ - enableStrictPluginMode?: boolean; - - /** - * 开启拖拽组件时,即将被放入的容器是否有视觉反馈,默认值:false - */ - enableReactiveContainer?: boolean; - - /** - * 关闭画布自动渲染,在资产包多重异步加载的场景有效,默认值:false - */ - disableAutoRender?: boolean; - - /** - * 关闭拖拽组件时的虚线响应,性能考虑,默认值:false - */ - disableDetecting?: boolean; - - /** - * 定制画布中点击被忽略的 selectors,默认值:undefined - */ - customizeIgnoreSelectors?: (defaultIgnoreSelectors: string[], e: MouseEvent) => string[]; - - /** - * 禁止默认的设置面板,默认值:false - */ - disableDefaultSettingPanel?: boolean; - - /** - * 禁止默认的设置器,默认值:false - */ - disableDefaultSetters?: boolean; - - /** - * 打开画布的锁定操作,默认值:false - */ - enableCanvasLock?: boolean; - - /** - * 容器锁定后,容器本身是否可以设置属性,仅当画布锁定特性开启时生效,默认值为:false - */ - enableLockedNodeSetting?: boolean; - - /** - * 当选中节点切换时,是否停留在相同的设置 tab 上,默认值:false - */ - stayOnTheSameSettingTab?: boolean; - - /** - * 是否在只有一个 item 的时候隐藏设置 tabs,默认值:false - */ - hideSettingsTabsWhenOnlyOneItem?: boolean; - - /** - * 自定义 loading 组件 - */ - loadingComponent?: ComponentType; - - /** - * 设置所有属性支持变量配置,默认值:false - */ - supportVariableGlobally?: boolean; - - /** - * 设置 simulator 相关的 url,默认值:undefined - */ - simulatorUrl?: string[]; - - /** - * 与 react-renderer 的 appHelper 一致,https://lowcode-engine.cn/site/docs/guide/expand/runtime/renderer#apphelper - */ - appHelper?: { - - /** 全局公共函数 */ - utils?: Record; - - /** 全局常量 */ - constants?: Record; - }; - - /** - * 数据源引擎的请求处理器映射 - */ - requestHandlersMap?: RequestHandlersMap; - - /** - * @default true - * JSExpression 是否只支持使用 this 来访问上下文变量,假如需要兼容原来的 'state.xxx',则设置为 false - */ - thisRequiredInJSE?: boolean; - - /** - * @default false - * 当开启组件未找到严格模式时,渲染模块不会默认给一个容器组件 - */ - enableStrictNotFoundMode?: boolean; - - /** - * 配置指定节点为根组件 - */ - focusNodeSelector?: (rootNode: Node) => Node; - - /** - * 开启应用级设计模式 - */ - enableWorkspaceMode?: boolean; - - /** - * @default true - * 应用级设计模式下,自动打开第一个窗口 - */ - enableAutoOpenFirstWindow?: boolean; - - /** - * @default false - * 开启右键菜单能力 - */ - enableContextMenu?: boolean; - - /** - * @default false - * 隐藏设计器辅助层 - */ - hideComponentAction?: boolean; -} diff --git a/packages/types/src/shell/type/field-config.ts b/packages/types/src/shell/type/field-config.ts deleted file mode 100644 index 42939956e..000000000 --- a/packages/types/src/shell/type/field-config.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { IPublicTypeTitleContent, IPublicTypeSetterType, IPublicTypeFieldExtraProps, IPublicTypeDynamicSetter } from './'; - -/** - * 属性面板配置 - */ -export interface IPublicTypeFieldConfig extends IPublicTypeFieldExtraProps { - - /** - * 面板配置隶属于单个 field 还是分组 - */ - type?: 'field' | 'group'; - - /** - * the name of this setting field, which used in quickEditor - */ - name?: string | number; - - /** - * the field title - * @default sameas .name - */ - title?: IPublicTypeTitleContent; - - /** - * 单个属性的 setter 配置 - * - * the field body contains when .type = 'field' - */ - setter?: IPublicTypeSetterType | IPublicTypeDynamicSetter; - - /** - * the setting items which group body contains when .type = 'group' - */ - items?: IPublicTypeFieldConfig[]; - - /** - * extra props for field - * 其他配置属性(不做流通要求) - */ - extraProps?: IPublicTypeFieldExtraProps; -} diff --git a/packages/types/src/shell/type/field-extra-props.ts b/packages/types/src/shell/type/field-extra-props.ts deleted file mode 100644 index 7aae7e0fe..000000000 --- a/packages/types/src/shell/type/field-extra-props.ts +++ /dev/null @@ -1,81 +0,0 @@ -import { IPublicModelSettingField } from '../model'; -import { IPublicTypeLiveTextEditingConfig } from './'; - -/** - * extra props for field - */ -export interface IPublicTypeFieldExtraProps { - - /** - * 是否必填参数 - */ - isRequired?: boolean; - - /** - * default value of target prop for setter use - */ - defaultValue?: any; - - /** - * get value for field - */ - getValue?: (target: IPublicModelSettingField, fieldValue: any) => any; - - /** - * set value for field - */ - setValue?: (target: IPublicModelSettingField, value: any) => void; - - /** - * the field conditional show, is not set always true - * @default undefined - */ - condition?: (target: IPublicModelSettingField) => boolean; - - /** - * 配置当前 prop 是否忽略默认值处理逻辑,如果返回值是 true 引擎不会处理默认值 - * @returns boolean - */ - ignoreDefaultValue?: (target: IPublicModelSettingField) => boolean; - - /** - * autorun when something change - */ - autorun?: (target: IPublicModelSettingField) => void; - - /** - * default collapsed when display accordion - */ - defaultCollapsed?: boolean; - - /** - * important field - */ - important?: boolean; - - /** - * internal use - */ - forceInline?: number; - - /** - * 是否支持变量配置 - */ - supportVariable?: boolean; - - /** - * compatiable vision display - */ - display?: 'accordion' | 'inline' | 'block' | 'plain' | 'popup' | 'entry'; - - // @todo 这个 omit 是否合理? - /** - * @todo 待补充文档 - */ - liveTextEditing?: Omit; - - /** - * onChange 事件 - */ - onChange?: (value: any, field: IPublicModelSettingField) => void; -} diff --git a/packages/types/src/shell/type/hotkey-callback-config.ts b/packages/types/src/shell/type/hotkey-callback-config.ts deleted file mode 100644 index cc4193612..000000000 --- a/packages/types/src/shell/type/hotkey-callback-config.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { IPublicTypeHotkeyCallback } from './'; - -export interface IPublicTypeHotkeyCallbackConfig { - callback: IPublicTypeHotkeyCallback; - modifiers: string[]; - action: string; - seq?: string; - level?: number; - combo?: string; -} diff --git a/packages/types/src/shell/type/hotkey-callback.ts b/packages/types/src/shell/type/hotkey-callback.ts deleted file mode 100644 index 4650b9b5c..000000000 --- a/packages/types/src/shell/type/hotkey-callback.ts +++ /dev/null @@ -1,2 +0,0 @@ - -export type IPublicTypeHotkeyCallback = (e: KeyboardEvent, combo?: string) => any | false; diff --git a/packages/types/src/shell/type/hotkey-callbacks.ts b/packages/types/src/shell/type/hotkey-callbacks.ts deleted file mode 100644 index d31b744d1..000000000 --- a/packages/types/src/shell/type/hotkey-callbacks.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { IPublicTypeHotkeyCallbackConfig } from './'; - -export interface IPublicTypeHotkeyCallbacks { - [key: string]: IPublicTypeHotkeyCallbackConfig[]; -} diff --git a/packages/types/src/shell/type/i18n-data.ts b/packages/types/src/shell/type/i18n-data.ts deleted file mode 100644 index 764d5f82d..000000000 --- a/packages/types/src/shell/type/i18n-data.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { ReactNode } from 'react'; - -export interface IPublicTypeI18nData { - type: 'i18n'; - intl?: ReactNode; - [key: string]: any; -} diff --git a/packages/types/src/shell/type/i18n-map.ts b/packages/types/src/shell/type/i18n-map.ts deleted file mode 100644 index 4d56a20b5..000000000 --- a/packages/types/src/shell/type/i18n-map.ts +++ /dev/null @@ -1,4 +0,0 @@ - -export interface IPublicTypeI18nMap { - [lang: string]: { [key: string]: string }; -} diff --git a/packages/types/src/shell/type/icon-config.ts b/packages/types/src/shell/type/icon-config.ts deleted file mode 100644 index f45fe7d69..000000000 --- a/packages/types/src/shell/type/icon-config.ts +++ /dev/null @@ -1,6 +0,0 @@ - -export interface IPublicTypeIconConfig { - type: string; - size?: number | 'small' | 'xxs' | 'xs' | 'medium' | 'large' | 'xl' | 'xxl' | 'xxxl' | 'inherit'; - className?: string; -} diff --git a/packages/types/src/shell/type/icon-type.ts b/packages/types/src/shell/type/icon-type.ts deleted file mode 100644 index 99882556b..000000000 --- a/packages/types/src/shell/type/icon-type.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { ReactElement, ComponentType } from 'react'; -import { IPublicTypeIconConfig } from './'; - -export type IPublicTypeIconType = string | ReactElement | ComponentType | IPublicTypeIconConfig; diff --git a/packages/types/src/shell/type/index.ts b/packages/types/src/shell/type/index.ts deleted file mode 100644 index c72cf93e4..000000000 --- a/packages/types/src/shell/type/index.ts +++ /dev/null @@ -1,96 +0,0 @@ -// this folder contains all interfaces/types working as type definition -// - some exists as type TypeName -// - some althought exists as interfaces , but there won`t be any class implements them. -// all of above cases will with prefix IPublicType, eg. IPublicTypeSomeName -export * from './location'; -export * from './active-target'; -export * from './component-instance'; -export * from './node-schema'; -export * from './disposable'; -export * from './assets-json'; -export * from './metadata-transducer'; -export * from './component-action'; -export * from './preference-value-type'; -export * from './project-schema'; -export * from './block-schema'; -export * from './component-schema'; -export * from './container-schema'; -export * from './page-schema'; -export * from './root-schema'; -export * from './props-transducer'; -export * from './registered-setter'; -export * from './custom-view'; -export * from './widget-base-config'; -export * from './node-data'; -export * from './icon-type'; -export * from './transformed-component-metadata'; -export * from './i18n-data'; -export * from './npm-info'; -export * from './drag-node-data-object'; -export * from './drag-node-object'; -export * from './prop-change-options'; -export * from './drag-any-object'; -export * from './drag-object'; -export * from './composite-value'; -export * from './props-map'; -export * from './props-list'; -export * from './plugin-config'; -export * from './plugin-declaration-property'; -export * from './plugin-declaration'; -export * from './plugin-meta'; -export * from './plugin-creater'; -export * from './plugin'; -export * from './setter-type'; -export * from './set-value-options'; -export * from './field-config'; -export * from './field-extra-props'; -export * from './component-sort'; -export * from './component-metadata'; -export * from './reference'; -export * from './component-description'; -export * from './remote-component-description'; -export * from './package'; -export * from './action-content-object'; -export * from './title-config'; -export * from './title-content'; -export * from './prop-config'; -export * from './prop-types'; -export * from './snippet'; -export * from './advanced'; -export * from './configure'; -export * from './value-type'; -export * from './tip-content'; -export * from './metadata'; -export * from './dynamic-setter'; -export * from './icon-config'; -export * from './dom-text'; -export * from './i18n-map'; -export * from './app-config'; -export * from './npm'; -export * from './dynamic-props'; -export * from './setter-config'; -export * from './tip-config'; -export * from './widget-config-area'; -export * from './hotkey-callback'; -export * from './plugin-register-options'; -export * from './resource-list'; -export * from './engine-options'; -export * from './on-change-options'; -export * from './slot-schema'; -export * from './node-data-type'; -export * from './node-instance'; -export * from './editor-value-key'; -export * from './editor-get-options'; -export * from './editor-get-result'; -export * from './editor-register-options'; -export * from './editor-view'; -export * from './resource-type'; -export * from './resource-type-config'; -export * from './editor-view-config'; -export * from './hotkey-callback-config'; -export * from './hotkey-callbacks'; -export * from './scrollable'; -export * from './simulator-renderer'; -export * from './config-transducer'; -export * from './context-menu'; -export * from './command'; diff --git a/packages/types/src/shell/type/location.ts b/packages/types/src/shell/type/location.ts deleted file mode 100644 index f9cb66172..000000000 --- a/packages/types/src/shell/type/location.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { IPublicModelNode, IPublicModelLocateEvent } from '../model'; - -export enum IPublicTypeLocationDetailType { - Children = 'Children', - Prop = 'Prop', -} - -export type IPublicTypeRect = DOMRect & { - elements?: Array; - computed?: boolean; -}; - -export interface IPublicTypeLocationChildrenDetail { - type: IPublicTypeLocationDetailType.Children; - index?: number | null; - - /** - * 是否有效位置 - */ - valid?: boolean; - edge?: DOMRect; - near?: { - node: IPublicModelNode; - pos: 'before' | 'after' | 'replace'; - rect?: IPublicTypeRect; - align?: 'V' | 'H'; - }; - focus?: { type: 'slots' } | { type: 'node'; node: IPublicModelNode }; -} - -export interface IPublicTypeLocationPropDetail { - // cover 形态,高亮 domNode,如果 domNode 为空,取 container 的值 - type: IPublicTypeLocationDetailType.Prop; - name: string; - domNode?: HTMLElement; -} - -export type IPublicTypeLocationDetail = IPublicTypeLocationChildrenDetail | IPublicTypeLocationPropDetail | { [key: string]: any; type: string }; - -export interface IPublicTypeLocationData< - Node = IPublicModelNode -> { - target: Node; // shadowNode | ConditionFlow | ElementNode | RootNode - detail: IPublicTypeLocationDetail; - source: string; - event: IPublicModelLocateEvent; -} diff --git a/packages/types/src/shell/type/metadata-transducer.ts b/packages/types/src/shell/type/metadata-transducer.ts deleted file mode 100644 index e5e407e36..000000000 --- a/packages/types/src/shell/type/metadata-transducer.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { IPublicTypeTransformedComponentMetadata } from './'; - - -export interface IPublicTypeMetadataTransducer { - (prev: IPublicTypeTransformedComponentMetadata): IPublicTypeTransformedComponentMetadata; - /** - * 0 - 9 system - * 10 - 99 builtin-plugin - * 100 - app & plugin - */ - level?: number; - /** - * use to replace TODO - */ - id?: string; -} diff --git a/packages/types/src/shell/type/metadata.ts b/packages/types/src/shell/type/metadata.ts deleted file mode 100644 index bfa87e049..000000000 --- a/packages/types/src/shell/type/metadata.ts +++ /dev/null @@ -1,232 +0,0 @@ -import { MouseEvent } from 'react'; -import { IPublicTypePropType, IPublicTypeComponentAction } from './'; -import { IPublicModelNode, IPublicModelSettingField } from '../model'; - -/** - * 嵌套控制函数 - */ -export type IPublicTypeNestingFilter = (testNode: any, currentNode: any) => boolean; - -/** - * 嵌套控制 - * 防止错误的节点嵌套,比如 a 嵌套 a, FormField 只能在 Form 容器下,Column 只能在 Table 下等 - */ -export interface IPublicTypeNestingRule { - - /** - * 子级白名单 - */ - childWhitelist?: string[] | string | RegExp | IPublicTypeNestingFilter; - - /** - * 父级白名单 - */ - parentWhitelist?: string[] | string | RegExp | IPublicTypeNestingFilter; - - /** - * 后裔白名单 - */ - descendantWhitelist?: string[] | string | RegExp | IPublicTypeNestingFilter; - - /** - * 后裔黑名单 - */ - descendantBlacklist?: string[] | string | RegExp | IPublicTypeNestingFilter; - - /** - * 祖先白名单 可用来做区域高亮 - */ - ancestorWhitelist?: string[] | string | RegExp | IPublicTypeNestingFilter; -} - -/** - * 组件能力配置 - */ -export interface IPublicTypeComponentConfigure { - - /** - * 是否容器组件 - */ - isContainer?: boolean; - - /** - * 组件是否带浮层,浮层组件拖入设计器时会遮挡画布区域,此时应当辅助一些交互以防止阻挡 - */ - isModal?: boolean; - - /** - * 是否存在渲染的根节点 - */ - isNullNode?: boolean; - - /** - * 组件树描述信息 - */ - descriptor?: string; - - /** - * 嵌套控制:防止错误的节点嵌套 - * 比如 a 嵌套 a, FormField 只能在 Form 容器下,Column 只能在 Table 下等 - */ - nestingRule?: IPublicTypeNestingRule; - - /** - * 是否是最小渲染单元 - * 最小渲染单元下的组件渲染和更新都从单元的根节点开始渲染和更新。如果嵌套了多层最小渲染单元,渲染会从最外层的最小渲染单元开始渲染。 - */ - isMinimalRenderUnit?: boolean; - - /** - * 组件选中框的 cssSelector - */ - rootSelector?: string; - - /** - * 禁用的行为,可以为 `'copy'`, `'move'`, `'remove'` 或它们组成的数组 - */ - disableBehaviors?: string[] | string; - - /** - * 用于详细配置上述操作项的内容 - */ - actions?: IPublicTypeComponentAction[]; -} - -export interface IPublicTypeInitialItem { - name: string; - initial: (target: IPublicModelSettingField, currentValue: any) => any; -} -export interface IPublicTypeFilterItem { - name: string; - filter: (target: IPublicModelSettingField | null, currentValue: any) => any; -} -export interface IPublicTypeAutorunItem { - name: string; - autorun: (target: IPublicModelSettingField | null | undefined) => any; -} - -// thinkof Array -/** - * Live Text Editing(如果 children 内容是纯文本,支持双击直接编辑)的可配置项目 - */ -export interface IPublicTypeLiveTextEditingConfig { - - /** - * @todo 待补充文档 - */ - propTarget: string; - - /** - * @todo 待补充文档 - */ - selector?: string; - - /** - * 编辑模式 纯文本 | 段落编辑 | 文章编辑(默认纯文本,无跟随工具条) - * @default 'plaintext' - */ - mode?: 'plaintext' | 'paragraph' | 'article'; - - /** - * 从 contentEditable 获取内容并设置到属性 - */ - onSaveContent?: (content: string, prop: any) => any; -} - -export type ConfigureSupportEvent = string | ConfigureSupportEventConfig; - -export interface ConfigureSupportEventConfig { - name: string; - propType?: IPublicTypePropType; - description?: string; - template?: string; -} - -/** - * 通用扩展面板支持性配置 - */ -export interface ConfigureSupport { - - /** - * 支持事件列表 - */ - events?: ConfigureSupportEvent[]; - - /** - * 支持 className 设置 - */ - className?: boolean; - - /** - * 支持样式设置 - */ - style?: boolean; - - /** - * 支持生命周期设置 - */ - lifecycles?: any[]; - - // general?: boolean; - /** - * 支持循环设置 - */ - loop?: boolean; - - /** - * 支持条件式渲染设置 - */ - condition?: boolean; -} - -/** - * handleResizing - */ - -/** - * 配置 callbacks 可捕获引擎抛出的一些事件,例如 onNodeAdd、onResize 等 - */ -export interface IPublicTypeCallbacks { - // hooks - onMouseDownHook?: (e: MouseEvent, currentNode: IPublicModelNode | null) => any; - onDblClickHook?: (e: MouseEvent, currentNode: IPublicModelNode | null) => any; - onClickHook?: (e: MouseEvent, currentNode: IPublicModelNode | null) => any; - // onLocateHook?: (e: any, currentNode: any) => any; - // onAcceptHook?: (currentNode: any, locationData: any) => any; - onMoveHook?: (currentNode: IPublicModelNode) => boolean; - // thinkof 限制性拖拽 - onHoverHook?: (currentNode: IPublicModelNode) => boolean; - - /** 选中 hook,如果返回值是 false,可以控制组件不可被选中 */ - onSelectHook?: (currentNode: IPublicModelNode) => boolean; - onChildMoveHook?: (childNode: IPublicModelNode, currentNode: IPublicModelNode) => boolean; - - // events - onNodeRemove?: (removedNode: IPublicModelNode | null, currentNode: IPublicModelNode | null) => void; - onNodeAdd?: (addedNode: IPublicModelNode | null, currentNode: IPublicModelNode | null) => void; - onSubtreeModified?: (currentNode: IPublicModelNode, options: any) => void; - onResize?: ( - e: MouseEvent & { - trigger: string; - deltaX?: number; - deltaY?: number; - }, - currentNode: any, - ) => void; - onResizeStart?: ( - e: MouseEvent & { - trigger: string; - deltaX?: number; - deltaY?: number; - }, - currentNode: any, - ) => void; - onResizeEnd?: ( - e: MouseEvent & { - trigger: string; - deltaX?: number; - deltaY?: number; - }, - currentNode: IPublicModelNode, - ) => void; -} diff --git a/packages/types/src/shell/type/node-data-type.ts b/packages/types/src/shell/type/node-data-type.ts deleted file mode 100644 index d7f68041a..000000000 --- a/packages/types/src/shell/type/node-data-type.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { IPublicTypeNodeData } from './node-data'; - -export type IPublicTypeNodeDataType = IPublicTypeNodeData | IPublicTypeNodeData[]; diff --git a/packages/types/src/shell/type/node-data.ts b/packages/types/src/shell/type/node-data.ts deleted file mode 100644 index 1314233b0..000000000 --- a/packages/types/src/shell/type/node-data.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { - IPublicTypeJSExpression, - IPublicTypeNodeSchema, - IPublicTypeDOMText, - IPublicTypeI18nData, -} from './'; - -export type IPublicTypeNodeData = - | IPublicTypeNodeSchema - | IPublicTypeJSExpression - | IPublicTypeDOMText - | IPublicTypeI18nData; diff --git a/packages/types/src/shell/type/node-instance.ts b/packages/types/src/shell/type/node-instance.ts deleted file mode 100644 index fab8e672b..000000000 --- a/packages/types/src/shell/type/node-instance.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { IPublicTypeComponentInstance, IPublicModelNode } from '..'; - -export interface IPublicTypeNodeInstance< - T = IPublicTypeComponentInstance, - Node = IPublicModelNode -> { - docId: string; - nodeId: string; - instance: T; - node?: Node | null; -} diff --git a/packages/types/src/shell/type/node-schema.ts b/packages/types/src/shell/type/node-schema.ts deleted file mode 100644 index 9cbd0a81a..000000000 --- a/packages/types/src/shell/type/node-schema.ts +++ /dev/null @@ -1,59 +0,0 @@ -import { IPublicTypeCompositeValue, IPublicTypePropsMap, IPublicTypeNodeData } from './'; - -// 转换成一个 .jsx 文件内 React Class 类 render 函数返回的 jsx 代码 -/** - * 搭建基础协议 - 单个组件树节点描述 - */ -export interface IPublicTypeNodeSchema { - - id?: string; - - /** - * 组件名称 必填、首字母大写 - */ - componentName: string; - - /** - * 组件属性对象 - */ - props?: { - children?: IPublicTypeNodeData | IPublicTypeNodeData[]; - } & IPublicTypePropsMap; // | PropsList; - - /** - * 渲染条件 - */ - condition?: IPublicTypeCompositeValue; - - /** - * 循环数据 - */ - loop?: IPublicTypeCompositeValue; - - /** - * 循环迭代对象、索引名称 ["item", "index"] - */ - loopArgs?: [string, string]; - - /** - * 子节点 - */ - children?: IPublicTypeNodeData | IPublicTypeNodeData[]; - - /** - * 是否锁定 - */ - isLocked?: boolean; - - // @todo - // ------- future support ----- - conditionGroup?: string; - title?: string; - ignore?: boolean; - locked?: boolean; - hidden?: boolean; - isTopFixed?: boolean; - - /** @experimental 编辑态内部使用 */ - __ctx?: any; -} diff --git a/packages/types/src/shell/type/npm-info.ts b/packages/types/src/shell/type/npm-info.ts deleted file mode 100644 index e91c39ebc..000000000 --- a/packages/types/src/shell/type/npm-info.ts +++ /dev/null @@ -1,33 +0,0 @@ -/** - * npm 源引入完整描述对象 - */ -export interface IPublicTypeNpmInfo { - /** - * 源码组件名称 - */ - componentName?: string; - /** - * 源码组件库名 - */ - package: string; - /** - * 源码组件版本号 - */ - version?: string; - /** - * 是否解构 - */ - destructuring?: boolean; - /** - * 源码组件名称 - */ - exportName?: string; - /** - * 子组件名 - */ - subName?: string; - /** - * 组件路径 - */ - main?: string; -} diff --git a/packages/types/src/shell/type/npm.ts b/packages/types/src/shell/type/npm.ts deleted file mode 100644 index 736c723b1..000000000 --- a/packages/types/src/shell/type/npm.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { IPublicTypeNpmInfo } from './npm-info'; - -export interface IPublicTypeLowCodeComponent { - /** - * 研发模式 - */ - devMode: 'lowCode'; - /** - * 组件名称 - */ - componentName: string; -} - -export type IPublicTypeProCodeComponent = IPublicTypeNpmInfo; -export type IPublicTypeComponentMap = - | IPublicTypeProCodeComponent - | IPublicTypeLowCodeComponent; -export type IPublicTypeComponentsMap = IPublicTypeComponentMap[]; diff --git a/packages/types/src/shell/type/on-change-options.ts b/packages/types/src/shell/type/on-change-options.ts deleted file mode 100644 index 47b88d72f..000000000 --- a/packages/types/src/shell/type/on-change-options.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { IPublicModelNode } from '..'; - -export interface IPublicTypeOnChangeOptions< - Node = IPublicModelNode -> { - type: string; - node: Node; -} diff --git a/packages/types/src/shell/type/package.ts b/packages/types/src/shell/type/package.ts deleted file mode 100644 index b33fa3f94..000000000 --- a/packages/types/src/shell/type/package.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { EitherOr } from '../../utils'; -import { IPublicTypeComponentSchema, IPublicTypeProjectSchema } from './'; - -/** - * 定义组件大包及 external 资源的信息 - * 应该被编辑器默认加载 - */ -export type IPublicTypePackage = EitherOr<{ - /** - * npm 包名 - */ - package: string; - /** - * 包唯一标识 - */ - id: string; - /** - * 包版本号 - */ - version: string; - /** - * 组件渲染态视图打包后的 CDN url 列表,包含 js 和 css - */ - urls?: string[] | any; - /** - * 组件编辑态视图打包后的 CDN url 列表,包含 js 和 css - */ - editUrls?: string[] | any; - /** - * 作为全局变量引用时的名称,和webpack output.library字段含义一样,用来定义全局变量名 - */ - library: string; - /** - * @experimental - * - * TODO: 需推进提案 @度城 - */ - async?: boolean; - /** - * 标识当前 package 从其他 package 的导出方式 - */ - exportMode?: 'functionCall'; - /** - * 标识当前 package 是从 window 上的哪个属性导出来的 - */ - exportSourceLibrary?: any; - /** - * 组件描述导出名字,可以通过 window[exportName] 获取到组件描述的 Object 内容; - */ - exportName?: string; - /** - * 低代码组件 schema 内容 - */ - schema?: IPublicTypeProjectSchema; -}, 'package', 'id'>; diff --git a/packages/types/src/shell/type/page-schema.ts b/packages/types/src/shell/type/page-schema.ts deleted file mode 100644 index 670c65451..000000000 --- a/packages/types/src/shell/type/page-schema.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { IPublicTypeContainerSchema } from './'; - -/** - * 页面容器 - * @see https://lowcode-engine.cn/lowcode - */ -export interface IPublicTypePageSchema extends IPublicTypeContainerSchema { - componentName: 'Page'; -} diff --git a/packages/types/src/shell/type/plugin-config.ts b/packages/types/src/shell/type/plugin-config.ts deleted file mode 100644 index 2d841dd80..000000000 --- a/packages/types/src/shell/type/plugin-config.ts +++ /dev/null @@ -1,5 +0,0 @@ -export interface IPublicTypePluginConfig { - init(): Promise | void; - destroy?(): Promise | void; - exports?(): any; -} diff --git a/packages/types/src/shell/type/plugin-creater.ts b/packages/types/src/shell/type/plugin-creater.ts deleted file mode 100644 index 3ffc49811..000000000 --- a/packages/types/src/shell/type/plugin-creater.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { IPublicTypePluginConfig } from './'; -import { IPublicModelPluginContext } from '../model'; - -export type IPublicTypePluginCreater = ( - ctx: IPublicModelPluginContext, options: any -) => IPublicTypePluginConfig; diff --git a/packages/types/src/shell/type/plugin-declaration-property.ts b/packages/types/src/shell/type/plugin-declaration-property.ts deleted file mode 100644 index a7389ee04..000000000 --- a/packages/types/src/shell/type/plugin-declaration-property.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { IPublicTypePluginPreferenceValueType } from './'; - -export interface IPublicTypePluginDeclarationProperty { - // shape like 'name' or 'group.name' or 'group.subGroup.name' - key: string; - // must have either one of description & markdownDescription - description: string; - // value in 'number', 'string', 'boolean' - type: string; - // default value - // NOTE! this is only used in configuration UI, won`t affect runtime - default?: IPublicTypePluginPreferenceValueType; - // only works when type === 'string', default value false - useMultipleLineTextInput?: boolean; - // enum values, only works when type === 'string' - enum?: any[]; - // descriptions for enum values - enumDescriptions?: string[]; - // message that describing deprecation of this property - deprecationMessage?: string; -} diff --git a/packages/types/src/shell/type/plugin-declaration.ts b/packages/types/src/shell/type/plugin-declaration.ts deleted file mode 100644 index 4d5e1a4e6..000000000 --- a/packages/types/src/shell/type/plugin-declaration.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { IPublicTypePluginDeclarationProperty } from './'; - -/** - * declaration of plugin`s preference - * when strictPluginMode === true, only declared preference can be obtained from inside plugin. - */ -export interface IPublicTypePluginDeclaration { - // this will be displayed on configuration UI, can be plugin name - title: string; - properties: IPublicTypePluginDeclarationProperty[]; -} diff --git a/packages/types/src/shell/type/plugin-meta.ts b/packages/types/src/shell/type/plugin-meta.ts deleted file mode 100644 index bf7f6212e..000000000 --- a/packages/types/src/shell/type/plugin-meta.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { IPublicTypePluginDeclaration } from './'; - -export interface IPublicTypePluginMeta { - - /** - * define dependencies which the plugin depends on - */ - dependencies?: string[]; - - /** - * specify which engine version is compatible with the plugin - */ - engines?: { - - /** e.g. '^1.0.0' */ - lowcodeEngine?: string; - }; - preferenceDeclaration?: IPublicTypePluginDeclaration; - - /** - * use 'common' as event prefix when eventPrefix is not set. - * strongly recommend using pluginName as eventPrefix - * - * eg. - * case 1, when eventPrefix is not specified - * event.emit('someEventName') is actually sending event with name 'common:someEventName' - * - * case 2, when eventPrefix is 'myEvent' - * event.emit('someEventName') is actually sending event with name 'myEvent:someEventName' - */ - eventPrefix?: string; - - /** - * 如果要使用 command 注册命令,需要在插件 meta 中定义 commandScope - */ - commandScope?: string; -} diff --git a/packages/types/src/shell/type/plugin-register-options.ts b/packages/types/src/shell/type/plugin-register-options.ts deleted file mode 100644 index 7d2377bbe..000000000 --- a/packages/types/src/shell/type/plugin-register-options.ts +++ /dev/null @@ -1,13 +0,0 @@ - -export interface IPublicTypePluginRegisterOptions { - /** - * Will enable plugin registered with auto-initialization immediately - * other than plugin-manager init all plugins at certain time. - * It is helpful when plugin register is later than plugin-manager initialization. - */ - autoInit?: boolean; - /** - * allow overriding existing plugin with same name when override === true - */ - override?: boolean; -} diff --git a/packages/types/src/shell/type/plugin.ts b/packages/types/src/shell/type/plugin.ts deleted file mode 100644 index 6f1f6c223..000000000 --- a/packages/types/src/shell/type/plugin.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { IPublicTypePluginMeta, IPublicTypePluginCreater } from './'; - -export interface IPublicTypePlugin extends IPublicTypePluginCreater { - pluginName: string; - meta?: IPublicTypePluginMeta; -} diff --git a/packages/types/src/shell/type/preference-value-type.ts b/packages/types/src/shell/type/preference-value-type.ts deleted file mode 100644 index 59c8045aa..000000000 --- a/packages/types/src/shell/type/preference-value-type.ts +++ /dev/null @@ -1,2 +0,0 @@ - -export type IPublicTypePluginPreferenceValueType = string | number | boolean; diff --git a/packages/types/src/shell/type/project-schema.ts b/packages/types/src/shell/type/project-schema.ts deleted file mode 100644 index 271841bfb..000000000 --- a/packages/types/src/shell/type/project-schema.ts +++ /dev/null @@ -1,68 +0,0 @@ -import { InterpretDataSource as DataSource } from '@alilc/lowcode-datasource-types'; -import { IPublicTypeJSONObject, IPublicTypeRootSchema, IPublicTypeI18nMap, IPublicTypeAppConfig, IPublicTypeComponentsMap, IPublicTypeJSExpression, IPublicTypeJSFunction, IPublicTypeNpmInfo } from './'; - -export interface IPublicTypeInternalUtils { - name: string; - type: 'function'; - content: IPublicTypeJSFunction | IPublicTypeJSExpression; -} - -export interface IPublicTypeExternalUtils { - name: string; - type: 'npm' | 'tnpm'; - content: IPublicTypeNpmInfo; -} - -export type IPublicTypeUtilItem = IPublicTypeInternalUtils | IPublicTypeExternalUtils; -export type IPublicTypeUtilsMap = IPublicTypeUtilItem[]; -/** - * 应用描述 - */ - -export interface IPublicTypeProjectSchema { - id?: string; - /** - * 当前应用协议版本号 - */ - version: string; - /** - * 当前应用所有组件映射关系 - */ - componentsMap: IPublicTypeComponentsMap; - /** - * 描述应用所有页面、低代码组件的组件树 - * 低代码业务组件树描述 - * 是长度固定为 1 的数组,即数组内仅包含根容器的描述(低代码业务组件容器类型) - */ - componentsTree: T[]; - /** - * 国际化语料 - */ - i18n?: IPublicTypeI18nMap; - /** - * 应用范围内的全局自定义函数或第三方工具类扩展 - */ - utils?: IPublicTypeUtilsMap; - /** - * 应用范围内的全局常量 - */ - constants?: IPublicTypeJSONObject; - /** - * 应用范围内的全局样式 - */ - css?: string; - /** - * 当前应用的公共数据源 - */ - dataSource?: DataSource; - /** - * 当前应用配置信息 - * - * TODO: 需要在后续版本中移除 `Record` 类型签名 - */ - config?: IPublicTypeAppConfig & Record; - /** - * 当前应用元数据信息 - */ - meta?: Record; -} diff --git a/packages/types/src/shell/type/prop-change-options.ts b/packages/types/src/shell/type/prop-change-options.ts deleted file mode 100644 index b515aec53..000000000 --- a/packages/types/src/shell/type/prop-change-options.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { - IPublicModelNode, - IPublicModelProp, -} from '../model'; - -export interface IPublicTypePropChangeOptions< - Node = IPublicModelNode -> { - key?: string | number; - prop?: IPublicModelProp; - node: Node; - newValue: any; - oldValue: any; -} diff --git a/packages/types/src/shell/type/prop-config.ts b/packages/types/src/shell/type/prop-config.ts deleted file mode 100644 index 74d78f5bc..000000000 --- a/packages/types/src/shell/type/prop-config.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { IPublicTypePropType } from './'; - -/** - * 组件属性信息 - */ -export interface IPublicTypePropConfig { - /** - * 属性名称 - */ - name: string; - /** - * 属性类型 - */ - propType: IPublicTypePropType; - /** - * 属性描述 - */ - description?: string; - /** - * 属性默认值 - */ - defaultValue?: any; -} diff --git a/packages/types/src/shell/type/prop-types.ts b/packages/types/src/shell/type/prop-types.ts deleted file mode 100644 index 4d8438a53..000000000 --- a/packages/types/src/shell/type/prop-types.ts +++ /dev/null @@ -1,67 +0,0 @@ -/* eslint-disable max-len */ -import { IPublicTypePropConfig } from './'; - -export type IPublicTypePropType = - | IPublicTypeBasicType - | IPublicTypeRequiredType - | IPublicTypeComplexType; -export type IPublicTypeBasicType = - | 'array' - | 'bool' - | 'func' - | 'number' - | 'object' - | 'string' - | 'node' - | 'element' - | 'any'; -export type IPublicTypeComplexType = - | IPublicTypeOneOf - | IPublicTypeOneOfType - | IPublicTypeArrayOf - | IPublicTypeObjectOf - | IPublicTypeShape - | IPublicTypeExact - | IPublicTypeInstanceOf; - -export interface IPublicTypeRequiredType { - type: IPublicTypeBasicType; - isRequired?: boolean; -} - -export interface IPublicTypeOneOf { - type: 'oneOf'; - value: string[]; - isRequired?: boolean; -} -export interface IPublicTypeOneOfType { - type: 'oneOfType'; - value: IPublicTypePropType[]; - isRequired?: boolean; -} -export interface IPublicTypeArrayOf { - type: 'arrayOf'; - value: IPublicTypePropType; - isRequired?: boolean; -} -export interface IPublicTypeObjectOf { - type: 'objectOf'; - value: IPublicTypePropType; - isRequired?: boolean; -} -export interface IPublicTypeShape { - type: 'shape'; - value: IPublicTypePropConfig[]; - isRequired?: boolean; -} -export interface IPublicTypeExact { - type: 'exact'; - value: IPublicTypePropConfig[]; - isRequired?: boolean; -} - -export interface IPublicTypeInstanceOf { - type: 'instanceOf'; - value: IPublicTypePropConfig; - isRequired?: boolean; -} diff --git a/packages/types/src/shell/type/props-list.ts b/packages/types/src/shell/type/props-list.ts deleted file mode 100644 index 801c088b6..000000000 --- a/packages/types/src/shell/type/props-list.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { IPublicTypeCompositeValue } from './'; - -export type IPublicTypePropsList = Array<{ - spread?: boolean; - name?: string; - value: IPublicTypeCompositeValue; -}>; diff --git a/packages/types/src/shell/type/props-map.ts b/packages/types/src/shell/type/props-map.ts deleted file mode 100644 index 1b93f4625..000000000 --- a/packages/types/src/shell/type/props-map.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { IPublicTypeCompositeObject, IPublicTypeNodeData } from './'; - -export type IPublicTypePropsMap = IPublicTypeCompositeObject; diff --git a/packages/types/src/shell/type/props-transducer.ts b/packages/types/src/shell/type/props-transducer.ts deleted file mode 100644 index b9eb74045..000000000 --- a/packages/types/src/shell/type/props-transducer.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { IPublicEnumTransformStage } from '../enum'; -import { IPublicModelNode } from '../model'; -import { IPublicTypePropsMap } from './'; - -export type IPublicTypePropsTransducer = ( - props: IPublicTypePropsMap, - node: IPublicModelNode, - ctx?: { - stage: IPublicEnumTransformStage; - }, -) => IPublicTypePropsMap; diff --git a/packages/types/src/shell/type/reference.ts b/packages/types/src/shell/type/reference.ts deleted file mode 100644 index 34de153d9..000000000 --- a/packages/types/src/shell/type/reference.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { EitherOr } from '../../utils'; - -/** - * 资源引用信息,Npm 的升级版本, - */ -export type IPublicTypeReference = EitherOr<{ - /** - * 引用资源的 id 标识 - */ - id: string; - /** - * 引用资源的包名 - */ - package: string; - /** - * 引用资源的导出对象中的属性值名称 - */ - exportName: string; - /** - * 引用 exportName 上的子对象 - */ - subName: string; - /** - * 引用的资源主入口 - */ - main?: string; - /** - * 是否从引用资源的导出对象中获取属性值 - */ - destructuring?: boolean; - /** - * 资源版本号 - */ - version: string; -}, 'package', 'id'>; diff --git a/packages/types/src/shell/type/registered-setter.ts b/packages/types/src/shell/type/registered-setter.ts deleted file mode 100644 index 55a90465a..000000000 --- a/packages/types/src/shell/type/registered-setter.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { IPublicModelSettingField } from '../model'; -import { IPublicTypeCustomView, IPublicTypeTitleContent } from './'; - -export interface IPublicTypeRegisteredSetter { - component: IPublicTypeCustomView; - defaultProps?: object; - title?: IPublicTypeTitleContent; - - /** - * for MixedSetter to check this setter if available - */ - condition?: (field: IPublicModelSettingField) => boolean; - - /** - * for MixedSetter to manual change to this setter - */ - initialValue?: any | ((field: IPublicModelSettingField) => any); - recommend?: boolean; - // 标识是否为动态 setter,默认为 true - isDynamic?: boolean; -} diff --git a/packages/types/src/shell/type/remote-component-description.ts b/packages/types/src/shell/type/remote-component-description.ts deleted file mode 100644 index 233720365..000000000 --- a/packages/types/src/shell/type/remote-component-description.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { Asset } from '../../assets'; -import { IPublicTypeComponentMetadata, IPublicTypeReference } from './'; - -/** - * 远程物料描述 - */ -export interface IPublicTypeRemoteComponentDescription extends IPublicTypeComponentMetadata { - - /** - * 组件描述导出名字,可以通过 window[exportName] 获取到组件描述的 Object 内容; - */ - exportName?: string; - - /** - * 组件描述的资源链接; - */ - url?: Asset; - - /** - * 组件 (库) 的 npm 信息; - */ - package?: { - npm?: string; - }; - - /** - * 替代 npm 字段的升级版本 - */ - reference?: IPublicTypeReference; -} diff --git a/packages/types/src/shell/type/resource-list.ts b/packages/types/src/shell/type/resource-list.ts deleted file mode 100644 index 543bb14d5..000000000 --- a/packages/types/src/shell/type/resource-list.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { ReactElement } from 'react'; - -export interface IPublicResourceData { - - /** 资源名字 */ - resourceName: string; - - /** 资源扩展配置 */ - config?: { - [key: string]: any; - }; - - /** 资源标题 */ - title?: string; - - /** 资源 Id */ - id?: string; - - /** 分类 */ - category?: string; - - /** 资源视图 */ - viewName?: string; - - /** 资源 icon */ - icon?: ReactElement; - - /** 资源其他配置,资源初始化时的第二个参数 */ - options: { - [key: string]: any; - }; - - /** 资源子元素 */ - children?: IPublicResourceData[]; -} - -export type IPublicResourceList = IPublicResourceData[]; diff --git a/packages/types/src/shell/type/resource-type-config.ts b/packages/types/src/shell/type/resource-type-config.ts deleted file mode 100644 index 400502617..000000000 --- a/packages/types/src/shell/type/resource-type-config.ts +++ /dev/null @@ -1,35 +0,0 @@ -import React from 'react'; -import { IPublicTypeEditorView } from './editor-view'; - -export interface IPublicResourceTypeConfig { - - /** 资源描述 */ - description?: string; - - /** 资源 icon 标识 */ - icon?: React.ReactElement | React.FunctionComponent | React.ComponentClass; - - /** 默认视图类型 */ - defaultViewName: string; - - /** 资源视图 */ - editorViews: IPublicTypeEditorView[]; - - init?: () => void; - - /** save 钩子 */ - save?: (schema: { - [viewName: string]: any; - }) => Promise; - - /** import 钩子 */ - import?: (schema: any) => Promise<{ - [viewName: string]: any; - }>; - - /** 默认标题 */ - defaultTitle?: string; - - /** resourceType 类型为 'webview' 时渲染的地址 */ - url?: () => Promise; -} diff --git a/packages/types/src/shell/type/resource-type.ts b/packages/types/src/shell/type/resource-type.ts deleted file mode 100644 index 05dc135b7..000000000 --- a/packages/types/src/shell/type/resource-type.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { IPublicModelPluginContext } from '../model'; -import { IPublicResourceTypeConfig } from './resource-type-config'; - -export interface IPublicTypeResourceType { - resourceName: string; - - resourceType: 'editor' | 'webview' | string; - - (ctx: IPublicModelPluginContext, options: Object): IPublicResourceTypeConfig; -} diff --git a/packages/types/src/shell/type/root-schema.ts b/packages/types/src/shell/type/root-schema.ts deleted file mode 100644 index 16f3bf94e..000000000 --- a/packages/types/src/shell/type/root-schema.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { IPublicTypePageSchema, IPublicTypeComponentSchema, IPublicTypeBlockSchema } from './'; - -/** - * @todo - */ -// eslint-disable-next-line max-len -export type IPublicTypeRootSchema = IPublicTypePageSchema | IPublicTypeComponentSchema | IPublicTypeBlockSchema; diff --git a/packages/types/src/shell/type/scrollable.ts b/packages/types/src/shell/type/scrollable.ts deleted file mode 100644 index b308637e0..000000000 --- a/packages/types/src/shell/type/scrollable.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { IPublicModelScrollTarget } from '../model'; - -export interface IPublicTypeScrollable { - scrollTarget?: IPublicModelScrollTarget | Element; - bounds?: DOMRect | null; - scale?: number; -} diff --git a/packages/types/src/shell/type/set-value-options.ts b/packages/types/src/shell/type/set-value-options.ts deleted file mode 100644 index 814f45845..000000000 --- a/packages/types/src/shell/type/set-value-options.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { IPublicEnumPropValueChangedType } from '../enum'; - -export interface IPublicTypeSetValueOptions { - disableMutator?: boolean; - type?: IPublicEnumPropValueChangedType; - fromSetHotValue?: boolean; -} diff --git a/packages/types/src/shell/type/setter-config.ts b/packages/types/src/shell/type/setter-config.ts deleted file mode 100644 index 7539e9c35..000000000 --- a/packages/types/src/shell/type/setter-config.ts +++ /dev/null @@ -1,59 +0,0 @@ -import { IPublicTypeCustomView, IPublicTypeCompositeValue, IPublicTypeTitleContent, IPublicModelSettingField } from '..'; -import { IPublicTypeDynamicProps } from './dynamic-props'; - -/** - * 设置器配置 - */ -export interface IPublicTypeSetterConfig { - - // if *string* passed must be a registered Setter Name - /** - * 配置设置器用哪一个 setter - */ - componentName: string | IPublicTypeCustomView; - - /** - * 传递给 setter 的属性 - * - * the props pass to Setter Component - */ - props?: Record | IPublicTypeDynamicProps; - - /** - * 是否必填? - * - * ArraySetter 里有个快捷预览,可以在不打开面板的情况下直接编辑 - */ - isRequired?: boolean; - - /** - * Setter 的初始值 - * - * @todo initialValue 可能要和 defaultValue 二选一 - */ - initialValue?: any | ((target: IPublicModelSettingField) => any); - - defaultValue?: any; - - // for MixedSetter - /** - * 给 MixedSetter 时切换 Setter 展示用的 - */ - title?: IPublicTypeTitleContent; - - // for MixedSetter check this is available - /** - * 给 MixedSetter 用于判断优先选中哪个 - */ - condition?: (target: IPublicModelSettingField) => boolean; - - /** - * 给 MixedSetter,切换值时声明类型 - * - * @todo 物料协议推进 - */ - valueType?: IPublicTypeCompositeValue[]; - - // 标识是否为动态 setter,默认为 true - isDynamic?: boolean; -} diff --git a/packages/types/src/shell/type/setter-type.ts b/packages/types/src/shell/type/setter-type.ts deleted file mode 100644 index cc8e853da..000000000 --- a/packages/types/src/shell/type/setter-type.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { IPublicTypeCustomView, IPublicTypeSetterConfig } from './'; - -// if *string* passed must be a registered Setter Name, future support blockSchema - -// eslint-disable-next-line max-len -export type IPublicTypeSetterType = - | IPublicTypeSetterConfig - | IPublicTypeSetterConfig[] - | string - | IPublicTypeCustomView; diff --git a/packages/types/src/shell/type/simulator-renderer.ts b/packages/types/src/shell/type/simulator-renderer.ts deleted file mode 100644 index 14aa16ab8..000000000 --- a/packages/types/src/shell/type/simulator-renderer.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { Asset } from '../../assets'; -import { - IPublicTypeNodeInstance, - IPublicTypeProjectSchema, - IPublicTypeComponentSchema, -} from './'; - -export interface IPublicTypeSimulatorRenderer { - readonly isSimulatorRenderer: true; - autoRepaintNode?: boolean; - components: Record; - rerender: () => void; - createComponent( - schema: IPublicTypeProjectSchema, - ): Component | null; - getComponent(componentName: string): Component; - getClosestNodeInstance( - from: ComponentInstance, - nodeId?: string, - ): IPublicTypeNodeInstance | null; - findDOMNodes(instance: ComponentInstance): Array | null; - getClientRects(element: Element | Text): DOMRect[]; - setNativeSelection(enableFlag: boolean): void; - setDraggingState(state: boolean): void; - setCopyState(state: boolean): void; - loadAsyncLibrary(asyncMap: { [index: string]: any }): void; - clearState(): void; - stopAutoRepaintNode(): void; - enableAutoRepaintNode(): void; - run(): void; - load(asset: Asset): Promise; -} diff --git a/packages/types/src/shell/type/slot-schema.ts b/packages/types/src/shell/type/slot-schema.ts deleted file mode 100644 index 8928a9824..000000000 --- a/packages/types/src/shell/type/slot-schema.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { IPublicTypeNodeData } from './node-data'; -import { IPublicTypeNodeSchema } from './node-schema'; - -/** - * Slot schema 描述 - */ -export interface IPublicTypeSlotSchema extends IPublicTypeNodeSchema { - componentName: 'Slot'; - name?: string; - title?: string; - params?: string[]; - props?: { - slotTitle?: string; - slotName?: string; - slotParams?: string[]; - }; - children?: IPublicTypeNodeData[] | IPublicTypeNodeData; -} diff --git a/packages/types/src/shell/type/snippet.ts b/packages/types/src/shell/type/snippet.ts deleted file mode 100644 index ac557c91e..000000000 --- a/packages/types/src/shell/type/snippet.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { IPublicTypeNodeSchema } from './'; - -/** - * 可用片段 - * - * 内容为组件不同状态下的低代码 schema (可以有多个),用户从组件面板拖入组件到设计器时会向页面 schema 中插入 snippets 中定义的组件低代码 schema - */ -export interface IPublicTypeSnippet { - /** - * 组件分类 title - */ - title?: string; - /** - * snippet 截图 - */ - screenshot?: string; - /** - * 待插入的 schema - */ - schema?: IPublicTypeNodeSchema; -} diff --git a/packages/types/src/shell/type/tip-config.ts b/packages/types/src/shell/type/tip-config.ts deleted file mode 100644 index f8b271c90..000000000 --- a/packages/types/src/shell/type/tip-config.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { IPublicTypeI18nData } from '..'; -import { ReactNode } from 'react'; - -export interface IPublicTypeTipConfig { - - /** - * className - */ - className?: string; - - /** - * tip 的内容 - */ - children?: IPublicTypeI18nData | ReactNode; - theme?: string; - - /** - * tip 的方向 - */ - direction?: 'top' | 'bottom' | 'left' | 'right'; -} diff --git a/packages/types/src/shell/type/tip-content.ts b/packages/types/src/shell/type/tip-content.ts deleted file mode 100644 index 340d404ab..000000000 --- a/packages/types/src/shell/type/tip-content.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { IPublicTypeI18nData } from '..'; -import { ReactNode } from 'react'; -import { IPublicTypeTipConfig } from './tip-config'; - -export type TipContent = string | IPublicTypeI18nData | ReactNode | IPublicTypeTipConfig; diff --git a/packages/types/src/shell/type/title-config.ts b/packages/types/src/shell/type/title-config.ts deleted file mode 100644 index f8de28759..000000000 --- a/packages/types/src/shell/type/title-config.ts +++ /dev/null @@ -1,53 +0,0 @@ -import { ReactNode } from 'react'; -import { IPublicTypeI18nData, IPublicTypeIconType, IPublicTypeTitleContent, TipContent } from './'; - -export interface IPublicTypeTitleProps { - - /** - * 标题内容 - */ - title: IPublicTypeTitleContent; - - /** - * className - */ - className?: string; - - /** - * 点击事件 - */ - onClick?: () => void; - match?: boolean; - keywords?: string; -} - -/** - * 描述 props 的 setter title - */ -export interface IPublicTypeTitleConfig { - - /** - * 文字描述 - */ - label?: IPublicTypeI18nData | ReactNode; - - /** - * hover 后的展现内容 - */ - tip?: TipContent; - - /** - * 文档链接,暂未实现 - */ - docUrl?: string; - - /** - * 图标 - */ - icon?: IPublicTypeIconType; - - /** - * CSS 类 - */ - className?: string; -} diff --git a/packages/types/src/shell/type/title-content.ts b/packages/types/src/shell/type/title-content.ts deleted file mode 100644 index 203cd61b4..000000000 --- a/packages/types/src/shell/type/title-content.ts +++ /dev/null @@ -1,10 +0,0 @@ -import type { ReactElement, ReactNode } from 'react'; -import type { IPublicTypeI18nData, IPublicTypeTitleConfig } from './'; - -// eslint-disable-next-line max-len -export type IPublicTypeTitleContent = - | string - | IPublicTypeI18nData - | ReactElement - | ReactNode - | IPublicTypeTitleConfig; diff --git a/packages/types/src/shell/type/transformed-component-metadata.ts b/packages/types/src/shell/type/transformed-component-metadata.ts deleted file mode 100644 index 6baa21c18..000000000 --- a/packages/types/src/shell/type/transformed-component-metadata.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { IPublicTypeComponentMetadata, IPublicTypeFieldConfig, IPublicTypeConfigure } from './'; - -/** - * @todo 待补充文档 - */ -export interface IPublicTypeTransformedComponentMetadata extends IPublicTypeComponentMetadata { - configure: IPublicTypeConfigure & { combined?: IPublicTypeFieldConfig[] }; -} diff --git a/packages/types/src/shell/type/value-type.ts b/packages/types/src/shell/type/value-type.ts deleted file mode 100644 index d1bbee354..000000000 --- a/packages/types/src/shell/type/value-type.ts +++ /dev/null @@ -1,126 +0,0 @@ -import { IPublicTypeNodeData, IPublicTypeCompositeValue, IPublicTypeNodeSchema } from './'; - -/** - * 变量表达式 - * - * 表达式内通过 this 对象获取上下文 - */ -export interface IPublicTypeJSExpression { - type: 'JSExpression'; - - /** - * 表达式字符串 - */ - value: string; - - /** - * 模拟值 - * - * @todo 待标准描述 - */ - mock?: any; - - /** - * 源码 - * - * @todo 待标准描述 - */ - compiled?: string; -} - -/** - * 事件函数类型 - * @see https://lowcode-engine.cn/lowcode - * - * 保留与原组件属性、生命周期 ( React / 小程序) 一致的输入参数,并给所有事件函数 binding 统一一致的上下文(当前组件所在容器结构的 this 对象) - */ -export interface IPublicTypeJSFunction { - type: 'JSFunction'; - - /** - * 函数定义,或直接函数表达式 - */ - value: string; - - /** - * 源码 - * - * @todo 待标准描述 - */ - compiled?: string; - - /** - * 模拟值 - * - * @todo 待标准描述 - */ - mock?: any; - - /** - * 额外扩展属性,如 extType、events - * - * @todo 待标准描述 - */ - [key: string]: any; -} - -/** - * Slot 函数类型 - * - * 通常用于描述组件的某一个属性为 ReactNode 或 Function return ReactNode 的场景。 - */ -export interface IPublicTypeJSSlot { - - /** - * type - */ - type: 'JSSlot'; - - /** - * @todo 待标准描述 - */ - title?: string; - - /** - * @todo 待标准描述 - */ - id?: string; - - /** - * 组件的某一个属性为 Function return ReactNode 时,函数的入参 - * - * 其子节点可以通过 this[参数名] 来获取对应的参数。 - */ - params?: string[]; - - /** - * 具体的值。 - */ - value?: IPublicTypeNodeData[] | IPublicTypeNodeData; - - /** - * @todo 待标准描述 - */ - name?: string; -} - -/** - * JSON 基本类型 - */ -export type IPublicTypeJSONValue = - | boolean - | string - | number - | null - | undefined - | IPublicTypeJSONArray - | IPublicTypeJSONObject; -export type IPublicTypeJSONArray = IPublicTypeJSONValue[]; -export interface IPublicTypeJSONObject { - [key: string]: IPublicTypeJSONValue; -} - -export type IPublicTypeCompositeArray = IPublicTypeCompositeValue[]; -export interface IPublicTypeCompositeObject { - [key: string]: IPublicTypeCompositeValue | T; -} diff --git a/packages/types/src/shell/type/widget-base-config.ts b/packages/types/src/shell/type/widget-base-config.ts deleted file mode 100644 index daa6e8d89..000000000 --- a/packages/types/src/shell/type/widget-base-config.ts +++ /dev/null @@ -1,110 +0,0 @@ -import type { ReactElement, ComponentType } from 'react'; -import type { - IPublicTypeI18nData, - IPublicTypeIconType, - IPublicTypeTitleContent, - IPublicTypeWidgetConfigArea, - TipContent, -} from './'; - -export type IPublicTypeHelpTipConfig = string | { url?: string; content?: string | ReactElement }; - -export interface IPublicTypePanelConfigProps extends IPublicTypePanelDockPanelProps { - title?: IPublicTypeTitleContent; - icon?: any; // 冗余字段 - description?: string | IPublicTypeI18nData; - help?: IPublicTypeHelpTipConfig; // 显示问号帮助 - hiddenWhenInit?: boolean; // when this is true, by default will be hidden - condition?: (widget: any) => any; - onInit?: (widget: any) => any; - onDestroy?: () => any; - shortcut?: string; // 只有在特定位置,可触发 toggle show - enableDrag?: boolean; // 是否开启通过 drag 调整 宽度 - keepVisibleWhileDragging?: boolean; // 是否在该 panel 范围内拖拽时保持 visible 状态 -} - -export interface IPublicTypePanelConfig extends IPublicTypeWidgetBaseConfig { - type: 'Panel'; - content?: string | ReactElement | ComponentType | IPublicTypePanelConfig[]; // as children - props?: IPublicTypePanelConfigProps; -} - -export interface IPublicTypeWidgetBaseConfig { - [extra: string]: any; - type: string; - name: string; - - /** - * 停靠位置: - * - 当 type 为 'Panel' 时自动为 'leftFloatArea'; - * - 当 type 为 'Widget' 时自动为 'mainArea'; - * - 其他时候自动为 'leftArea'; - */ - area?: IPublicTypeWidgetConfigArea; - props?: Record; - content?: - | string - | ReactElement - | ComponentType - | IPublicTypePanelConfig[] - | IPublicTypePanelConfig; - contentProps?: Record; - - /** - * 优先级,值越小,优先级越高,优先级高的会排在前面 - */ - index?: number; -} - -export interface IPublicTypePanelDockConfig extends IPublicTypeWidgetBaseConfig { - type: 'PanelDock'; - - panelProps?: IPublicTypePanelDockPanelProps; - - props?: IPublicTypePanelDockProps; - - /** 面板 name, 当没有 props.title 时, 会使用 name 作为标题 */ - name: string; -} - -export interface IPublicTypePanelDockProps { - [key: string]: any; - - size?: 'small' | 'medium' | 'large'; - - className?: string; - - /** 详细描述,hover 时在标题上方显示的 tips 内容 */ - description?: TipContent; - - onClick?: () => void; - - /** - * 面板标题前的 icon - */ - icon?: IPublicTypeIconType; - - /** - * 面板标题 - */ - title?: IPublicTypeTitleContent; -} - -export interface IPublicTypePanelDockPanelProps { - [key: string]: any; - - /** 是否隐藏面板顶部条 */ - hideTitleBar?: boolean; - - width?: number; - - height?: number; - - maxWidth?: number; - - maxHeight?: number; - - area?: IPublicTypeWidgetConfigArea; -} - -export type IPublicTypeSkeletonConfig = IPublicTypePanelDockConfig | IPublicTypeWidgetBaseConfig; diff --git a/packages/types/src/shell/type/widget-config-area.ts b/packages/types/src/shell/type/widget-config-area.ts deleted file mode 100644 index 41e71baa2..000000000 --- a/packages/types/src/shell/type/widget-config-area.ts +++ /dev/null @@ -1,9 +0,0 @@ -/** - * 所有可能的停靠位置 - */ -export type IPublicTypeWidgetConfigArea = 'leftArea' | 'left' | 'rightArea' | - 'right' | 'topArea' | 'subTopArea' | 'top' | - 'toolbar' | 'mainArea' | 'main' | - 'center' | 'centerArea' | 'bottomArea' | - 'bottom' | 'leftFixedArea' | - 'leftFloatArea' | 'stages'; diff --git a/packages/types/src/utils.ts b/packages/types/src/utils.ts deleted file mode 100644 index 2914597a7..000000000 --- a/packages/types/src/utils.ts +++ /dev/null @@ -1,34 +0,0 @@ - -type FilterOptional = Pick< - T, - Exclude< - { - [K in keyof T]: T extends Record ? K : never; - }[keyof T], - undefined - > ->; - -type FilterNotOptional = Pick< - T, - Exclude< - { - [K in keyof T]: T extends Record ? never : K; - }[keyof T], - undefined - > ->; - -type PartialEither = { [P in Exclude, K>]-?: T[P] } & - { [P in Exclude, K>]?: T[P] } & - { [P in Extract]?: undefined }; - -type Object = { - [name: string]: any; -}; - -export type EitherOr = - ( - PartialEither, L> | - PartialEither, R> - ) & Omit; diff --git a/packages/types/tsconfig.declaration.json b/packages/types/tsconfig.declaration.json deleted file mode 100644 index bccb9a3e5..000000000 --- a/packages/types/tsconfig.declaration.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "emitDeclarationOnly": true, - "declaration": true, - "outDir": "temp", - "stripInternal": true - } -} diff --git a/packages/types/vite.config.ts b/packages/types/vite.config.ts deleted file mode 100644 index ad9c0cf99..000000000 --- a/packages/types/vite.config.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { defineConfig } from 'vite'; -import baseConfigFn from '../../vite.base.config' - -export default defineConfig(async () => baseConfigFn({ - name: 'LowCodeTypes', -})); diff --git a/packages/utils/package.json b/packages/utils/package.json deleted file mode 100644 index fc4dac6f5..000000000 --- a/packages/utils/package.json +++ /dev/null @@ -1,67 +0,0 @@ -{ - "name": "@alilc/lowcode-utils", - "version": "2.0.0-beta.0", - "description": "Utils for Ali lowCode engine", - "type": "module", - "main": "lib/low-code-utils.js", - "module": "dist/low-code-utils.js", - "types": "dist/index.d.ts", - "exports": { - ".": { - "import": "./dist/low-code-utils.js", - "types": "./dist/index.d.ts" - }, - "./dist/style.css": { - "import": "./dist/style.css", - "require": "./dist/style.css" - }, - "./package.json": "./package.json" - }, - "sideEffects": [ - "*.css" - ], - "files": [ - "dist", - "src", - "package.json" - ], - "scripts": { - "build:target": "vite build", - "build:dts": "tsc -p tsconfig.declaration.json && node ../../scripts/rollup-dts.mjs", - "test": "vitest" - }, - "dependencies": { - "@alifd/next": "^1.27.8", - "@alilc/lowcode-types": "workspace:*", - "classnames": "^2.5.1", - "lodash-es": "^4.17.21", - "mobx": "^6.12.1", - "prop-types": "^15.8.1", - "react": "^18.2.0", - "react-is": "^18.2.0", - "events": "^3.3.0" - }, - "devDependencies": { - "@testing-library/react": "^14.2.2", - "@types/lodash-es": "^4.17.12", - "@types/react": "^18.2.67", - "@types/react-is": "^18.2.4", - "@types/prop-types": "^15.7.12", - "@types/events": "^3.0.3" - }, - "peerDependencies": { - "@alifd/next": "^1.27.8", - "react": "^18.2.0" - }, - "publishConfig": { - "access": "public", - "registry": "https://registry.npmjs.org/" - }, - "repository": { - "type": "http", - "url": "https://github.com/alibaba/lowcode-engine/tree/main/packages/utils" - }, - "gitHead": "2669f179e6f899d395ce1942d0fe04f9c5ed48a6", - "bugs": "https://github.com/alibaba/lowcode-engine/issues", - "homepage": "https://github.com/alibaba/lowcode-engine/#readme" -} diff --git a/packages/utils/src/app-helper.ts b/packages/utils/src/app-helper.ts deleted file mode 100644 index 97caaa890..000000000 --- a/packages/utils/src/app-helper.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { EventEmitter } from 'events'; - -let instance: AppHelper | null = null; - -EventEmitter.defaultMaxListeners = 100; - -export class AppHelper extends EventEmitter { - static getInstance = () => { - if (!instance) { - instance = new AppHelper(); - } - return instance; - }; - - [key: string]: any; - - constructor(config?: Record) { - super(); - instance = this; - Object.assign(this, config); - } - - get(key: string) { - return this[key]; - } - - set(key: any, val: any) { - if (typeof key === 'string') { - this[key] = val; - } else if (typeof key === 'object') { - Object.keys(key).forEach((item) => { - this[item] = key[item]; - }); - } - } - - batchOn(events: Array, listener: (...args: any[]) => void) { - if (!Array.isArray(events)) return; - events.forEach((event) => this.on(event, listener)); - } - - batchOnce(events: Array, listener: (...args: any[]) => void) { - if (!Array.isArray(events)) return; - events.forEach((event) => this.once(event, listener)); - } - - batchOff(events: Array, listener: (...args: any[]) => void) { - if (!Array.isArray(events)) return; - events.forEach((event) => this.off(event, listener)); - } -} diff --git a/packages/utils/src/asset.ts b/packages/utils/src/asset.ts deleted file mode 100644 index 261e2171e..000000000 --- a/packages/utils/src/asset.ts +++ /dev/null @@ -1,342 +0,0 @@ -import { AssetType, AssetLevels, AssetLevel } from '@alilc/lowcode-types'; -import type { - AssetItem, - Asset, - AssetList, - AssetBundle, - IPublicTypeAssetsJson, -} from '@alilc/lowcode-types'; -import { isCSSUrl } from './is-css-url'; -import { createDefer } from './create-defer'; -import { load, evaluate } from './script'; - -// API 向下兼容 -export { AssetType, AssetLevels, AssetLevel } from '@alilc/lowcode-types'; -export type { - AssetItem, - Asset, - AssetList, - AssetBundle, - IPublicTypeAssetsJson, -} from '@alilc/lowcode-types'; - -export function isAssetItem(obj: any): obj is AssetItem { - return obj && obj.type; -} - -export function isAssetBundle(obj: any): obj is AssetBundle { - return obj && obj.type === AssetType.Bundle; -} - -export function assetBundle( - assets?: Asset | AssetList | null, - level?: AssetLevel, -): AssetBundle | null { - if (!assets) { - return null; - } - return { - type: AssetType.Bundle, - assets, - level, - }; -} - -/* -urls: "view.js,view2 , view3 ", -urls: [ - "view.js", - "view.js *", - "view1.js mobile|pc", - "view2.js " -] */ -export function assetItem( - type: AssetType, - content?: string | null, - level?: AssetLevel, - id?: string, -): AssetItem | null { - if (!content) { - return null; - } - return { - type, - content, - level, - id, - }; -} - -export function mergeAssets( - assets: IPublicTypeAssetsJson, - incrementalAssets: IPublicTypeAssetsJson, -): IPublicTypeAssetsJson { - if (incrementalAssets.packages) { - assets.packages = [...(assets.packages || []), ...incrementalAssets.packages]; - } - - if (incrementalAssets.components) { - assets.components = [...(assets.components || []), ...incrementalAssets.components]; - } - - mergeAssetsComponentList(assets, incrementalAssets, 'componentList'); - mergeAssetsComponentList(assets, incrementalAssets, 'bizComponentList'); - - return assets; -} - -function mergeAssetsComponentList( - assets: IPublicTypeAssetsJson, - incrementalAssets: IPublicTypeAssetsJson, - listName: keyof Omit, -): void { - if (incrementalAssets[listName]) { - if (assets[listName]) { - // 根据title进行合并 - incrementalAssets[listName]?.map((item) => { - let matchFlag = false; - assets[listName]?.map((assetItem) => { - if (assetItem.title === item.title) { - assetItem.children = assetItem.children.concat(item.children); - matchFlag = true; - } - - return assetItem; - }); - - !matchFlag && assets[listName]?.push(item); - return item; - }); - } - } -} - -export class StylePoint { - private lastContent: string | undefined; - - private lastUrl: string | undefined; - - private placeholder: Element | Text; - - readonly level: number; - - readonly id: string; - - constructor(level: number, id?: string) { - this.level = level; - if (id) { - this.id = id; - } - let placeholder: any; - if (id) { - placeholder = document.head.querySelector(`style[data-id="${id}"]`); - } - if (!placeholder) { - placeholder = document.createTextNode(''); - const meta = document.head.querySelector(`meta[level="${level}"]`); - if (meta) { - document.head.insertBefore(placeholder, meta); - } else { - document.head.appendChild(placeholder); - } - } - this.placeholder = placeholder; - } - - applyText(content: string) { - if (this.lastContent === content) { - return; - } - this.lastContent = content; - this.lastUrl = undefined; - const element = document.createElement('style'); - element.setAttribute('type', 'text/css'); - if (this.id) { - element.setAttribute('data-id', this.id); - } - element.appendChild(document.createTextNode(content)); - document.head.insertBefore( - element, - this.placeholder.parentNode === document.head ? this.placeholder.nextSibling : null, - ); - document.head.removeChild(this.placeholder); - this.placeholder = element; - } - - applyUrl(url: string) { - if (this.lastUrl === url) { - return; - } - this.lastContent = undefined; - this.lastUrl = url; - const element = document.createElement('link'); - element.onload = onload; - element.onerror = onload; - - const i = createDefer(); - function onload(e: any) { - element.onload = null; - element.onerror = null; - if (e.type === 'load') { - i.resolve(); - } else { - i.reject(); - } - } - - element.href = url; - element.rel = 'stylesheet'; - if (this.id) { - element.setAttribute('data-id', this.id); - } - document.head.insertBefore( - element, - this.placeholder.parentNode === document.head ? this.placeholder.nextSibling : null, - ); - document.head.removeChild(this.placeholder); - this.placeholder = element; - return i.promise(); - } -} - -function parseAssetList(scripts: any, styles: any, assets: AssetList, level?: AssetLevel) { - for (const asset of assets) { - parseAsset(scripts, styles, asset, level); - } -} - -function parseAsset( - scripts: any, - styles: any, - asset: Asset | undefined | null, - level?: AssetLevel, -) { - if (!asset) { - return; - } - if (Array.isArray(asset)) { - return parseAssetList(scripts, styles, asset, level); - } - - if (isAssetBundle(asset)) { - if (asset.assets) { - if (Array.isArray(asset.assets)) { - parseAssetList(scripts, styles, asset.assets, asset.level || level); - } else { - parseAsset(scripts, styles, asset.assets, asset.level || level); - } - return; - } - return; - } - - if (!isAssetItem(asset)) { - asset = assetItem(isCSSUrl(asset) ? AssetType.CSSUrl : AssetType.JSUrl, asset, level)!; - } - - let lv = asset.level || level; - - if (!lv || AssetLevel[lv] == null) { - lv = AssetLevel.App; - } - - asset.level = lv; - if (asset.type === AssetType.CSSUrl || asset.type == AssetType.CSSText) { - styles[lv].push(asset); - } else { - scripts[lv].push(asset); - } -} - -export class AssetLoader { - private stylePoints = new Map(); - - async load(asset: Asset) { - const styles: any = {}; - const scripts: any = {}; - AssetLevels.forEach((lv) => { - styles[lv] = []; - scripts[lv] = []; - }); - parseAsset(scripts, styles, asset); - const styleQueue: AssetItem[] = styles[AssetLevel.Environment].concat( - styles[AssetLevel.Library], - styles[AssetLevel.Theme], - styles[AssetLevel.Runtime], - styles[AssetLevel.App], - ); - const scriptQueue: AssetItem[] = scripts[AssetLevel.Environment].concat( - scripts[AssetLevel.Library], - scripts[AssetLevel.Theme], - scripts[AssetLevel.Runtime], - scripts[AssetLevel.App], - ); - await Promise.all( - styleQueue.map(({ content, level, type, id }) => - this.loadStyle(content, level!, type === AssetType.CSSUrl, id), - ), - ); - await Promise.all( - scriptQueue.map(({ content, type, scriptType }) => - this.loadScript(content, type === AssetType.JSUrl, scriptType), - ), - ); - } - - private loadStyle( - content: string | undefined | null, - level: AssetLevel, - isUrl?: boolean, - id?: string, - ) { - if (!content) { - return; - } - let point: StylePoint | undefined; - if (id) { - point = this.stylePoints.get(id); - if (!point) { - point = new StylePoint(level, id); - this.stylePoints.set(id, point); - } - } else { - point = new StylePoint(level); - } - return isUrl ? point.applyUrl(content) : point.applyText(content); - } - - private loadScript(content: string | undefined | null, isUrl?: boolean, scriptType?: string) { - if (!content) { - return; - } - return isUrl ? load(content, scriptType) : evaluate(content, scriptType); - } - - // todo 补充类型 - async loadAsyncLibrary(asyncLibraryMap: Record) { - const promiseList: any[] = []; - const libraryKeyList: any[] = []; - const pkgs: any[] = []; - for (const key in asyncLibraryMap) { - // 需要异步加载 - if (asyncLibraryMap[key].async) { - promiseList.push(window[asyncLibraryMap[key].library]); - libraryKeyList.push(asyncLibraryMap[key].library); - pkgs.push(asyncLibraryMap[key]); - } - } - await Promise.all(promiseList).then((mods) => { - if (mods.length > 0) { - mods.map((item, index) => { - const { exportMode, exportSourceLibrary, library } = pkgs[index]; - window[libraryKeyList[index]] = - exportMode === 'functionCall' && - (exportSourceLibrary == null || exportSourceLibrary === library) - ? item() - : item; - return item; - }); - } - }); - } -} diff --git a/packages/utils/src/build-components.ts b/packages/utils/src/build-components.ts deleted file mode 100644 index 8763592f4..000000000 --- a/packages/utils/src/build-components.ts +++ /dev/null @@ -1,186 +0,0 @@ -import { ComponentType, forwardRef, createElement, FunctionComponent } from 'react'; -import { - IPublicTypeNpmInfo, - IPublicTypeComponentSchema, - IPublicTypeProjectSchema, -} from '@alilc/lowcode-types'; -import { isESModule } from './is-es-module'; -import { isReactComponent, acceptsRef, wrapReactClass } from './is-react'; -import { isObject } from './is-object'; -import { isLowcodeProjectSchema } from './check-types'; -import { isComponentSchema } from './check-types/is-component-schema'; - -type Component = ComponentType | object; -interface LibraryMap { - [key: string]: string; -} - -export function accessLibrary(library: string | Record) { - if (typeof library !== 'string') { - return library; - } - - return (window as any)[library] || generateHtmlComp(library); -} - -export function generateHtmlComp(library: string): any { - if (['a', 'img', 'div', 'span', 'svg'].includes(library)) { - return forwardRef((props: any, ref) => { - return createElement(library, { ref, ...props }, props.children); - }); - } -} - -export function getSubComponent(library: any, paths: string[]) { - const l = paths.length; - if (l < 1 || !library) { - return library; - } - let i = 0; - let component: any; - while (i < l) { - const key = paths[i]!; - let ex: any; - try { - component = library[key] || component; - } catch (e) { - ex = e; - component = null; - } - if (i === 0 && component == null && key === 'default') { - if (ex) { - return l === 1 ? library : null; - } - component = library; - } else if (component == null) { - return null; - } - library = component; - i++; - } - return component; -} - -function findComponent(libraryMap: LibraryMap, componentName: string, npm?: IPublicTypeNpmInfo) { - if (!npm) { - return accessLibrary(componentName); - } - // libraryName the key access to global - // export { exportName } from xxx exportName === global.libraryName.exportName - // export exportName from xxx exportName === global.libraryName.default || global.libraryName - // export { exportName as componentName } from package - // if exportName == null exportName === componentName; - // const componentName = exportName.subName, if exportName empty subName donot use - const exportName = npm.exportName || npm.componentName || componentName; - const libraryName = libraryMap[npm.package] || exportName; - const library = accessLibrary(libraryName); - const paths = npm.exportName && npm.subName ? npm.subName.split('.') : []; - if (npm.destructuring) { - paths.unshift(exportName); - } else if (isESModule(library)) { - paths.unshift('default'); - } - return getSubComponent(library, paths); -} - -/** - * 判断是否是一个混合组件,即 components 是一个对象,对象值是 React 组件 - * 示例: - * { - * Button: ReactNode, - * Text: ReactNode, - * } - */ -function isMixinComponent(components: any) { - if (!isObject(components)) { - return false; - } - - return Object.keys(components).some((componentName) => - isReactComponent(components[componentName]), - ); -} - -export function buildComponents( - libraryMap: LibraryMap, - componentsMap: { - [componentName: string]: IPublicTypeNpmInfo | ComponentType | IPublicTypeComponentSchema; - }, - createComponent: ( - schema: IPublicTypeProjectSchema, - ) => Component | null, -) { - const components: any = {}; - Object.keys(componentsMap).forEach((componentName) => { - let component = componentsMap[componentName]; - if (component && (isLowcodeProjectSchema(component) || isComponentSchema(component))) { - if (isComponentSchema(component)) { - components[componentName] = createComponent({ - version: '', - componentsMap: [], - componentsTree: [component], - }); - } else { - components[componentName] = createComponent(component); - } - } else if (isReactComponent(component)) { - if (!acceptsRef(component)) { - component = wrapReactClass(component as FunctionComponent); - } - components[componentName] = component; - } else if (isMixinComponent(component)) { - components[componentName] = component; - } else { - component = findComponent(libraryMap, componentName, component); - if (component) { - if (!acceptsRef(component) && isReactComponent(component)) { - component = wrapReactClass(component as FunctionComponent); - } - components[componentName] = component; - } - } - }); - return components; -} - -export interface UtilsMetadata { - name: string; - npm: { - package: string; - version?: string; - exportName: string; - subName?: string; - destructuring?: boolean; - main?: string; - }; -} - -interface LibrayMap { - [key: string]: string; -} - -interface ProjectUtils { - [packageName: string]: any; -} -export function getProjectUtils( - librayMap: LibrayMap, - utilsMetadata: UtilsMetadata[], -): ProjectUtils { - const projectUtils: ProjectUtils = {}; - if (utilsMetadata) { - utilsMetadata.forEach((meta) => { - if (librayMap[meta?.npm?.package]) { - const lib = accessLibrary(librayMap[meta?.npm.package]); - if (lib?.destructuring) { - Object.keys(lib).forEach((name) => { - if (name === 'destructuring') return; - projectUtils[name] = lib[name]; - }); - } else if (meta.name) { - projectUtils[meta.name] = lib; - } - } - }); - } - return projectUtils; -} diff --git a/packages/utils/src/check-prop-types.ts b/packages/utils/src/check-prop-types.ts deleted file mode 100644 index 463a89238..000000000 --- a/packages/utils/src/check-prop-types.ts +++ /dev/null @@ -1,83 +0,0 @@ -import * as ReactIs from 'react-is'; -// @ts-expect-error -import { default as ReactPropTypesSecret } from 'prop-types/lib/ReactPropTypesSecret'; -// @ts-expect-error -import { default as factoryWithTypeCheckers } from 'prop-types/factoryWithTypeCheckers'; -import { IPublicTypePropType } from '@alilc/lowcode-types'; -import { isRequiredPropType } from './check-types/is-required-prop-type'; -import { Logger } from '../../shared/src/helper/logger'; - -const PropTypes2 = factoryWithTypeCheckers(ReactIs.isElement, true); -const logger = new Logger({ level: 'warn', bizName: 'utils' }); - -export function transformPropTypesRuleToString(rule: IPublicTypePropType | string): string { - if (!rule) { - return 'PropTypes.any'; - } - - if (typeof rule === 'string') { - return rule.startsWith('PropTypes.') ? rule : `PropTypes.${rule}`; - } - - if (isRequiredPropType(rule)) { - const { type, isRequired } = rule; - return `PropTypes.${type}${isRequired ? '.isRequired' : ''}`; - } - - const { type, value } = rule; - switch (type) { - case 'oneOf': - return `PropTypes.oneOf([${value.map((item: any) => `"${item}"`).join(',')}])`; - case 'oneOfType': - return `PropTypes.oneOfType([${value.map((item: any) => transformPropTypesRuleToString(item)).join(', ')}])`; - case 'arrayOf': - case 'objectOf': - return `PropTypes.${type}(${transformPropTypesRuleToString(value)})`; - case 'shape': - case 'exact': - return `PropTypes.${type}({${value.map((item: any) => `${item.name}: ${transformPropTypesRuleToString(item.propType)}`).join(',')}})`; - default: - logger.error(`Unknown prop type: ${type}`); - } - - return 'PropTypes.any'; -} - -export function checkPropTypes( - value: any, - name: string, - rule: any, - componentName: string, -): boolean { - let ruleFunction = rule; - if (typeof rule === 'object') { - // eslint-disable-next-line no-new-func - ruleFunction = new Function( - `"use strict"; const PropTypes = arguments[0]; return ${transformPropTypesRuleToString(rule)}`, - )(PropTypes2); - } - if (typeof rule === 'string') { - // eslint-disable-next-line no-new-func - ruleFunction = new Function( - `"use strict"; const PropTypes = arguments[0]; return ${transformPropTypesRuleToString(rule)}`, - )(PropTypes2); - } - if (!ruleFunction || typeof ruleFunction !== 'function') { - logger.warn('checkPropTypes should have a function type rule argument'); - return true; - } - const err = ruleFunction( - { - [name]: value, - }, - name, - componentName, - 'prop', - null, - ReactPropTypesSecret, - ); - if (err) { - logger.warn(err); - } - return !err; -} diff --git a/packages/utils/src/check-types/index.ts b/packages/utils/src/check-types/index.ts deleted file mode 100644 index 8db11580d..000000000 --- a/packages/utils/src/check-types/index.ts +++ /dev/null @@ -1,28 +0,0 @@ -// 此模块存放 @alilc/lowcode-types 中类型相关判断工具 -export * from './is-action-content-object'; -export * from './is-custom-view'; -export * from './is-dom-text'; -export * from './is-dynamic-setter'; -export * from './is-i18n-data'; -export * from './is-jsblock'; -export * from './is-jsexpression'; -export * from './is-isfunction'; -export * from './is-jsslot'; -export * from './is-lowcode-component-type'; -export * from './is-node-schema'; -export * from './is-procode-component-type'; -export * from './is-project-schema'; -export * from './is-setter-config'; -export * from './is-title-config'; -export * from './is-drag-node-data-object'; -export * from './is-drag-node-object'; -export * from './is-drag-any-object'; -export * from './is-location-children-detail'; -export * from './is-node'; -export * from './is-location-data'; -export * from './is-setting-field'; -export * from './is-lowcode-component-type'; -export * from './is-lowcode-project-schema'; -export * from './is-component-schema'; -export * from './is-basic-prop-type'; -export * from './is-required-prop-type'; diff --git a/packages/utils/src/check-types/is-action-content-object.ts b/packages/utils/src/check-types/is-action-content-object.ts deleted file mode 100644 index 8fe31b5bd..000000000 --- a/packages/utils/src/check-types/is-action-content-object.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { IPublicTypeActionContentObject } from '@alilc/lowcode-types'; -import { isObject } from '../is-object'; - -export function isActionContentObject(obj: any): obj is IPublicTypeActionContentObject { - return isObject(obj); -} diff --git a/packages/utils/src/check-types/is-basic-prop-type.ts b/packages/utils/src/check-types/is-basic-prop-type.ts deleted file mode 100644 index 5b069fe7f..000000000 --- a/packages/utils/src/check-types/is-basic-prop-type.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { IPublicTypeBasicType, IPublicTypePropType } from '@alilc/lowcode-types'; - -export function isBasicPropType(propType: IPublicTypePropType): propType is IPublicTypeBasicType { - if (!propType) { - return false; - } - return typeof propType === 'string'; -} diff --git a/packages/utils/src/check-types/is-component-schema.ts b/packages/utils/src/check-types/is-component-schema.ts deleted file mode 100644 index fc20c2b8d..000000000 --- a/packages/utils/src/check-types/is-component-schema.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { IPublicTypeComponentSchema } from '@alilc/lowcode-types'; - -export function isComponentSchema(schema: any): schema is IPublicTypeComponentSchema { - if (typeof schema === 'object') { - return schema.componentName === 'Component'; - } - return false; -} diff --git a/packages/utils/src/check-types/is-custom-view.ts b/packages/utils/src/check-types/is-custom-view.ts deleted file mode 100644 index aa7633386..000000000 --- a/packages/utils/src/check-types/is-custom-view.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { isValidElement } from 'react'; -import { IPublicTypeCustomView } from '@alilc/lowcode-types'; -import { isReactComponent } from '../is-react'; - -export function isCustomView(obj: any): obj is IPublicTypeCustomView { - if (!obj) { - return false; - } - return isValidElement(obj) || isReactComponent(obj); -} diff --git a/packages/utils/src/check-types/is-dom-text.ts b/packages/utils/src/check-types/is-dom-text.ts deleted file mode 100644 index 950954440..000000000 --- a/packages/utils/src/check-types/is-dom-text.ts +++ /dev/null @@ -1,3 +0,0 @@ -export function isDOMText(data: any): data is string { - return typeof data === 'string'; -} diff --git a/packages/utils/src/check-types/is-drag-any-object.ts b/packages/utils/src/check-types/is-drag-any-object.ts deleted file mode 100644 index 8186b6a97..000000000 --- a/packages/utils/src/check-types/is-drag-any-object.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { IPublicEnumDragObjectType } from '@alilc/lowcode-types'; -import { isObject } from '../is-object'; - -export function isDragAnyObject(obj: any): boolean { - if (!isObject(obj)) { - return false; - } - return obj.type !== IPublicEnumDragObjectType.NodeData && obj.type !== IPublicEnumDragObjectType.Node; -} diff --git a/packages/utils/src/check-types/is-drag-node-data-object.ts b/packages/utils/src/check-types/is-drag-node-data-object.ts deleted file mode 100644 index f427505e8..000000000 --- a/packages/utils/src/check-types/is-drag-node-data-object.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { IPublicEnumDragObjectType, IPublicTypeDragNodeDataObject } from '@alilc/lowcode-types'; -import { isObject } from '../is-object'; - -export function isDragNodeDataObject(obj: any): obj is IPublicTypeDragNodeDataObject { - if (!isObject(obj)) { - return false; - } - return obj.type === IPublicEnumDragObjectType.NodeData; -} diff --git a/packages/utils/src/check-types/is-drag-node-object.ts b/packages/utils/src/check-types/is-drag-node-object.ts deleted file mode 100644 index 28350f123..000000000 --- a/packages/utils/src/check-types/is-drag-node-object.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { IPublicEnumDragObjectType, IPublicModelNode, IPublicTypeDragNodeObject } from '@alilc/lowcode-types'; -import { isObject } from '../is-object'; - -export function isDragNodeObject(obj: any): obj is IPublicTypeDragNodeObject { - if (!isObject(obj)) { - return false; - } - return obj.type === IPublicEnumDragObjectType.Node; -} diff --git a/packages/utils/src/check-types/is-dynamic-setter.ts b/packages/utils/src/check-types/is-dynamic-setter.ts deleted file mode 100644 index 35f8ff389..000000000 --- a/packages/utils/src/check-types/is-dynamic-setter.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { isFunction } from '../is-function'; -import { isReactClass } from '../is-react'; -import { IPublicTypeDynamicSetter } from '@alilc/lowcode-types'; - -export function isDynamicSetter(obj: any): obj is IPublicTypeDynamicSetter { - if (!isFunction(obj)) { - return false; - } - return !isReactClass(obj); -} diff --git a/packages/utils/src/check-types/is-function.ts b/packages/utils/src/check-types/is-function.ts deleted file mode 100644 index 3f6f9a06b..000000000 --- a/packages/utils/src/check-types/is-function.ts +++ /dev/null @@ -1,3 +0,0 @@ -export function isFunction(obj: any): obj is Function { - return obj && typeof obj === 'function'; -} diff --git a/packages/utils/src/check-types/is-i18n-data.ts b/packages/utils/src/check-types/is-i18n-data.ts deleted file mode 100644 index 793295d24..000000000 --- a/packages/utils/src/check-types/is-i18n-data.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { IPublicTypeI18nData } from '@alilc/lowcode-types'; -import { isObject } from '../is-object'; - -export function isI18nData(obj: any): obj is IPublicTypeI18nData { - if (!isObject(obj)) { - return false; - } - return obj.type === 'i18n'; -} diff --git a/packages/utils/src/check-types/is-isfunction.ts b/packages/utils/src/check-types/is-isfunction.ts deleted file mode 100644 index 64b867663..000000000 --- a/packages/utils/src/check-types/is-isfunction.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { IPublicTypeJSFunction } from '@alilc/lowcode-types'; -import { isObject } from '../is-object'; - -interface InnerJsFunction { - type: 'JSExpression'; - source: string; - value: string; - extType: 'function'; -} - -/** - * 内部版本 的 { type: 'JSExpression', source: '', value: '', extType: 'function' } 能力上等同于 JSFunction - */ -export function isInnerJsFunction(data: any): data is InnerJsFunction { - if (!isObject(data)) { - return false; - } - return data.type === 'JSExpression' && data.extType === 'function'; -} - -export function isJSFunction(data: any): data is IPublicTypeJSFunction { - if (!isObject(data)) { - return false; - } - return data.type === 'JSFunction' || isInnerJsFunction(data); -} diff --git a/packages/utils/src/check-types/is-jsblock.ts b/packages/utils/src/check-types/is-jsblock.ts deleted file mode 100644 index 858f5c09c..000000000 --- a/packages/utils/src/check-types/is-jsblock.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { IPublicTypeJSBlock } from '@alilc/lowcode-types'; -import { isObject } from '../is-object'; - -export function isJSBlock(data: any): data is IPublicTypeJSBlock { - if (!isObject(data)) { - return false; - } - return data.type === 'JSBlock'; -} diff --git a/packages/utils/src/check-types/is-jsexpression.ts b/packages/utils/src/check-types/is-jsexpression.ts deleted file mode 100644 index 16b8f4ac2..000000000 --- a/packages/utils/src/check-types/is-jsexpression.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { IPublicTypeJSExpression } from '@alilc/lowcode-types'; -import { isObject } from '../is-object'; - -/** - * 为了避免把 { type: 'JSExpression', extType: 'function' } 误判为表达式,故增加如下逻辑。 - * - * 引擎中关于函数的表达: - * 开源版本:{ type: 'JSFunction', source: '', value: '' } - * 内部版本:{ type: 'JSExpression', source: '', value: '', extType: 'function' } - * 能力是对标的,不过开源的 react-renderer 只认识第一种,而内部只识别第二种(包括 Java 代码、RE)。 - * @param data - * @returns - */ -export function isJSExpression(data: any): data is IPublicTypeJSExpression { - if (!isObject(data)) { - return false; - } - return data.type === 'JSExpression' && data.extType !== 'function'; -} diff --git a/packages/utils/src/check-types/is-jsslot.ts b/packages/utils/src/check-types/is-jsslot.ts deleted file mode 100644 index 1fb1d819d..000000000 --- a/packages/utils/src/check-types/is-jsslot.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { IPublicTypeJSSlot } from '@alilc/lowcode-types'; -import { isObject } from '../is-object'; - -export function isJSSlot(data: any): data is IPublicTypeJSSlot { - if (!isObject(data)) { - return false; - } - return data.type === 'JSSlot'; -} diff --git a/packages/utils/src/check-types/is-location-children-detail.ts b/packages/utils/src/check-types/is-location-children-detail.ts deleted file mode 100644 index a0b177988..000000000 --- a/packages/utils/src/check-types/is-location-children-detail.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { IPublicTypeLocationChildrenDetail, IPublicTypeLocationDetailType } from '@alilc/lowcode-types'; -import { isObject } from '../is-object'; - -export function isLocationChildrenDetail(obj: any): obj is IPublicTypeLocationChildrenDetail { - if (!isObject(obj)) { - return false; - } - return obj.type === IPublicTypeLocationDetailType.Children; -} diff --git a/packages/utils/src/check-types/is-location-data.ts b/packages/utils/src/check-types/is-location-data.ts deleted file mode 100644 index 000735abc..000000000 --- a/packages/utils/src/check-types/is-location-data.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { IPublicTypeLocationData } from '@alilc/lowcode-types'; -import { isObject } from '../is-object'; - -export function isLocationData(obj: any): obj is IPublicTypeLocationData { - if (!isObject(obj)) { - return false; - } - return 'target' in obj && 'detail' in obj; -} diff --git a/packages/utils/src/check-types/is-lowcode-component-type.ts b/packages/utils/src/check-types/is-lowcode-component-type.ts deleted file mode 100644 index ce19c23e8..000000000 --- a/packages/utils/src/check-types/is-lowcode-component-type.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { isProCodeComponentType } from './is-procode-component-type'; -import { IPublicTypeComponentMap, IPublicTypeLowCodeComponent } from '@alilc/lowcode-types'; - - -export function isLowCodeComponentType(desc: IPublicTypeComponentMap): desc is IPublicTypeLowCodeComponent { - return !isProCodeComponentType(desc); -} diff --git a/packages/utils/src/check-types/is-lowcode-project-schema.ts b/packages/utils/src/check-types/is-lowcode-project-schema.ts deleted file mode 100644 index 230911f0f..000000000 --- a/packages/utils/src/check-types/is-lowcode-project-schema.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { IPublicTypeComponentSchema, IPublicTypeProjectSchema } from '@alilc/lowcode-types'; -import { isComponentSchema } from './is-component-schema'; -import { isObject } from '../is-object'; - -export function isLowcodeProjectSchema(data: any): data is IPublicTypeProjectSchema { - if (!isObject(data)) { - return false; - } - - if (!('componentsTree' in data) || data.componentsTree.length === 0) { - return false; - } - - return isComponentSchema(data.componentsTree[0]); -} diff --git a/packages/utils/src/check-types/is-node-schema.ts b/packages/utils/src/check-types/is-node-schema.ts deleted file mode 100644 index 253c05a08..000000000 --- a/packages/utils/src/check-types/is-node-schema.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { IPublicTypeNodeSchema } from '@alilc/lowcode-types'; -import { isObject } from '../is-object'; - -export function isNodeSchema(data: any): data is IPublicTypeNodeSchema { - if (!isObject(data)) { - return false; - } - return 'componentName' in data && !data.isNode; -} diff --git a/packages/utils/src/check-types/is-node.ts b/packages/utils/src/check-types/is-node.ts deleted file mode 100644 index a12a1775a..000000000 --- a/packages/utils/src/check-types/is-node.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { IPublicModelNode } from '@alilc/lowcode-types'; -import { isObject } from '../is-object'; - -export function isNode(node: any): node is Node { - if (!isObject(node)) { - return false; - } - return node.isNode; -} diff --git a/packages/utils/src/check-types/is-object.ts b/packages/utils/src/check-types/is-object.ts deleted file mode 100644 index 54fb9b2ae..000000000 --- a/packages/utils/src/check-types/is-object.ts +++ /dev/null @@ -1,3 +0,0 @@ -export function isObject(obj: any): boolean { - return obj && typeof obj === 'object'; -} diff --git a/packages/utils/src/check-types/is-procode-component-type.ts b/packages/utils/src/check-types/is-procode-component-type.ts deleted file mode 100644 index 46618dcd5..000000000 --- a/packages/utils/src/check-types/is-procode-component-type.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { IPublicTypeComponentMap, IPublicTypeProCodeComponent } from '@alilc/lowcode-types'; -import { isObject } from '../is-object'; - -export function isProCodeComponentType(desc: IPublicTypeComponentMap): desc is IPublicTypeProCodeComponent { - if (!isObject(desc)) { - return false; - } - - return 'package' in desc; -} diff --git a/packages/utils/src/check-types/is-project-schema.ts b/packages/utils/src/check-types/is-project-schema.ts deleted file mode 100644 index d217acd9e..000000000 --- a/packages/utils/src/check-types/is-project-schema.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { IPublicTypeProjectSchema } from '@alilc/lowcode-types'; -import { isObject } from '../is-object'; - -export function isProjectSchema(data: any): data is IPublicTypeProjectSchema { - if (!isObject(data)) { - return false; - } - return 'componentsTree' in data; -} diff --git a/packages/utils/src/check-types/is-required-prop-type.ts b/packages/utils/src/check-types/is-required-prop-type.ts deleted file mode 100644 index b5fc10e76..000000000 --- a/packages/utils/src/check-types/is-required-prop-type.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { IPublicTypePropType, IPublicTypeRequiredType } from '@alilc/lowcode-types'; - -export function isRequiredPropType(propType: IPublicTypePropType): propType is IPublicTypeRequiredType { - if (!propType) { - return false; - } - return typeof propType === 'object' && propType.type && ['array', 'bool', 'func', 'number', 'object', 'string', 'node', 'element', 'any'].includes(propType.type); -} diff --git a/packages/utils/src/check-types/is-setter-config.ts b/packages/utils/src/check-types/is-setter-config.ts deleted file mode 100644 index 98d835f32..000000000 --- a/packages/utils/src/check-types/is-setter-config.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { IPublicTypeSetterConfig } from '@alilc/lowcode-types'; -import { isCustomView } from './is-custom-view'; -import { isObject } from '../is-object'; - -export function isSetterConfig(obj: any): obj is IPublicTypeSetterConfig { - if (!isObject(obj)) { - return false; - } - return 'componentName' in obj && !isCustomView(obj); -} diff --git a/packages/utils/src/check-types/is-setting-field.ts b/packages/utils/src/check-types/is-setting-field.ts deleted file mode 100644 index 0d6e21d84..000000000 --- a/packages/utils/src/check-types/is-setting-field.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { IPublicModelSettingField } from '@alilc/lowcode-types'; -import { isObject } from '../is-object'; - -export function isSettingField(obj: any): obj is IPublicModelSettingField { - if (!isObject(obj)) { - return false; - } - - return 'isSettingField' in obj && obj.isSettingField; -} diff --git a/packages/utils/src/check-types/is-title-config.ts b/packages/utils/src/check-types/is-title-config.ts deleted file mode 100644 index 460da9979..000000000 --- a/packages/utils/src/check-types/is-title-config.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { IPublicTypeTitleConfig } from '@alilc/lowcode-types'; -import { isI18nData } from './is-i18n-data'; -import { isPlainObject } from '../is-plain-object'; - -export function isTitleConfig(obj: any): obj is IPublicTypeTitleConfig { - return isPlainObject(obj) && !isI18nData(obj); -} diff --git a/packages/utils/src/clone-deep.ts b/packages/utils/src/clone-deep.ts deleted file mode 100644 index 99114634b..000000000 --- a/packages/utils/src/clone-deep.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { isPlainObject } from './is-plain-object'; - -export function cloneDeep(src: any): any { - const type = typeof src; - - let data: any; - if (src === null || src === undefined) { - data = src; - } else if (Array.isArray(src)) { - data = src.map(item => cloneDeep(item)); - } else if (type === 'object' && isPlainObject(src)) { - data = {}; - for (const key in src) { - // eslint-disable-next-line no-prototype-builtins - if (src.hasOwnProperty(key)) { - data[key] = cloneDeep(src[key]); - } - } - } else { - data = src; - } - - return data; -} diff --git a/packages/utils/src/clone-enumerable-property.ts b/packages/utils/src/clone-enumerable-property.ts deleted file mode 100644 index eb09e177f..000000000 --- a/packages/utils/src/clone-enumerable-property.ts +++ /dev/null @@ -1,22 +0,0 @@ -const excludePropertyNames = [ - '$$typeof', - 'render', - 'defaultProps', - 'props', - 'length', - 'prototype', - 'name', - 'caller', - 'callee', - 'arguments', -]; - -export function cloneEnumerableProperty(target: any, origin: any, excludes = excludePropertyNames) { - const compExtraPropertyNames = Object.keys(origin).filter(d => !excludes.includes(d)); - - compExtraPropertyNames.forEach((d: string) => { - (target as any)[d] = origin[d]; - }); - - return target; -} diff --git a/packages/utils/src/context-menu.less b/packages/utils/src/context-menu.less deleted file mode 100644 index 0b75ca3ec..000000000 --- a/packages/utils/src/context-menu.less +++ /dev/null @@ -1,50 +0,0 @@ -.engine-context-menu-tree-wrap { - position: relative; - padding: 4px 10px 4px 32px; -} - -.engine-context-menu-tree-children { - margin-left: 8px; - line-height: 24px; -} - -.engine-context-menu-item { - .engine-context-menu-text { - color: var(--color-context-menu-text, var(--color-text)); - display: flex; - align-items: center; - - .lc-help-tip { - margin-left: 4px; - opacity: 0.8; - } - } - - &.disabled { - &:hover .engine-context-menu-text, .engine-context-menu-text { - color: var(--color-context-menu-text-disabled, var(--color-text-disabled)); - } - } - - &:hover { - .engine-context-menu-text { - color: var(--color-context-menu-text-hover, var(--color-title)); - } - } -} - -.engine-context-menu-title { - color: var(--color-context-menu-text, var(--color-text)); - cursor: pointer; - - &:hover { - background-color: var(--color-block-background-light); - color: var(--color-title); - } -} - -.engine-context-menu-tree-selecte-icon { - position: absolute; - left: 10px; - color: var(--color-icon-active); -} \ No newline at end of file diff --git a/packages/utils/src/context-menu.tsx b/packages/utils/src/context-menu.tsx deleted file mode 100644 index 868626bf6..000000000 --- a/packages/utils/src/context-menu.tsx +++ /dev/null @@ -1,242 +0,0 @@ -import { Menu, Icon } from '@alifd/next'; -import { - IPublicEnumContextMenuType, - IPublicModelNode, - IPublicModelPluginContext, - IPublicTypeContextMenuAction, - IPublicTypeContextMenuItem, -} from '@alilc/lowcode-types'; -import { createLogger, type AnyFunction } from '@alilc/lowcode-shared'; -import classNames from 'classnames'; -import React from 'react'; - -import './context-menu.less'; - -const logger = createLogger({ level: 'warn', bizName: 'utils' }); -const { Item, Divider, PopupItem } = Menu; - -const MAX_LEVEL = 2; - -interface IOptions { - nodes?: IPublicModelNode[] | null; - destroy?: AnyFunction; - pluginContext: IPublicModelPluginContext; -} - -const Tree = (props: { - node?: IPublicModelNode | null; - children?: React.ReactNode; - options: IOptions; -}) => { - const { node } = props; - - if (!node) { - return
{props.children}
; - } - - const { common } = props.options.pluginContext || {}; - const { intl } = common?.utils || {}; - const indent = node.zLevel * 8 + 32; - const style = { - paddingLeft: indent, - marginLeft: -indent, - marginRight: -10, - paddingRight: 10, - }; - - return ( - -
{ - props.options.destroy?.(); - node.select(); - }} - style={style} - > - {props.options.nodes?.[0].id === node.id ? ( - - ) : null} - {intl(node.title)} -
-
{props.children}
-
- ); -}; - -let destroyFn: AnyFunction | undefined; - -export function parseContextMenuAsReactNode( - menus: IPublicTypeContextMenuItem[], - options: IOptions, -): React.ReactNode[] { - const { common, commonUI } = options.pluginContext || {}; - const { intl = (title: any) => title } = common?.utils || {}; - const { HelpTip } = commonUI || {}; - - const children: React.ReactNode[] = []; - menus.forEach((menu, index) => { - if (menu.type === IPublicEnumContextMenuType.SEPARATOR) { - children.push(); - return; - } - - if (menu.type === IPublicEnumContextMenuType.MENU_ITEM) { - if (menu.items && menu.items.length) { - children.push( - {intl(menu.title)}} - > - - {parseContextMenuAsReactNode(menu.items, options)} - - , - ); - } else { - children.push( - { - menu.action?.(); - }} - key={menu.name} - > -
- {menu.title ? intl(menu.title) : null} - {menu.help ? : null} -
-
, - ); - } - } - - if (menu.type === IPublicEnumContextMenuType.NODE_TREE) { - children.push(); - } - }); - - return children; -} - -export function parseContextMenuProperties( - menus: (IPublicTypeContextMenuAction | Omit)[], - options: IOptions & { - event?: MouseEvent; - }, - level = 1, -): IPublicTypeContextMenuItem[] { - destroyFn?.(); - - const { nodes, destroy } = options; - if (level > MAX_LEVEL) { - logger.warn('context menu level is too deep, please check your context menu config'); - return []; - } - - return menus - .filter((menu) => !menu.condition || (menu.condition && menu.condition(nodes || []))) - .map((menu) => { - const { name, title, type = IPublicEnumContextMenuType.MENU_ITEM, help } = menu; - - const result: IPublicTypeContextMenuItem = { - name, - title, - type, - help, - action: () => { - destroy?.(); - menu.action?.(nodes || [], options.event); - }, - disabled: (menu.disabled && menu.disabled(nodes || [])) || false, - }; - - if ('items' in menu && menu.items) { - result.items = parseContextMenuProperties( - typeof menu.items === 'function' ? menu.items(nodes || []) : menu.items, - options, - level + 1, - ); - } - - return result; - }) - .reduce((menus: IPublicTypeContextMenuItem[], currentMenu: IPublicTypeContextMenuItem) => { - if (!currentMenu.name) { - return menus.concat([currentMenu]); - } - - const index = menus.find((item) => item.name === currentMenu.name); - if (!index) { - return menus.concat([currentMenu]); - } else { - return menus; - } - }, []); -} - -let cachedMenuItemHeight: string | undefined; - -function getMenuItemHeight() { - if (cachedMenuItemHeight) { - return cachedMenuItemHeight; - } - const root = document.documentElement; - const styles = getComputedStyle(root); - const menuItemHeight = styles.getPropertyValue('--context-menu-item-height').trim(); - cachedMenuItemHeight = menuItemHeight; - - return menuItemHeight; -} - -export function createContextMenu( - children: React.ReactNode[], - { - event, - offset = [0, 0], - }: { - event: MouseEvent | React.MouseEvent; - offset?: [number, number]; - }, -) { - event.preventDefault(); - event.stopPropagation(); - - const viewportWidth = window.innerWidth; - const viewportHeight = window.innerHeight; - const dividerCount = React.Children.count( - children.filter((child) => React.isValidElement(child) && child.type === Divider), - ); - const popupItemCount = React.Children.count( - children.filter( - (child) => React.isValidElement(child) && (child.type === PopupItem || child.type === Item), - ), - ); - const menuHeight = popupItemCount * parseInt(getMenuItemHeight(), 10) + dividerCount * 8 + 16; - const menuWidthLimit = 200; - let x = event.clientX + offset[0]; - let y = event.clientY + offset[1]; - if (x + menuWidthLimit > viewportWidth) { - x = x - menuWidthLimit; - } - if (y + menuHeight > viewportHeight) { - y = y - menuHeight; - } - - const menuInstance = Menu.create({ - target: document.body, - offset: [x, y], - children, - className: 'engine-context-menu', - }); - - destroyFn = (menuInstance as any).destroy; - - return destroyFn; -} diff --git a/packages/utils/src/create-content.ts b/packages/utils/src/create-content.ts deleted file mode 100644 index 71f53a681..000000000 --- a/packages/utils/src/create-content.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { ReactNode, ComponentType, isValidElement, cloneElement, createElement } from 'react'; -import { isReactComponent } from './is-react'; - -export function createContent( - content: ReactNode | ComponentType, - props?: Record, -): ReactNode { - if (isValidElement(content)) { - return props ? cloneElement(content, props) : content; - } - if (isReactComponent(content)) { - return createElement(content, props); - } - - return content; -} diff --git a/packages/utils/src/create-defer.ts b/packages/utils/src/create-defer.ts deleted file mode 100644 index e7997365a..000000000 --- a/packages/utils/src/create-defer.ts +++ /dev/null @@ -1,17 +0,0 @@ -export interface Defer { - resolve(value?: T | PromiseLike): void; - reject(reason?: any): void; - promise(): Promise; -} - -export function createDefer(): Defer { - const r: any = {}; - const promise = new Promise((resolve, reject) => { - r.resolve = resolve; - r.reject = reject; - }); - - r.promise = () => promise; - - return r; -} diff --git a/packages/utils/src/create-icon.tsx b/packages/utils/src/create-icon.tsx deleted file mode 100644 index 1f36c656d..000000000 --- a/packages/utils/src/create-icon.tsx +++ /dev/null @@ -1,40 +0,0 @@ -import { isValidElement, ReactNode, createElement, cloneElement } from 'react'; -import { Icon } from '@alifd/next'; -import { IPublicTypeIconType } from '@alilc/lowcode-types'; -import { isReactComponent } from './is-react'; -import { isESModule } from './is-es-module'; - -const URL_RE = /^(https?:)\/\//i; - -export function createIcon( - icon?: IPublicTypeIconType | null, - props?: Record, -): ReactNode { - if (!icon) { - return null; - } - if (isESModule(icon)) { - icon = icon.default; - } - if (typeof icon === 'string') { - if (URL_RE.test(icon)) { - return createElement('img', { - src: icon, - className: props?.className, - ...props, - }); - } - return ; - } - if (isValidElement(icon)) { - return cloneElement(icon, { ...props }); - } - if (isReactComponent(icon)) { - return createElement(icon, { - className: props?.className, - ...props, - }); - } - - return ; -} diff --git a/packages/utils/src/css-helper.ts b/packages/utils/src/css-helper.ts deleted file mode 100644 index fed0d14a3..000000000 --- a/packages/utils/src/css-helper.ts +++ /dev/null @@ -1,208 +0,0 @@ -/** - * just for legao - * @author: jiushen - */ -// 需要通过 Env 来判断是否需要 - -import { some } from 'lodash-es'; - -const pseudoMap = ['hover', 'focus', 'active', 'visited']; - -const RE_CAMEL = /[A-Z]/g; -const RE_HYPHEN = /[-\s]+(.)?/g; -const PROPS_REG = /([^:]*):\s?(.*)/i; - -// 给 css 分组 -function groupingCss(css: string) { - let stackLength = 0; - let startIndex = 0; - const group: string[] = []; - css.split('').forEach((char, index) => { - if (char === '{') { - stackLength++; - } - if (char === '}') { - if (stackLength === 1) { - group.push(css.substring(startIndex, index + 1)); - startIndex = index + 1; - } - stackLength--; - } - }); - return group; -} - -function isString(str: any): str is string { - return {}.toString.call(str) === '[object String]'; -} - -function hyphenate(str: string): string { - return str.replace(RE_CAMEL, (w) => `-${w}`).toLowerCase(); -} - -function camelize(str: string): string { - return str.replace(RE_HYPHEN, (m, w) => (w ? w.toUpperCase() : '')); -} - -/** - * convert - * {background-color: "red"} - * to - * background-color: red; - */ -function runtimeToCss(runtime: Record) { - const css: string[] = []; - Object.keys(runtime).forEach((key) => { - css.push(` ${key}: ${runtime[key]};`); - }); - return css.join('\n'); -} - -function toNativeStyle(runtime: Record | undefined) { - if (!runtime) { - return {}; - } - if (runtime.default) { - const normalized: any = {}; - Object.keys(runtime).forEach((pseudo) => { - if (pseudo === 'extra') { - normalized[pseudo] = runtime[pseudo]; - return; - } - normalized[pseudo] = toNativeStyle(runtime[pseudo] as any); - }); - return normalized; - } - - const normalized: any = {}; - Object.keys(runtime).forEach((key) => { - normalized[camelize(key)] = runtime[key]; - }); - return normalized; -} - -function normalizeStyle(style: any): any { - if (!style) { - return {}; - } - if (style.default) { - const normalized: Record = {}; - Object.keys(style).forEach((pseudo) => { - if (pseudo === 'extra') { - normalized[pseudo] = style[pseudo]; - return; - } - normalized[pseudo] = normalizeStyle(style[pseudo]); - }); - return normalized; - } - - const normalized: Record> = {}; - Object.keys(style).forEach((key) => { - normalized[hyphenate(key)] = style[key]; - }); - return normalized; -} - -function toCss(runtime: Record) { - if (!runtime) { - return `:root { - -}`; - } - - if (runtime.default) { - const css: string[] = []; - Object.keys(runtime).forEach((pseudo) => { - if (pseudo === 'extra') { - Array.isArray(runtime.extra) && css.push(runtime.extra.join('\n')); - return; - } - // 只需要对这四种做兼容 - const prefix = pseudoMap.indexOf(pseudo) > -1 ? ':' : ''; - css.push( - `:root${pseudo === 'default' ? '' : `${prefix}${pseudo}`} { -${runtimeToCss(normalizeStyle(runtime[pseudo]))} -}\n`, - ); - }); - return css.join('\n'); - } - - return `:root { -${runtimeToCss(normalizeStyle(runtime))} -} -`; -} - -function cssToRuntime(css: string) { - if (!css) { - return {}; - } - const runtime: { - extra?: string[]; - default?: Record; - } = {}; - const groups = groupingCss(css); - groups.forEach((cssItem) => { - if (!cssItem.startsWith(':root')) { - runtime.extra = runtime.extra || []; - runtime.extra.push(cssItem.trim()); - } else { - const res = /:root:?(.*)?{(.*)/gi.exec(cssItem.replace(/[\r\n]+/gi, '').trim()); - if (res) { - let pseudo: string | undefined; - - if (res[1] && res[1].trim() && some(pseudoMap, (pse) => res[1].indexOf(pse) === 0)) { - pseudo = res[1].trim(); - } else if (res[1] && res[1].trim()) { - pseudo = res[1]; - } - - const s: Record = {}; - res[2] - .split(';') - .reduce((prev, next) => { - if (next.indexOf('base64') > -1) { - prev[prev.length - 1] += `;${next}`; - } else { - prev.push(next); - } - return prev; - }, []) - .forEach((item) => { - if (item) { - if (PROPS_REG.test(item)) { - const props = item.match(PROPS_REG); - const key = props?.[1]; - const value = props?.[2]; - if (key && value) { - s[key.trim()] = value.trim(); - } - } - } - }); - - (runtime as any)[pseudo || 'default'] = s; - } - } - }); - return runtime; -} - -function cssToStyle(css: any) { - try { - if (isString(css)) { - return toNativeStyle(cssToRuntime(css).default); - } - if (css.default) { - return toNativeStyle(normalizeStyle(css.default)); - } - return toNativeStyle(normalizeStyle(css)); - } catch (e) { - // do nothing - } - return {}; -} - -export { hyphenate, camelize, toNativeStyle, normalizeStyle, toCss, cssToRuntime, cssToStyle }; diff --git a/packages/utils/src/cursor.css b/packages/utils/src/cursor.css deleted file mode 100644 index e13da656e..000000000 --- a/packages/utils/src/cursor.css +++ /dev/null @@ -1,19 +0,0 @@ -html.lc-cursor-dragging, -html.lc-cursor-dragging * { - cursor: move !important; -} - -html.lc-cursor-x-resizing, -html.lc-cursor-x-resizing * { - cursor: col-resize; -} - -html.lc-cursor-y-resizing, -html.lc-cursor-y-resizing * { - cursor: row-resize; -} - -html.lc-cursor-copy, -html.lc-cursor-copy * { - cursor: copy !important; -} diff --git a/packages/utils/src/cursor.ts b/packages/utils/src/cursor.ts deleted file mode 100644 index c12ec64b9..000000000 --- a/packages/utils/src/cursor.ts +++ /dev/null @@ -1,63 +0,0 @@ -import './cursor.css'; - -export class Cursor { - private states = new Set(); - - setDragging(flag: boolean) { - if (flag) { - this.addState('dragging'); - } else { - this.removeState('dragging'); - } - } - - setXResizing(flag: boolean) { - if (flag) { - this.addState('x-resizing'); - } else { - this.removeState('x-resizing'); - } - } - - setYResizing(flag: boolean) { - if (flag) { - this.addState('y-resizing'); - } else { - this.removeState('y-resizing'); - } - } - - setCopy(flag: boolean) { - if (flag) { - this.addState('copy'); - } else { - this.removeState('copy'); - } - } - - isCopy() { - return this.states.has('copy'); - } - - release() { - for (const state of this.states) { - this.removeState(state); - } - } - - addState(state: string) { - if (!this.states.has(state)) { - this.states.add(state); - document.documentElement.classList.add(`lc-cursor-${state}`); - } - } - - private removeState(state: string) { - if (this.states.has(state)) { - this.states.delete(state); - document.documentElement.classList.remove(`lc-cursor-${state}`); - } - } -} - -export const cursor = new Cursor(); diff --git a/packages/utils/src/env.ts b/packages/utils/src/env.ts deleted file mode 100644 index b9a7b4696..000000000 --- a/packages/utils/src/env.ts +++ /dev/null @@ -1,3 +0,0 @@ -export function isInSimulator() { - return Boolean((window as any).__is_simulator_env__); -} diff --git a/packages/utils/src/get-prototype-of.ts b/packages/utils/src/get-prototype-of.ts deleted file mode 100644 index 924c01bcd..000000000 --- a/packages/utils/src/get-prototype-of.ts +++ /dev/null @@ -1,8 +0,0 @@ -export function getPrototypeOf(target: any) { - if (typeof Object.getPrototypeOf !== 'undefined') { - return Object.getPrototypeOf(target); - } - - // eslint-disable-next-line no-proto - return target.__proto__; -} diff --git a/packages/utils/src/has-own-property.ts b/packages/utils/src/has-own-property.ts deleted file mode 100644 index ea5ece914..000000000 --- a/packages/utils/src/has-own-property.ts +++ /dev/null @@ -1,4 +0,0 @@ -const prototypeHasOwnProperty = Object.prototype.hasOwnProperty; -export function hasOwnProperty(obj: any, key: string | number | symbol): boolean { - return obj && prototypeHasOwnProperty.call(obj, key); -} diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts deleted file mode 100644 index 5bca82fbb..000000000 --- a/packages/utils/src/index.ts +++ /dev/null @@ -1,37 +0,0 @@ -import * as css from './css-helper'; - -export * from './asset'; -export * from './clone-deep'; -export * from './create-content'; -export * from './create-icon'; -export * from './cursor'; -export * from './get-prototype-of'; -export * from './has-own-property'; -export * from './is-css-url'; -export * from './is-element'; -export * from './is-es-module'; -export * from './is-form-event'; -export * from './is-function'; -export * from './is-object'; -export * from './is-plain-object'; -export * from './is-react'; -export * from './navtive-selection'; -export * from './set-prototype-of'; -export * from './shallow-equal'; -export * from './svg-icon'; -export * from './unique-id'; -export * from './build-components'; -export * from './app-helper'; -export * from './misc'; -export * from './schema'; -export * from './node-helper'; -export * from './clone-enumerable-property'; -export * from '../../shared/src/helper/logger'; -export * from './is-shaken'; -export * from './is-plugin-event-name'; -export { css }; -export { transactionManager } from './transaction-manager'; -export * from './check-types'; -export * from './workspace'; -export * from './context-menu'; -export { checkPropTypes } from './check-prop-types'; diff --git a/packages/utils/src/is-css-url.ts b/packages/utils/src/is-css-url.ts deleted file mode 100644 index af2960482..000000000 --- a/packages/utils/src/is-css-url.ts +++ /dev/null @@ -1,3 +0,0 @@ -export function isCSSUrl(url: string): boolean { - return /\.css(\?.*)?$/.test(url); -} diff --git a/packages/utils/src/is-element.ts b/packages/utils/src/is-element.ts deleted file mode 100644 index 5ffb60ad9..000000000 --- a/packages/utils/src/is-element.ts +++ /dev/null @@ -1,4 +0,0 @@ -export function isElement(node: any): node is Element { - if (!node) return false; - return node.nodeType === Node.ELEMENT_NODE; -} diff --git a/packages/utils/src/is-es-module.ts b/packages/utils/src/is-es-module.ts deleted file mode 100644 index 6a9d0fa9e..000000000 --- a/packages/utils/src/is-es-module.ts +++ /dev/null @@ -1,7 +0,0 @@ -export type ESModule = { - __esModule: true; - default: any; -}; -export function isESModule(obj: any): obj is ESModule { - return obj && obj.__esModule; -} diff --git a/packages/utils/src/is-form-event.ts b/packages/utils/src/is-form-event.ts deleted file mode 100644 index 40d652fb1..000000000 --- a/packages/utils/src/is-form-event.ts +++ /dev/null @@ -1,14 +0,0 @@ -export function isFormEvent(e: KeyboardEvent | MouseEvent) { - const t = e.target as HTMLFormElement; - if (!t) { - return false; - } - - if (t.form || /^(INPUT|SELECT|TEXTAREA)$/.test(t.tagName)) { - return true; - } - if (t instanceof HTMLElement && /write/.test(window.getComputedStyle(t).getPropertyValue('-webkit-user-modify'))) { - return true; - } - return false; -} diff --git a/packages/utils/src/is-function.ts b/packages/utils/src/is-function.ts deleted file mode 100644 index 4f1c1c0e2..000000000 --- a/packages/utils/src/is-function.ts +++ /dev/null @@ -1,3 +0,0 @@ -export function isFunction(fn: any): boolean { - return typeof fn === 'function'; -} diff --git a/packages/utils/src/is-object.ts b/packages/utils/src/is-object.ts deleted file mode 100644 index c8d764458..000000000 --- a/packages/utils/src/is-object.ts +++ /dev/null @@ -1,7 +0,0 @@ -export function isObject(value: any): value is Record { - return value !== null && typeof value === 'object'; -} - -export function isI18NObject(value: any): boolean { - return isObject(value) && value.type === 'i18n'; -} diff --git a/packages/utils/src/is-plain-object.ts b/packages/utils/src/is-plain-object.ts deleted file mode 100644 index 3fef56fa4..000000000 --- a/packages/utils/src/is-plain-object.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { isObject } from './is-object'; - -export function isPlainObject>(value: any): value is T { - if (!isObject(value)) { - return false; - } - const proto = Object.getPrototypeOf(value); - return proto === Object.prototype || proto === null || Object.getPrototypeOf(proto) === null; -} diff --git a/packages/utils/src/is-plugin-event-name.ts b/packages/utils/src/is-plugin-event-name.ts deleted file mode 100644 index 688eddc6e..000000000 --- a/packages/utils/src/is-plugin-event-name.ts +++ /dev/null @@ -1,8 +0,0 @@ -export function isPluginEventName(eventName: string): boolean { - if (!eventName) { - return false; - } - - const eventSegments = eventName.split(':'); - return (eventSegments.length > 1 && eventSegments[0].length > 0); -} diff --git a/packages/utils/src/is-react.ts b/packages/utils/src/is-react.ts deleted file mode 100644 index 391a89871..000000000 --- a/packages/utils/src/is-react.ts +++ /dev/null @@ -1,75 +0,0 @@ -import { ComponentClass, Component, FunctionComponent, ComponentType, createElement } from 'react'; -import { cloneEnumerableProperty } from './clone-enumerable-property'; - -const hasSymbol = typeof Symbol === 'function' && Symbol.for; -export const REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0; -export const REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3; - -export function isReactClass(obj: any): obj is ComponentClass { - if (!obj) { - return false; - } - if (obj.prototype && (obj.prototype.isReactComponent || obj.prototype instanceof Component)) { - return true; - } - return false; -} - -export function acceptsRef(obj: any): boolean { - if (!obj) { - return false; - } - if (obj?.prototype?.isReactComponent || isForwardOrMemoForward(obj)) { - return true; - } - - return false; -} - -export function isForwardRefType(obj: any): boolean { - if (!obj || !obj?.$$typeof) { - return false; - } - return obj?.$$typeof === REACT_FORWARD_REF_TYPE; -} - -export function isMemoType(obj: any): boolean { - if (!obj || !obj?.$$typeof) { - return false; - } - return obj.$$typeof === REACT_MEMO_TYPE; -} - -export function isForwardOrMemoForward(obj: any): boolean { - if (!obj || !obj?.$$typeof) { - return false; - } - return ( - // React.forwardRef(..) - isForwardRefType(obj) || - // React.memo(React.forwardRef(..)) - (isMemoType(obj) && isForwardRefType(obj.type)) - ); -} - -export function isReactComponent(obj: any): obj is ComponentType { - if (!obj) { - return false; - } - - return Boolean( - isReactClass(obj) || typeof obj === 'function' || isForwardRefType(obj) || isMemoType(obj), - ); -} - -export function wrapReactClass(view: FunctionComponent) { - let ViewComponentClass = class extends Component { - render() { - const { children, ...other } = this.props; - return createElement(view, other, children); - } - } as any; - ViewComponentClass = cloneEnumerableProperty(ViewComponentClass, view); - ViewComponentClass.displayName = view.displayName; - return ViewComponentClass; -} diff --git a/packages/utils/src/is-shaken.ts b/packages/utils/src/is-shaken.ts deleted file mode 100644 index 088e8ce4a..000000000 --- a/packages/utils/src/is-shaken.ts +++ /dev/null @@ -1,15 +0,0 @@ -const SHAKE_DISTANCE = 4; -/** - * mouse shake check - */ -export function isShaken(e1: MouseEvent | DragEvent, e2: MouseEvent | DragEvent): boolean { - if ((e1 as any).shaken) { - return true; - } - if (e1.target !== e2.target) { - return true; - } - return ( - Math.pow(e1.clientY - e2.clientY, 2) + Math.pow(e1.clientX - e2.clientX, 2) > SHAKE_DISTANCE - ); -} diff --git a/packages/utils/src/misc.ts b/packages/utils/src/misc.ts deleted file mode 100644 index a5e80bde1..000000000 --- a/packages/utils/src/misc.ts +++ /dev/null @@ -1,129 +0,0 @@ -import { isI18NObject } from './is-object'; -import { get } from 'lodash-es'; -import { IPublicEnumTransformStage, IPublicModelComponentMeta } from '@alilc/lowcode-types'; -import { Logger } from '../../shared/src/helper/logger'; - -const logger = new Logger({ level: 'warn', bizName: 'utils' }); - -interface Variable { - type: 'variable'; - variable: string; - value: any; -} - -export function isVariable(obj: any): obj is Variable { - if (!obj || typeof obj !== 'object') { - return false; - } - return obj.type === 'variable'; -} - -export function isUseI18NSetter(prototype: any, propName: string) { - const configure = prototype?.options?.configure; - if (Array.isArray(configure)) { - return configure.some((c) => { - return c.name === propName && c?.setter?.type?.displayName === 'I18nSetter'; - }); - } - return false; -} - -export function convertToI18NObject(v: string | any, locale: string = 'zh-CN') { - if (isI18NObject(v)) return v; - return { type: 'i18n', use: locale, [locale]: v }; -} - -export function isString(v: any): v is string { - return typeof v === 'string'; -} - -function _innerWaitForThing(obj: any, path: string): Promise { - const timeGap = 200; - return new Promise((resolve, reject) => { - setTimeout(() => { - const thing = get(obj, path); - if (thing) { - return resolve(thing); - } - reject(); - }, timeGap); - }).catch(() => { - return _innerWaitForThing(obj, path); - }); -} - -export function waitForThing(obj: any, path: string): Promise { - const thing = get(obj, path); - if (thing) { - return Promise.resolve(thing); - } - return _innerWaitForThing(obj, path); -} - -export function arrShallowEquals(arr1: any[], arr2: any[]): boolean { - if (!Array.isArray(arr1) || !Array.isArray(arr2)) return false; - if (arr1.length !== arr2.length) return false; - return arr1.every((item) => arr2.includes(item)); -} - -/** - * 判断当前 meta 是否从 vc prototype 转换而来 - * @param meta - */ -export function isFromVC(meta: IPublicModelComponentMeta) { - return !!meta?.getMetadata().configure?.advanced; -} - -export function executePendingFn(fn: () => void, timeout: number = 2000) { - return setTimeout(fn, timeout); -} - -const stageList = ['render', 'serilize', 'save', 'clone', 'init', 'upgrade']; - -/** - * 兼容原来的数字版本的枚举对象 - * @param stage - * @returns - */ -export function compatStage(stage: IPublicEnumTransformStage | number): IPublicEnumTransformStage { - if (typeof stage === 'number') { - console.warn( - 'stage 直接指定为数字的使用方式已经过时,将在下一版本移除,请直接使用 IPublicEnumTransformStage.Render|Serilize|Save|Clone|Init|Upgrade', - ); - return stageList[stage - 1] as IPublicEnumTransformStage; - } - return stage as IPublicEnumTransformStage; -} - -export function invariant(check: any, message: string, thing?: any) { - if (!check) { - throw new Error(`Invariant failed: ${message}${thing ? ` in '${thing}'` : ''}`); - } -} - -export function deprecate(fail: any, message: string, alterative?: string) { - if (fail) { - logger.warn(`Deprecation: ${message}` + (alterative ? `, use ${alterative} instead.` : '')); - } -} - -export function isRegExp(obj: any): obj is RegExp { - if (!obj || typeof obj !== 'object') { - return false; - } - return 'test' in obj && 'exec' in obj && 'compile' in obj; -} - -/** - * The prop supportVariable SHOULD take precedence over default global supportVariable. - * @param propSupportVariable prop supportVariable - * @param globalSupportVariable global supportVariable - * @returns - */ -export function shouldUseVariableSetter( - propSupportVariable: boolean | undefined, - globalSupportVariable: boolean, -) { - if (propSupportVariable === false) return false; - return propSupportVariable || globalSupportVariable; -} diff --git a/packages/utils/src/navtive-selection.ts b/packages/utils/src/navtive-selection.ts deleted file mode 100644 index b8e525773..000000000 --- a/packages/utils/src/navtive-selection.ts +++ /dev/null @@ -1,16 +0,0 @@ -export let nativeSelectionEnabled = true; - -const preventSelection = (e: Event) => { - if (nativeSelectionEnabled) { - return null; - } - e.preventDefault(); - e.stopPropagation(); - return false; -}; -document.addEventListener('selectstart', preventSelection, true); -document.addEventListener('dragstart', preventSelection, true); - -export function setNativeSelection(enableFlag: boolean) { - nativeSelectionEnabled = enableFlag; -} diff --git a/packages/utils/src/node-helper.ts b/packages/utils/src/node-helper.ts deleted file mode 100644 index 438983b3b..000000000 --- a/packages/utils/src/node-helper.ts +++ /dev/null @@ -1,30 +0,0 @@ -// 仅使用类型 -import { IPublicModelNode } from '@alilc/lowcode-types'; -import { MouseEvent } from 'react'; - -export const getClosestNode = ( - node: Node, - until: (n: Node) => boolean, -): Node | undefined => { - if (!node) { - return undefined; - } - if (until(node)) { - return node; - } else { - // @ts-ignore - return getClosestNode(node.parent, until); - } -}; - -/** - * 判断节点是否可被点击 - * @param {Node} node 节点 - * @param {unknown} e 点击事件 - * @returns {boolean} 是否可点击,true表示可点击 - */ -export function canClickNode(node: Node, e: MouseEvent): boolean { - const onClickHook = node.componentMeta?.advanced?.callbacks?.onClickHook; - const canClick = typeof onClickHook === 'function' ? onClickHook(e, node) : true; - return canClick; -} diff --git a/packages/utils/src/schema.ts b/packages/utils/src/schema.ts deleted file mode 100644 index f8fcbbcbc..000000000 --- a/packages/utils/src/schema.ts +++ /dev/null @@ -1,123 +0,0 @@ -import { ActivityType, IPublicTypeNodeSchema, IPublicTypeRootSchema } from '@alilc/lowcode-types'; -import { isJSBlock, isJSSlot } from './check-types'; -import { isVariable } from './misc'; -import { isPlainObject } from './is-plain-object'; - -function isJsObject(props: any) { - if (typeof props === 'object' && props !== null) { - return props.type && props.source && props.compiled; - } -} -function isActionRef(props: any): boolean { - return props.type && props.type === 'actionRef'; -} - -/** - * 将「乐高版本」协议升级成 JSExpression / JSSlot 等标准协议的结构 - * @param props - * @returns - */ -export function compatibleLegaoSchema(props: any): any { - if (!props) { - return props; - } - - if (Array.isArray(props)) { - return props.map((k) => compatibleLegaoSchema(k)); - } - - if (!isPlainObject(props)) { - return props; - } - - if (isJSBlock(props)) { - if (props.value.componentName === 'Slot') { - return { - type: 'JSSlot', - title: (props.value.props as any)?.slotTitle, - name: (props.value.props as any)?.slotName, - value: compatibleLegaoSchema(props.value.children), - params: (props.value.props as any)?.slotParams, - }; - } else { - return props.value; - } - } - if (isVariable(props)) { - return { - type: 'JSExpression', - value: props.variable, - mock: props.value, - }; - } - if (isJsObject(props)) { - return { - type: 'JSExpression', - value: props.compiled, - extType: 'function', - }; - } - if (isActionRef(props)) { - return { - type: 'JSExpression', - value: `${props.id}.bind(this)`, - }; - } - const newProps: any = {}; - Object.keys(props).forEach((key) => { - if (/^__slot__/.test(key) && props[key] === true) { - return; - } - // TODO: 先移除,目前没有业务使用 - // if (key === 'dataSource') { - // newProps[key] = props[key]; - // return; - // } - newProps[key] = compatibleLegaoSchema(props[key]); - }); - return newProps; -} - -export function getNodeSchemaById( - schema: IPublicTypeNodeSchema, - nodeId: string, -): IPublicTypeNodeSchema | undefined { - let found: IPublicTypeNodeSchema | undefined; - if (schema.id === nodeId) { - return schema; - } - const { children, props } = schema; - // 查找 children - if (Array.isArray(children)) { - for (const child of children) { - found = getNodeSchemaById(child as IPublicTypeNodeSchema, nodeId); - if (found) return found; - } - } - if (isPlainObject(props)) { - // 查找 props,主要是 slot 类型 - found = getNodeSchemaFromPropsById(props, nodeId); - if (found) return found; - } -} - -function getNodeSchemaFromPropsById(props: any, nodeId: string): IPublicTypeNodeSchema | undefined { - let found: IPublicTypeNodeSchema | undefined; - for (const [, value] of Object.entries(props)) { - if (isJSSlot(value)) { - // value 是数组类型 { type: 'JSSlot', value: IPublicTypeNodeSchema[] } - if (Array.isArray(value.value)) { - for (const child of value.value) { - found = getNodeSchemaById(child as IPublicTypeNodeSchema, nodeId); - if (found) return found; - } - } - // value 是对象类型 { type: 'JSSlot', value: IPublicTypeNodeSchema } - found = getNodeSchemaById(value.value as IPublicTypeNodeSchema, nodeId); - if (found) return found; - } else if (isPlainObject(value)) { - found = getNodeSchemaFromPropsById(value, nodeId); - if (found) return found; - } - } -} diff --git a/packages/utils/src/script.ts b/packages/utils/src/script.ts deleted file mode 100644 index 383fa0b0f..000000000 --- a/packages/utils/src/script.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { createDefer } from './create-defer'; -import { Logger } from '../../shared/src/helper/logger'; - -const logger = new Logger({ level: 'warn', bizName: 'utils' }); - -export function evaluate(script: string, scriptType?: string) { - const scriptEl = document.createElement('script'); - scriptType && (scriptEl.type = scriptType); - scriptEl.text = script; - document.head.appendChild(scriptEl); - document.head.removeChild(scriptEl); -} - -export function load(url: string, scriptType?: string) { - const node = document.createElement('script'); - - // node.setAttribute('crossorigin', 'anonymous'); - - node.onload = onload; - node.onerror = onload; - - const i = createDefer(); - - function onload(e: any) { - node.onload = null; - node.onerror = null; - if (e.type === 'load') { - i.resolve(); - } else { - i.reject(); - } - // document.head.removeChild(node); - // node = null; - } - - node.src = url; - - // `async=false` is required to make sure all js resources execute sequentially. - node.async = false; - - scriptType && (node.type = scriptType); - - document.head.appendChild(node); - - return i.promise(); -} - -export function evaluateExpression(expr: string) { - // eslint-disable-next-line no-new-func - const fn = new Function(expr); - return fn(); -} - -export function newFunction(args: string, code: string) { - try { - // eslint-disable-next-line no-new-func - return new Function(args, code); - } catch (e) { - logger.warn('Caught error, Cant init func'); - return null; - } -} diff --git a/packages/utils/src/set-prototype-of.ts b/packages/utils/src/set-prototype-of.ts deleted file mode 100644 index 484ea7819..000000000 --- a/packages/utils/src/set-prototype-of.ts +++ /dev/null @@ -1,8 +0,0 @@ -export function setPrototypeOf(target: any, proto: any) { - if (typeof Object.setPrototypeOf !== 'undefined') { - Object.setPrototypeOf(target, proto); - } else { - // eslint-disable-next-line no-proto - target.__proto__ = proto; - } -} diff --git a/packages/utils/src/shallow-equal.ts b/packages/utils/src/shallow-equal.ts deleted file mode 100644 index c7fdb9cb1..000000000 --- a/packages/utils/src/shallow-equal.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { hasOwnProperty } from './has-own-property'; - -export function shallowEqual(objA: any, objB: any): boolean { - if (objA === objB) { - return true; - } - - if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) { - return false; - } - - const keysA = Object.keys(objA); - const keysB = Object.keys(objB); - - if (keysA.length !== keysB.length) { - return false; - } - - // Test for A's keys different from B. - for (let i = 0; i < keysA.length; i++) { - if (!hasOwnProperty(objB, keysA[i]) || objA[keysA[i]] !== objB[keysA[i]]) { - return false; - } - } - - return true; -} diff --git a/packages/utils/src/svg-icon.tsx b/packages/utils/src/svg-icon.tsx deleted file mode 100644 index c27e24b18..000000000 --- a/packages/utils/src/svg-icon.tsx +++ /dev/null @@ -1,49 +0,0 @@ -import React, { ReactNode } from 'react'; - -const SizePresets = { - xsmall: 8, - small: 12, - medium: 16, - large: 20, - xlarge: 30, -}; - -export interface IconProps { - className?: string; - fill?: string; - size?: 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge' | number; - children?: ReactNode; - style?: Record; -} - -export function SVGIcon({ - fill, - size = 'medium', - viewBox, - style, - children, - ...props -}: IconProps & { - viewBox: string; -}) { - if (typeof size === 'string' && size in SizePresets) { - size = SizePresets[size]; - } - - return ( - - {children} - - ); -} diff --git a/packages/utils/src/transaction-manager.ts b/packages/utils/src/transaction-manager.ts deleted file mode 100644 index feb9b7a11..000000000 --- a/packages/utils/src/transaction-manager.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { IPublicEnumTransitionType } from '@alilc/lowcode-types'; -import { runInAction } from 'mobx'; -import { EventEmitter } from 'events'; - -class TransactionManager { - emitter = new EventEmitter(); - - executeTransaction = ( - fn: () => void, - type: IPublicEnumTransitionType = IPublicEnumTransitionType.REPAINT, - ): void => { - this.emitter.emit(`[${type}]startTransaction`); - runInAction(fn); - this.emitter.emit(`[${type}]endTransaction`); - }; - - onStartTransaction = ( - fn: () => void, - type: IPublicEnumTransitionType = IPublicEnumTransitionType.REPAINT, - ): (() => void) => { - this.emitter.on(`[${type}]startTransaction`, fn); - return () => { - this.emitter.off(`[${type}]startTransaction`, fn); - }; - }; - - onEndTransaction = ( - fn: () => void, - type: IPublicEnumTransitionType = IPublicEnumTransitionType.REPAINT, - ): (() => void) => { - this.emitter.on(`[${type}]endTransaction`, fn); - return () => { - this.emitter.off(`[${type}]endTransaction`, fn); - }; - }; -} - -export const transactionManager = new TransactionManager(); diff --git a/packages/utils/src/unique-id.ts b/packages/utils/src/unique-id.ts deleted file mode 100644 index 3713cbd06..000000000 --- a/packages/utils/src/unique-id.ts +++ /dev/null @@ -1,4 +0,0 @@ -let guid = Date.now(); -export function uniqueId(prefix = '') { - return `${prefix}${(guid++).toString(36).toLowerCase()}`; -} diff --git a/packages/utils/src/workspace.tsx b/packages/utils/src/workspace.tsx deleted file mode 100644 index 446530ce8..000000000 --- a/packages/utils/src/workspace.tsx +++ /dev/null @@ -1,54 +0,0 @@ -import React, { useEffect, useState, useCallback } from 'react'; -import { IPublicModelPluginContext, IPublicEnumPluginRegisterLevel, IPublicModelWindow, IPublicModelEditorView } from '@alilc/lowcode-types'; - -/** - * 高阶组件(HOC):为组件提供 view 插件上下文。 - * - * @param {React.ComponentType} Component - 需要被封装的组件。 - * @param {string|string[]} viewName - 视图名称或视图名称数组,用于过滤特定的视图插件上下文。 - * @returns {React.ComponentType} 返回封装后的组件。 - * - * @example - * // 用法示例(函数组件): - * const EnhancedComponent = ProvideViewPluginContext(MyComponent, "viewName"); - */ -export const ProvideViewPluginContext = (Component: any, viewName?: string | string[]) => { - // 创建一个新的函数组件,以便在其中使用 Hooks - return function WithPluginContext(props: { - [key: string]: any; - - pluginContext?: IPublicModelPluginContext; - }) { - const getPluginContextFun = useCallback((editorWindow?: IPublicModelWindow | null) => { - if (!editorWindow?.currentEditorView) { - return null; - } - if (viewName) { - const items = editorWindow?.editorViews.filter(d => (d as any).viewName === viewName || (Array.isArray(viewName) && viewName.includes((d as any).viewName))); - return items[0]; - } else { - return editorWindow.currentEditorView; - } - }, []); - - const { workspace } = props.pluginContext || {}; - const [pluginContext, setPluginContext] = useState(getPluginContextFun(workspace?.window)); - - useEffect(() => { - if (workspace?.window) { - const ctx = getPluginContextFun(workspace.window); - ctx && setPluginContext(ctx); - } - return workspace?.onChangeActiveEditorView(() => { - const ctx = getPluginContextFun(workspace.window); - ctx && setPluginContext(ctx); - }); - }, [workspace, getPluginContextFun]); - - if (props.pluginContext?.registerLevel !== IPublicEnumPluginRegisterLevel.Workspace || !props.pluginContext) { - return ; - } - - return ; - }; -}; diff --git a/packages/utils/tests/src/__snapshots__/is-react.test.tsx.snap b/packages/utils/tests/src/__snapshots__/is-react.test.tsx.snap deleted file mode 100644 index 14ef39453..000000000 --- a/packages/utils/tests/src/__snapshots__/is-react.test.tsx.snap +++ /dev/null @@ -1,10 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`wrapReactClass should render the FunctionComponent with props 1`] = ` - - Child Text - -`; diff --git a/packages/utils/tests/src/__snapshots__/schema.test.ts.snap b/packages/utils/tests/src/__snapshots__/schema.test.ts.snap deleted file mode 100644 index e926c89b3..000000000 --- a/packages/utils/tests/src/__snapshots__/schema.test.ts.snap +++ /dev/null @@ -1,23 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Schema Ut props 1`] = ` -Object { - "props": Object { - "mobileSlot": Object { - "name": undefined, - "params": undefined, - "title": undefined, - "type": "JSSlot", - "value": Array [ - Object { - "loop": Object { - "mock": undefined, - "type": "JSExpression", - "value": "props.content", - }, - }, - ], - }, - }, -} -`; diff --git a/packages/utils/tests/src/build-components/buildComponents.test.tsx b/packages/utils/tests/src/build-components/buildComponents.test.tsx deleted file mode 100644 index a50a68b39..000000000 --- a/packages/utils/tests/src/build-components/buildComponents.test.tsx +++ /dev/null @@ -1,616 +0,0 @@ -import React from 'react'; -import { - accessLibrary, - generateHtmlComp, - getSubComponent, - buildComponents, - getProjectUtils, -} from "../../../src/build-components"; - -function Button() {}; - -function WrapButton() {}; - -function ButtonGroup() {}; - -function WrapButtonGroup() {}; - -ButtonGroup.Button = Button; - -Button.displayName = "Button"; -ButtonGroup.displayName = "ButtonGroup"; -ButtonGroup.prototype.isReactComponent = true; -Button.prototype.isReactComponent = true; - -jest.mock('../../../src/is-react', () => { - const original = jest.requireActual('../../../src/is-react'); - return { - ...original, - wrapReactClass(view) { - return view; - } - } -}); - -describe('accessLibrary', () => { - it('should return a library object when given a library object', () => { - const libraryObject = { key: 'value' }; - const result = accessLibrary(libraryObject); - expect(result).toEqual(libraryObject); - }); - - it('should generate an HTML component when given a string library name', () => { - const libraryName = 'div'; - const result = accessLibrary(libraryName); - - // You can write more specific assertions to validate the generated component - expect(result).toBeDefined(); - }); - - // Add more test cases to cover other scenarios -}); - -describe('generateHtmlComp', () => { - it('should generate an HTML component for valid HTML tags', () => { - const htmlTags = ['a', 'img', 'div', 'span', 'svg']; - htmlTags.forEach((tag) => { - const result = generateHtmlComp(tag); - - // You can write more specific assertions to validate the generated component - expect(result).toBeDefined(); - }); - }); - - it('should return undefined for an invalid HTML tag', () => { - const invalidTag = 'invalidtag'; - const result = generateHtmlComp(invalidTag); - expect(result).toBeUndefined(); - }); - - // Add more test cases to cover other scenarios -}); - -describe('getSubComponent', () => { - it('should return the root library if paths are empty', () => { - const library = { component: 'RootComponent' }; - const paths = []; - const result = getSubComponent(library, paths); - expect(result).toEqual(library); - }); - - it('should return the specified sub-component', () => { - const library = { - components: { - Button: 'ButtonComponent', - Text: 'TextComponent', - }, - }; - const paths = ['components', 'Button']; - const result = getSubComponent(library, paths); - expect(result).toEqual('ButtonComponent'); - }); - - it('should handle missing keys in the path', () => { - const library = { - components: { - Button: 'ButtonComponent', - }, - }; - const paths = ['components', 'Text']; - const result = getSubComponent(library, paths); - expect(result).toEqual({ - Button: 'ButtonComponent', - }); - }); - - it('should handle exceptions and return null', () => { - const library = 'ButtonComponent'; - const paths = ['components', 'Button']; - // Simulate an exception by providing a non-object in place of 'ButtonComponent' - const result = getSubComponent(library, paths); - expect(result).toBeNull(); - }); - - it('should handle the "default" key as the first path element', () => { - const library = { - default: 'DefaultComponent', - }; - const paths = ['default']; - const result = getSubComponent(library, paths); - expect(result).toEqual('DefaultComponent'); - }); -}); - -describe('getProjectUtils', () => { - it('should return an empty object when given empty metadata and library map', () => { - const libraryMap = {}; - const utilsMetadata = []; - const result = getProjectUtils(libraryMap, utilsMetadata); - expect(result).toEqual({}); - }); - - it('should return project utilities based on metadata and library map', () => { - const libraryMap = { - 'package1': 'library1', - 'package2': 'library2', - }; - - const utilsMetadata = [ - { - name: 'util1', - npm: { - package: 'package1', - }, - }, - { - name: 'util2', - npm: { - package: 'package2', - }, - }, - ]; - - global['library1'] = { name: 'library1' }; - global['library2'] = { name: 'library2' }; - - const result = getProjectUtils(libraryMap, utilsMetadata); - - // Define the expected output based on the mocked accessLibrary - const expectedOutput = { - 'util1': { name: 'library1' }, - 'util2': { name: 'library2' }, - }; - - expect(result).toEqual(expectedOutput); - - global['library1'] = null; - global['library1'] = null; - }); - - it('should handle metadata with destructuring', () => { - const libraryMap = { - 'package1': { destructuring: true, util1: 'library1', util2: 'library2' }, - }; - - const utilsMetadata = [ - { - name: 'util1', - npm: { - package: 'package1', - destructuring: true, - }, - }, - ]; - - const result = getProjectUtils(libraryMap, utilsMetadata); - - // Define the expected output based on the mocked accessLibrary - const expectedOutput = { - 'util1': 'library1', - 'util2': 'library2', - }; - - expect(result).toEqual(expectedOutput); - }); -}); - -describe('buildComponents', () => { - it('should create components from component map with React components', () => { - const libraryMap = {}; - const componentsMap = { - Button: () => , - Text: () =>

Text

, - }; - - const createComponent = (schema) => { - // Mock createComponent function - return schema.componentsTree.map((component) => component.component); - }; - - const result = buildComponents(libraryMap, componentsMap, createComponent); - - expect(result.Button).toBeDefined(); - expect(result.Text).toBeDefined(); - }); - - it('should create components from component map with component schemas', () => { - const libraryMap = {}; - const componentsMap = { - Button: { - componentsTree: [ - { - componentName: 'Component' - } - ] - }, - Text: { - componentsTree: [ - { - componentName: 'Component' - } - ] - }, - }; - - const createComponent = (schema) => { - // Mock createComponent function - return schema.componentsTree.map((component) => component.component); - }; - - const result = buildComponents(libraryMap, componentsMap, createComponent); - - expect(result.Button).toBeDefined(); - expect(result.Text).toBeDefined(); - }); - - it('should create components from component map with React components and schemas', () => { - const libraryMap = {}; - const componentsMap = { - Button: () => , - Text: { - type: 'ComponentSchema', - // Add component schema properties here - }, - }; - - const createComponent = (schema) => { - // Mock createComponent function - return schema.componentsTree.map((component) => component.component); - }; - - const result = buildComponents(libraryMap, componentsMap, createComponent); - - expect(result.Button).toBeDefined(); - expect(result.Text).toBeDefined(); - }); - - it('should create components from component map with library mappings', () => { - const libraryMap = { - 'libraryName1': 'library1', - 'libraryName2': 'library2', - }; - const componentsMap = { - Button: { - package: 'libraryName1', - version: '1.0', - exportName: 'ButtonComponent', - }, - Text: { - package: 'libraryName2', - version: '2.0', - exportName: 'TextComponent', - }, - }; - - const createComponent = (schema) => { - // Mock createComponent function - return schema.componentsTree.map((component) => component.component); - }; - - global['library1'] = () => ; - global['library2'] = () => () =>

TextComponent

; - - const result = buildComponents(libraryMap, componentsMap, createComponent); - - expect(result.Button).toBeDefined(); - expect(result.Text).toBeDefined(); - - global['library1'] = null; - global['library2'] = null; - }); -}); - -describe('build-component', () => { - it('basic button', () => { - expect( - buildComponents( - { - '@alilc/button': { - Button, - } - }, - { - Button: { - componentName: 'Button', - package: '@alilc/button', - destructuring: true, - exportName: 'Button', - subName: 'Button', - } - }, - () => {}, - )) - .toEqual({ - Button, - }); - }); - - it('component is a __esModule', () => { - expect( - buildComponents( - { - '@alilc/button': { - __esModule: true, - default: Button, - } - }, - { - Button: { - componentName: 'Button', - package: '@alilc/button', - } - }, - () => {}, - )) - .toEqual({ - Button, - }); - }) - - it('basic warp button', () => { - expect( - buildComponents( - { - '@alilc/button': { - WrapButton, - } - }, - { - WrapButton: { - componentName: 'WrapButton', - package: '@alilc/button', - destructuring: true, - exportName: 'WrapButton', - subName: 'WrapButton', - } - }, - () => {}, - )) - .toEqual({ - WrapButton, - }); - }); - - it('destructuring is false button', () => { - expect( - buildComponents( - { - '@alilc/button': Button - }, - { - Button: { - componentName: 'Button', - package: '@alilc/button', - destructuring: false, - } - }, - () => {}, - )) - .toEqual({ - Button, - }); - }); - - it('Button and ButtonGroup', () => { - expect( - buildComponents( - { - '@alilc/button': { - Button, - ButtonGroup, - } - }, - { - Button: { - componentName: 'Button', - package: '@alilc/button', - destructuring: true, - exportName: 'Button', - subName: 'Button', - }, - ButtonGroup: { - componentName: 'ButtonGroup', - package: '@alilc/button', - destructuring: true, - exportName: 'ButtonGroup', - subName: 'ButtonGroup', - } - }, - () => {}, - )) - .toEqual({ - Button, - ButtonGroup, - }); - }); - - it('ButtonGroup and ButtonGroup.Button', () => { - expect( - buildComponents( - { - '@alilc/button': { - ButtonGroup, - } - }, - { - Button: { - componentName: 'Button', - package: '@alilc/button', - destructuring: true, - exportName: 'ButtonGroup', - subName: 'ButtonGroup.Button', - }, - ButtonGroup: { - componentName: 'ButtonGroup', - package: '@alilc/button', - destructuring: true, - exportName: 'ButtonGroup', - subName: 'ButtonGroup', - } - }, - () => {}, - )) - .toEqual({ - Button, - ButtonGroup, - }); - }); - - it('ButtonGroup.default and ButtonGroup.Button', () => { - expect( - buildComponents( - { - '@alilc/button': ButtonGroup, - }, - { - Button: { - componentName: 'Button', - package: '@alilc/button', - destructuring: true, - exportName: 'Button', - subName: 'Button', - }, - ButtonGroup: { - componentName: 'ButtonGroup', - package: '@alilc/button', - destructuring: true, - exportName: 'default', - subName: 'default', - } - }, - () => {}, - )) - .toEqual({ - Button, - ButtonGroup, - }); - }); - - it('no npm component', () => { - expect( - buildComponents( - { - '@alilc/button': Button, - }, - { - Button: null, - }, - () => {}, - )) - .toEqual({}); - }); - - it('no npm component and global button', () => { - window.Button = Button; - expect( - buildComponents( - {}, - { - Button: null, - }, - () => {}, - )) - .toEqual({ - Button, - }); - window.Button = null; - }); - - it('componentsMap value is component funtion', () => { - expect( - buildComponents( - {}, - { - Button, - }, - () => {}, - )) - .toEqual({ - Button, - }); - }); - - - it('componentsMap value is component', () => { - expect( - buildComponents( - {}, - { - Button: WrapButton, - }, - () => {}, - )) - .toEqual({ - Button: WrapButton, - }); - }); - - it('componentsMap value is mix component', () => { - expect( - buildComponents( - {}, - { - Button: { - WrapButton, - Button, - ButtonGroup, - }, - }, - () => {}, - )) - .toEqual({ - Button: { - WrapButton, - Button, - ButtonGroup, - }, - }); - }); - - it('componentsMap value is Lowcode Component', () => { - expect( - buildComponents( - {}, - { - Button: { - componentName: 'Component', - schema: {}, - }, - }, - (component) => { - return component as any; - }, - )) - .toEqual({ - Button: { - componentsMap: [], - componentsTree: [ - { - componentName: 'Component', - schema: {}, - } - ], - version: "", - }, - }); - }) -}); - -describe('build div component', () => { - it('build div component', () => { - const components = buildComponents( - { - '@alilc/div': 'div' - }, - { - div: { - componentName: 'div', - package: '@alilc/div' - } - }, - () => {}, - ); - - expect(components['div']).not.toBeNull(); - }) -}) \ No newline at end of file diff --git a/packages/utils/tests/src/build-components/getProjectUtils.test.ts b/packages/utils/tests/src/build-components/getProjectUtils.test.ts deleted file mode 100644 index 216f3db42..000000000 --- a/packages/utils/tests/src/build-components/getProjectUtils.test.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { getProjectUtils } from "../../../src/build-components"; - -const sampleUtil = () => 'I am a sample util'; -const sampleUtil2 = () => 'I am a sample util 2'; - -describe('get project utils', () => { - it('get utils with destructuring true', () => { - expect(getProjectUtils( - { - '@alilc/utils': { - destructuring: true, - sampleUtil, - sampleUtil2, - } - }, - [{ - name: 'sampleUtils', - npm: { - package: '@alilc/utils' - } - }] - )).toEqual({ - sampleUtil, - sampleUtil2, - }) - }); - - it('get utils with name', () => { - expect(getProjectUtils( - { - '@alilc/utils': sampleUtil - }, - [{ - name: 'sampleUtil', - npm: { - package: '@alilc/utils' - } - }] - )).toEqual({ - sampleUtil, - }) - }); -}) \ No newline at end of file diff --git a/packages/utils/tests/src/build-components/getSubComponent.test.ts b/packages/utils/tests/src/build-components/getSubComponent.test.ts deleted file mode 100644 index ca91bb230..000000000 --- a/packages/utils/tests/src/build-components/getSubComponent.test.ts +++ /dev/null @@ -1,85 +0,0 @@ -import { getSubComponent } from '../../../src/build-components'; - -function Button() {} - -function ButtonGroup() {} - -ButtonGroup.Button = Button; - -function OnlyButtonGroup() {} - -describe('getSubComponent library is object', () => { - it('get Button from Button', () => { - expect(getSubComponent({ - Button, - }, ['Button'])).toBe(Button); - }); - - it('get ButtonGroup.Button from ButtonGroup', () => { - expect(getSubComponent({ - ButtonGroup, - }, ['ButtonGroup', 'Button'])).toBe(Button); - }); - - it('get ButtonGroup from ButtonGroup', () => { - expect(getSubComponent({ - ButtonGroup, - }, ['ButtonGroup'])).toBe(ButtonGroup); - }); - - it('get ButtonGroup.Button from OnlyButtonGroup', () => { - expect(getSubComponent({ - ButtonGroup: OnlyButtonGroup, - }, ['ButtonGroup', 'Button'])).toBe(OnlyButtonGroup); - }); -}); - -describe('getSubComponent library is null', () => { - it('getSubComponent library is null', () => { - expect(getSubComponent(null, ['ButtonGroup', 'Button'])).toBeNull(); - }); -}) - -describe('getSubComponent paths is []', () => { - it('getSubComponent paths is []', () => { - expect(getSubComponent(Button, [])).toBe(Button); - }); -}); - -describe('getSubComponent make error', () => { - it('library is string', () => { - expect(getSubComponent(true, ['Button'])).toBe(null); - }); - - it('library is boolean', () => { - expect(getSubComponent('I am a string', ['Button'])).toBe(null); - }); - - it('library is number', () => { - expect(getSubComponent(123, ['Button'])).toBe(null); - }); - - it('library ButtonGroup is null', () => { - expect(getSubComponent({ - ButtonGroup: null, - }, ['ButtonGroup', 'Button'])).toBe(null); - }); - - it('library ButtonGroup.Button is null', () => { - expect(getSubComponent({ - ButtonGroup: null, - }, ['ButtonGroup', 'Button', 'SubButton'])).toBe(null); - }); - - it('path s is [[]]', () => { - expect(getSubComponent({ - ButtonGroup: null, - }, [['ButtonGroup'] as any, 'Button'])).toBe(null); - }); - - it('ButtonGroup is undefined', () => { - expect(getSubComponent({ - ButtonGroup: undefined, - }, ['ButtonGroup', 'Button'])).toBe(null); - }); -}) \ No newline at end of file diff --git a/packages/utils/tests/src/check-prop-types.test.ts b/packages/utils/tests/src/check-prop-types.test.ts deleted file mode 100644 index 74146f2d9..000000000 --- a/packages/utils/tests/src/check-prop-types.test.ts +++ /dev/null @@ -1,255 +0,0 @@ -import { checkPropTypes, transformPropTypesRuleToString } from '../../src/check-prop-types'; -import PropTypes from 'prop-types'; - -describe('checkPropTypes', () => { - it('should validate correctly with valid prop type', () => { - expect(checkPropTypes(123, 'age', PropTypes.number, 'TestComponent')).toBe(true); - expect(checkPropTypes('123', 'age', PropTypes.string, 'TestComponent')).toBe(true); - }); - - it('should log a warning and return false with invalid prop type', () => { - expect(checkPropTypes(123, 'age', PropTypes.string, 'TestComponent')).toBe(false); - expect(checkPropTypes('123', 'age', PropTypes.number, 'TestComponent')).toBe(false); - }); - - it('should validate correctly with valid object prop type', () => { - expect(checkPropTypes({ a: 123 }, 'age', PropTypes.object, 'TestComponent')).toBe(true); - expect(checkPropTypes({ a: '123' }, 'age', PropTypes.object, 'TestComponent')).toBe(true); - }); - - it('should validate correctly with valid object string prop type', () => { - expect(checkPropTypes({ a: 123 }, 'age', 'object', 'TestComponent')).toBe(true); - expect(checkPropTypes({ a: '123' }, 'age', 'object', 'TestComponent')).toBe(true); - }); - - it('should validate correctly with valid isRequired prop type', () => { - const rule = { - type: 'string', - isRequired: true, - }; - expect(transformPropTypesRuleToString(rule)).toBe('PropTypes.string.isRequired'); - expect(checkPropTypes('News', 'type', rule, 'TestComponent')).toBe(true); - expect(checkPropTypes(undefined, 'type', rule, 'TestComponent')).toBe(false); - }); - - it('should handle custom rule functions correctly', () => { - const customRule = (props, propName) => { - if (props[propName] !== 123) { - return new Error('Invalid value'); - } - }; - const result = checkPropTypes(123, 'customProp', customRule, 'TestComponent'); - expect(result).toBe(true); - }); - - - it('should interpret and validate a rule given as a string', () => { - const result = checkPropTypes(123, 'age', 'PropTypes.number', 'TestComponent'); - expect(result).toBe(true); - }); - - it('should interpret and validate a rule given as a string', () => { - expect(checkPropTypes(123, 'age', 'number', 'TestComponent')).toBe(true); - expect(checkPropTypes('123', 'age', 'string', 'TestComponent')).toBe(true); - }); - - it('should log a warning for invalid rule type', () => { - const result = checkPropTypes(123, 'age', 123, 'TestComponent'); - expect(result).toBe(true); - }); - - // oneOf - it('should validate correctly with valid oneOf prop type', () => { - const rule = { - type: 'oneOf', - value: ['News', 'Photos'], - } - expect(transformPropTypesRuleToString(rule)).toBe(`PropTypes.oneOf(["News","Photos"])`); - expect(checkPropTypes('News', 'type', rule, 'TestComponent')).toBe(true); - expect(checkPropTypes('Others', 'type', rule, 'TestComponent')).toBe(false); - }); - - // oneOfType - it('should validate correctly with valid oneOfType prop type', () => { - const rule = { - type: 'oneOfType', - value: ['string', 'number', { - type: 'array', - isRequired: true, - }], - }; - expect(transformPropTypesRuleToString(rule)).toBe('PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.array.isRequired])'); - expect(checkPropTypes(['News', 'Photos'], 'type', rule, 'TestComponent')).toBe(true); - expect(checkPropTypes('News', 'type', rule, 'TestComponent')).toBe(true); - expect(checkPropTypes(123, 'type', rule, 'TestComponent')).toBe(true); - expect(checkPropTypes({}, 'type', rule, 'TestComponent')).toBe(false); - }); - - it('should validate correctly with valid oneOfType prop type', () => { - const rule = { - type: 'oneOfType', - value: [ - 'bool', - { - type: 'shape', - value: [ - { - name: 'type', - propType: { - type: 'oneOf', - value: ['JSExpression'], - } - }, - { - name: 'value', - propType: 'string', - }, - ], - }, - ], - }; - expect(transformPropTypesRuleToString(rule)).toBe('PropTypes.oneOfType([PropTypes.bool, PropTypes.shape({type: PropTypes.oneOf(["JSExpression"]),value: PropTypes.string})])'); - expect(checkPropTypes(true, 'type', rule, 'TestComponent')).toBe(true); - expect(checkPropTypes({ type: 'JSExpression', value: '1 + 1 === 2' }, 'type', rule, 'TestComponent')).toBe(true); - expect(checkPropTypes({ type: 'JSExpression' }, 'type', rule, 'TestComponent')).toBe(true); - expect(checkPropTypes({ type: 'JSExpression', value: 123 }, 'type', rule, 'TestComponent')).toBe(false); - }); - - it('should log a warning for invalid type', () => { - const rule = { - type: 'inval', - value: ['News', 'Photos'], - } - expect(transformPropTypesRuleToString(rule)).toBe('PropTypes.any'); - expect(checkPropTypes('News', 'type', rule, 'TestComponent')).toBe(true); - expect(checkPropTypes('Others', 'type', rule, 'TestComponent')).toBe(true); - }); - - // arrayOf - it('should validate correctly with valid arrayOf prop type', () => { - const rule = { - type: 'arrayOf', - value: { - type: 'string', - isRequired: true, - }, - }; - expect(transformPropTypesRuleToString(rule)).toBe('PropTypes.arrayOf(PropTypes.string.isRequired)'); - expect(checkPropTypes(['News', 'Photos'], 'type', rule, 'TestComponent')).toBe(true); - expect(checkPropTypes(['News', 123], 'type', rule, 'TestComponent')).toBe(false); - }); - - // objectOf - it('should validate correctly with valid objectOf prop type', () => { - const rule = { - type: 'objectOf', - value: { - type: 'string', - isRequired: true, - }, - }; - expect(transformPropTypesRuleToString(rule)).toBe('PropTypes.objectOf(PropTypes.string.isRequired)'); - expect(checkPropTypes({ a: 'News', b: 'Photos' }, 'type', rule, 'TestComponent')).toBe(true); - expect(checkPropTypes({ a: 'News', b: 123 }, 'type', rule, 'TestComponent')).toBe(false); - }); - - // shape - it('should validate correctly with valid shape prop type', () => { - const rule = { - type: 'shape', - value: [ - { - name: 'a', - propType: { - type: 'string', - isRequired: true, - }, - }, - { - name: 'b', - propType: { - type: 'number', - isRequired: true, - }, - }, - ], - }; - expect(transformPropTypesRuleToString(rule)).toBe('PropTypes.shape({a: PropTypes.string.isRequired,b: PropTypes.number.isRequired})'); - expect(checkPropTypes({ a: 'News', b: 123 }, 'type', rule, 'TestComponent')).toBe(true); - expect(checkPropTypes({ a: 'News', b: 'Photos' }, 'type', rule, 'TestComponent')).toBe(false); - - // isRequired - const rule2 = { - type: 'shape', - value: [ - { - name: 'a', - propType: { - type: 'string', - isRequired: true, - }, - }, - { - name: 'b', - propType: { - type: 'number', - isRequired: false, - }, - }, - ], - }; - expect(transformPropTypesRuleToString(rule2)).toBe('PropTypes.shape({a: PropTypes.string.isRequired,b: PropTypes.number})'); - expect(checkPropTypes({ a: 'News', b: 123 }, 'type', rule2, 'TestComponent')).toBe(true); - expect(checkPropTypes({ b: 123 }, 'type', rule2, 'TestComponent')).toBe(false); - }); - - // exact - it('should validate correctly with valid exact prop type', () => { - const rule = { - type: 'exact', - value: [ - { - name: 'a', - propType: { - type: 'string', - isRequired: true, - }, - }, - { - name: 'b', - propType: { - type: 'number', - isRequired: true, - }, - }, - ], - }; - expect(transformPropTypesRuleToString(rule)).toBe('PropTypes.exact({a: PropTypes.string.isRequired,b: PropTypes.number.isRequired})'); - expect(checkPropTypes({ a: 'News', b: 123 }, 'type', rule, 'TestComponent')).toBe(true); - expect(checkPropTypes({ a: 'News', b: 'Photos' }, 'type', rule, 'TestComponent')).toBe(false); - - // isRequired - const rule2 = { - type: 'exact', - value: [ - { - name: 'a', - propType: { - type: 'string', - isRequired: true, - }, - }, - { - name: 'b', - propType: { - type: 'number', - isRequired: false, - }, - }, - ], - }; - expect(transformPropTypesRuleToString(rule2)).toBe('PropTypes.exact({a: PropTypes.string.isRequired,b: PropTypes.number})'); - expect(checkPropTypes({ a: 'News', b: 123 }, 'type', rule2, 'TestComponent')).toBe(true); - expect(checkPropTypes({ b: 123 }, 'type', rule2, 'TestComponent')).toBe(false); - }); -}); \ No newline at end of file diff --git a/packages/utils/tests/src/check-types/is-action-content-object.test.ts b/packages/utils/tests/src/check-types/is-action-content-object.test.ts deleted file mode 100644 index 08b95788d..000000000 --- a/packages/utils/tests/src/check-types/is-action-content-object.test.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { isActionContentObject } from '../../../src/check-types/is-action-content-object'; - -describe('isActionContentObject', () => { - test('should return true for an object', () => { - const obj = { prop: 'value' }; - expect(isActionContentObject(obj)).toBe(true); - }); - - test('should return false for a non-object', () => { - expect(isActionContentObject('not an object')).toBe(false); - expect(isActionContentObject(123)).toBe(false); - expect(isActionContentObject(null)).toBe(false); - expect(isActionContentObject(undefined)).toBe(false); - }); - - test('should return false for an empty object', () => { - const obj = {}; - expect(isActionContentObject(obj)).toBe(true); - }); -}); diff --git a/packages/utils/tests/src/check-types/is-basic-prop-type.test.ts b/packages/utils/tests/src/check-types/is-basic-prop-type.test.ts deleted file mode 100644 index 81a1bf0d3..000000000 --- a/packages/utils/tests/src/check-types/is-basic-prop-type.test.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { isBasicPropType } from '../../../src'; - -describe('test isBasicPropType ', () => { - it('should work', () => { - expect(isBasicPropType(null)).toBeFalsy(); - expect(isBasicPropType(undefined)).toBeFalsy(); - expect(isBasicPropType({})).toBeFalsy(); - expect(isBasicPropType({ type: 'any other type' })).toBeFalsy(); - expect(isBasicPropType('string')).toBeTruthy(); - }); -}); \ No newline at end of file diff --git a/packages/utils/tests/src/check-types/is-custom-view.test.tsx b/packages/utils/tests/src/check-types/is-custom-view.test.tsx deleted file mode 100644 index 62c08780e..000000000 --- a/packages/utils/tests/src/check-types/is-custom-view.test.tsx +++ /dev/null @@ -1,26 +0,0 @@ -import React from 'react'; -import { isCustomView } from '../../../src/check-types/is-custom-view'; -import { IPublicTypeCustomView } from '@alilc/lowcode-types'; - -describe('isCustomView', () => { - test('should return true when obj is a valid React element', () => { - const obj: IPublicTypeCustomView =
Hello, World!
; - expect(isCustomView(obj)).toBe(true); - }); - - test('should return true when obj is a valid React component', () => { - const MyComponent: React.FC = () =>
Hello, World!
; - const obj: IPublicTypeCustomView = MyComponent; - expect(isCustomView(obj)).toBe(true); - }); - - test('should return false when obj is null or undefined', () => { - expect(isCustomView(null)).toBe(false); - expect(isCustomView(undefined)).toBe(false); - }); - - test('should return false when obj is not a valid React element or component', () => { - const obj: IPublicTypeCustomView = 'not a valid object'; - expect(isCustomView(obj)).toBe(false); - }); -}); diff --git a/packages/utils/tests/src/check-types/is-dom-text.test.ts b/packages/utils/tests/src/check-types/is-dom-text.test.ts deleted file mode 100644 index 50dce0fb7..000000000 --- a/packages/utils/tests/src/check-types/is-dom-text.test.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { isDOMText } from '../../../src/check-types/is-dom-text'; - -describe('isDOMText', () => { - it('should return true when the input is a string', () => { - const result = isDOMText('Hello World'); - expect(result).toBe(true); - }); - - it('should return false when the input is not a string', () => { - const result = isDOMText(123); - expect(result).toBe(false); - }); -}); diff --git a/packages/utils/tests/src/check-types/is-drag-any-object.test.ts b/packages/utils/tests/src/check-types/is-drag-any-object.test.ts deleted file mode 100644 index 6a835f2be..000000000 --- a/packages/utils/tests/src/check-types/is-drag-any-object.test.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { isDragAnyObject } from '../../../src/check-types/is-drag-any-object'; -import { IPublicEnumDragObjectType } from '@alilc/lowcode-types'; - -describe('isDragAnyObject', () => { - it('should return false if obj is null', () => { - const result = isDragAnyObject(null); - expect(result).toBe(false); - }); - - it('should return false if obj is number', () => { - const result = isDragAnyObject(2); - expect(result).toBe(false); - }); - - it('should return false if obj.type is NodeData', () => { - const obj = { type: IPublicEnumDragObjectType.NodeData }; - const result = isDragAnyObject(obj); - expect(result).toBe(false); - }); - - it('should return false if obj.type is Node', () => { - const obj = { type: IPublicEnumDragObjectType.Node }; - const result = isDragAnyObject(obj); - expect(result).toBe(false); - }); - - it('should return true if obj.type is anything else', () => { - const obj = { type: 'SomeOtherType' }; - const result = isDragAnyObject(obj); - expect(result).toBe(true); - }); -}); diff --git a/packages/utils/tests/src/check-types/is-drag-node-data-object.test.ts b/packages/utils/tests/src/check-types/is-drag-node-data-object.test.ts deleted file mode 100644 index 92867843a..000000000 --- a/packages/utils/tests/src/check-types/is-drag-node-data-object.test.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { IPublicEnumDragObjectType, IPublicTypeDragNodeDataObject } from '@alilc/lowcode-types'; -import { isDragNodeDataObject } from '../../../src/check-types/is-drag-node-data-object'; - -describe('isDragNodeDataObject', () => { - test('should return true for valid IPublicTypeDragNodeDataObject', () => { - const obj: IPublicTypeDragNodeDataObject = { - type: IPublicEnumDragObjectType.NodeData, - // 其他属性... - }; - - expect(isDragNodeDataObject(obj)).toBe(true); - }); - - test('should return false for invalid IPublicTypeDragNodeDataObject', () => { - const obj: any = { - type: 'InvalidType', - // 其他属性... - }; - - expect(isDragNodeDataObject(obj)).toBe(false); - }); - - test('should return false for null or undefined', () => { - expect(isDragNodeDataObject(null)).toBe(false); - expect(isDragNodeDataObject(undefined)).toBe(false); - }); - - // 可以添加更多测试用例... -}); diff --git a/packages/utils/tests/src/check-types/is-drag-node-object.test.ts b/packages/utils/tests/src/check-types/is-drag-node-object.test.ts deleted file mode 100644 index 3561c8788..000000000 --- a/packages/utils/tests/src/check-types/is-drag-node-object.test.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { IPublicEnumDragObjectType } from '@alilc/lowcode-types'; -import { isDragNodeObject } from '../../../src/check-types/is-drag-node-object'; - -describe('isDragNodeObject', () => { - it('should return true if the object is of IPublicTypeDragNodeObject type and has type IPublicEnumDragObjectType.Node', () => { - const obj = { - type: IPublicEnumDragObjectType.Node, - //... other properties - }; - - expect(isDragNodeObject(obj)).toBe(true); - }); - - it('should return false if the object is not of IPublicTypeDragNodeObject type', () => { - const obj = { - type: IPublicEnumDragObjectType.OtherType, - //... other properties - }; - - expect(isDragNodeObject(obj)).toBe(false); - }); - - it('should return false if the object is of IPublicTypeDragNodeObject type but type is not IPublicEnumDragObjectType.Node', () => { - const obj = { - type: IPublicEnumDragObjectType.OtherType, - //... other properties - }; - - expect(isDragNodeObject(obj)).toBe(false); - }); - - it('should return false if the object is null or undefined', () => { - expect(isDragNodeObject(null)).toBe(false); - expect(isDragNodeObject(undefined)).toBe(false); - }); -}); diff --git a/packages/utils/tests/src/check-types/is-dynamic-setter.test.ts b/packages/utils/tests/src/check-types/is-dynamic-setter.test.ts deleted file mode 100644 index 72f55367d..000000000 --- a/packages/utils/tests/src/check-types/is-dynamic-setter.test.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { Component } from 'react'; -import { isDynamicSetter } from '../../../src/check-types/is-dynamic-setter'; - -describe('isDynamicSetter', () => { - it('returns true if input is a dynamic setter function', () => { - const dynamicSetter = (value: any) => { - // some implementation - }; - - expect(isDynamicSetter(dynamicSetter)).toBeTruthy(); - }); - - it('returns false if input is not a dynamic setter function', () => { - expect(isDynamicSetter('not a function')).toBeFalsy(); - expect(isDynamicSetter(null)).toBeFalsy(); - expect(isDynamicSetter(undefined)).toBeFalsy(); - expect(isDynamicSetter(2)).toBeFalsy(); - expect(isDynamicSetter(0)).toBeFalsy(); - }); - - it('returns false if input is a React class', () => { - class ReactClass extends Component { - // some implementation - } - - expect(isDynamicSetter(ReactClass)).toBeFalsy(); - }); -}); diff --git a/packages/utils/tests/src/check-types/is-i18n-data.test.ts b/packages/utils/tests/src/check-types/is-i18n-data.test.ts deleted file mode 100644 index 2e903a2ed..000000000 --- a/packages/utils/tests/src/check-types/is-i18n-data.test.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { isI18nData } from '../../../src/check-types/is-i18n-data'; -import { IPublicTypeI18nData } from "@alilc/lowcode-types"; - -describe('isI18nData', () => { - it('should return true for valid i18n data', () => { - const i18nData: IPublicTypeI18nData = { - type: 'i18n', - // add any other required properties here - }; - - expect(isI18nData(i18nData)).toBe(true); - }); - - it('should return false for invalid i18n data', () => { - const invalidData = { - type: 'some-other-type', - // add any other properties here - }; - - expect(isI18nData(invalidData)).toBe(false); - }); - - it('should return false for undefined or null', () => { - expect(isI18nData(undefined)).toBe(false); - expect(isI18nData(null)).toBe(false); - }); -}); diff --git a/packages/utils/tests/src/check-types/is-isfunction.test.ts b/packages/utils/tests/src/check-types/is-isfunction.test.ts deleted file mode 100644 index 515428228..000000000 --- a/packages/utils/tests/src/check-types/is-isfunction.test.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { isInnerJsFunction, isJSFunction } from '../../../src/check-types/is-isfunction'; - -describe('isInnerJsFunction', () => { - test('should return true for valid input', () => { - const data = { - type: 'JSExpression', - source: '', - value: '', - extType: 'function' - }; - - expect(isInnerJsFunction(data)).toBe(true); - }); - - test('should return false for invalid input', () => { - const data = { - type: 'JSExpression', - source: '', - value: '', - extType: 'object' - }; - - expect(isInnerJsFunction(data)).toBe(false); - expect(isInnerJsFunction(null)).toBe(false); - expect(isInnerJsFunction(undefined)).toBe(false); - expect(isInnerJsFunction(1)).toBe(false); - expect(isInnerJsFunction(0)).toBe(false); - expect(isInnerJsFunction('string')).toBe(false); - expect(isInnerJsFunction('')).toBe(false); - }); -}); - -describe('isJSFunction', () => { - test('should return true for valid input', () => { - const data = { - type: 'JSFunction', - }; - - expect(isJSFunction(data)).toBe(true); - }); - - test('should return true for inner js function', () => { - const data = { - type: 'JSExpression', - source: '', - value: '', - extType: 'function' - }; - - expect(isJSFunction(data)).toBe(true); - }); - - test('should return false for invalid input', () => { - expect(isJSFunction(null)).toBe(false); - expect(isJSFunction(undefined)).toBe(false); - expect(isJSFunction('string')).toBe(false); - expect(isJSFunction('')).toBe(false); - expect(isJSFunction(0)).toBe(false); - expect(isJSFunction(2)).toBe(false); - }); -}); diff --git a/packages/utils/tests/src/check-types/is-jsblock.test.ts b/packages/utils/tests/src/check-types/is-jsblock.test.ts deleted file mode 100644 index e44e9eb70..000000000 --- a/packages/utils/tests/src/check-types/is-jsblock.test.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { isJSBlock } from '../../../src/check-types/is-jsblock'; - -describe('isJSBlock', () => { - it('should return false if data is null or undefined', () => { - expect(isJSBlock(null)).toBe(false); - expect(isJSBlock(undefined)).toBe(false); - }); - - it('should return false if data is not an object', () => { - expect(isJSBlock('JSBlock')).toBe(false); - expect(isJSBlock(123)).toBe(false); - expect(isJSBlock(true)).toBe(false); - }); - - it('should return false if data.type is not "JSBlock"', () => { - expect(isJSBlock({ type: 'InvalidType' })).toBe(false); - }); - - it('should return true if data is an object and data.type is "JSBlock"', () => { - expect(isJSBlock({ type: 'JSBlock' })).toBe(true); - }); -}); diff --git a/packages/utils/tests/src/check-types/is-jsexpression.test.ts b/packages/utils/tests/src/check-types/is-jsexpression.test.ts deleted file mode 100644 index dd8509a3b..000000000 --- a/packages/utils/tests/src/check-types/is-jsexpression.test.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { isJSExpression } from '../../../src/check-types/is-jsexpression'; - -describe('isJSExpression', () => { - it('should return true if the input is a valid JSExpression object', () => { - const validJSExpression = { - type: 'JSExpression', - extType: 'variable', - }; - - const result = isJSExpression(validJSExpression); - - expect(result).toBe(true); - }); - - it('should return false if the input is not a valid JSExpression object', () => { - const invalidJSExpression = { - type: 'JSExpression', - extType: 'function', - }; - - const result = isJSExpression(invalidJSExpression); - - expect(result).toBe(false); - }); - - it('should return false if the input is null', () => { - const result = isJSExpression(null); - - expect(result).toBe(false); - }); - - it('should return false if the input is undefined', () => { - const result = isJSExpression(undefined); - - expect(result).toBe(false); - }); - - // 添加其他需要的测试 -}); diff --git a/packages/utils/tests/src/check-types/is-jsslot.test.ts b/packages/utils/tests/src/check-types/is-jsslot.test.ts deleted file mode 100644 index 5c130cddf..000000000 --- a/packages/utils/tests/src/check-types/is-jsslot.test.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { isJSSlot } from '../../../src/check-types/is-jsslot'; -import { IPublicTypeJSSlot } from '@alilc/lowcode-types'; - -describe('isJSSlot', () => { - it('should return true when input is of type IPublicTypeJSSlot', () => { - const input: IPublicTypeJSSlot = { - type: 'JSSlot', - // other properties of IPublicTypeJSSlot - }; - - const result = isJSSlot(input); - - expect(result).toBe(true); - }); - - it('should return false when input is not of type IPublicTypeJSSlot', () => { - const input = { - type: 'OtherType', - // other properties - }; - - const result = isJSSlot(input); - - expect(result).toBe(false); - }); - - it('should return false when input is null or undefined', () => { - const input1 = null; - const input2 = undefined; - - const result1 = isJSSlot(input1); - const result2 = isJSSlot(input2); - - expect(result1).toBe(false); - expect(result2).toBe(false); - }); -}); diff --git a/packages/utils/tests/src/check-types/is-location-children-detail.test.ts b/packages/utils/tests/src/check-types/is-location-children-detail.test.ts deleted file mode 100644 index f209e8e63..000000000 --- a/packages/utils/tests/src/check-types/is-location-children-detail.test.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { isLocationChildrenDetail } from '../../../src/check-types/is-location-children-detail'; -import { IPublicTypeLocationChildrenDetail, IPublicTypeLocationDetailType } from '@alilc/lowcode-types'; - -describe('isLocationChildrenDetail', () => { - it('should return true when obj is IPublicTypeLocationChildrenDetail', () => { - const obj: IPublicTypeLocationChildrenDetail = { - type: IPublicTypeLocationDetailType.Children, - // 添加其他必要的属性 - }; - - expect(isLocationChildrenDetail(obj)).toBe(true); - }); - - it('should return false when obj is not IPublicTypeLocationChildrenDetail', () => { - const obj = { - type: 'other', - // 添加其他必要的属性 - }; - - expect(isLocationChildrenDetail(obj)).toBe(false); - expect(isLocationChildrenDetail(null)).toBe(false); - expect(isLocationChildrenDetail(undefined)).toBe(false); - expect(isLocationChildrenDetail('string')).toBe(false); - expect(isLocationChildrenDetail(0)).toBe(false); - expect(isLocationChildrenDetail(2)).toBe(false); - }); -}); diff --git a/packages/utils/tests/src/check-types/is-location-data.test.ts b/packages/utils/tests/src/check-types/is-location-data.test.ts deleted file mode 100644 index ba2e2c8be..000000000 --- a/packages/utils/tests/src/check-types/is-location-data.test.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { isLocationData } from '../../../src/check-types/is-location-data'; -import { IPublicTypeLocationData } from '@alilc/lowcode-types'; - -describe('isLocationData', () => { - it('should return true when obj is valid location data', () => { - const obj: IPublicTypeLocationData = { - target: 'some target', - detail: 'some detail', - }; - - const result = isLocationData(obj); - - expect(result).toBe(true); - }); - - it('should return false when obj is missing target or detail', () => { - const obj1 = { - target: 'some target', - // missing detail - }; - - const obj2 = { - // missing target - detail: 'some detail', - }; - - const result1 = isLocationData(obj1); - const result2 = isLocationData(obj2); - - expect(result1).toBe(false); - expect(result2).toBe(false); - }); - - it('should return false when obj is null or undefined', () => { - const obj1 = null; - const obj2 = undefined; - - const result1 = isLocationData(obj1); - const result2 = isLocationData(obj2); - - expect(result1).toBe(false); - expect(result2).toBe(false); - }); -}); diff --git a/packages/utils/tests/src/check-types/is-lowcode-component-type.test.ts b/packages/utils/tests/src/check-types/is-lowcode-component-type.test.ts deleted file mode 100644 index 35b76f00b..000000000 --- a/packages/utils/tests/src/check-types/is-lowcode-component-type.test.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { isLowCodeComponentType } from '../../../src/check-types/is-lowcode-component-type'; -import { IPublicTypeLowCodeComponent, IPublicTypeProCodeComponent } from '@alilc/lowcode-types'; - -describe('isLowCodeComponentType', () => { - test('should return true for a low code component type', () => { - const desc: IPublicTypeLowCodeComponent = { - // create a valid low code component description - }; - - expect(isLowCodeComponentType(desc)).toBe(true); - }); - - test('should return false for a pro code component type', () => { - const desc: IPublicTypeProCodeComponent = { - // create a valid pro code component description - package: 'pro-code' - }; - - expect(isLowCodeComponentType(desc)).toBe(false); - }); -}); diff --git a/packages/utils/tests/src/check-types/is-lowcode-project-schema.test.ts b/packages/utils/tests/src/check-types/is-lowcode-project-schema.test.ts deleted file mode 100644 index bb750ed88..000000000 --- a/packages/utils/tests/src/check-types/is-lowcode-project-schema.test.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { isLowcodeProjectSchema } from "../../../src/check-types/is-lowcode-project-schema"; - -describe("isLowcodeProjectSchema", () => { - it("should return false when data is null", () => { - const result = isLowcodeProjectSchema(null); - expect(result).toBe(false); - }); - - it("should return false when data is undefined", () => { - const result = isLowcodeProjectSchema(undefined); - expect(result).toBe(false); - }); - - it("should return false when data is not an object", () => { - const result = isLowcodeProjectSchema("not an object"); - expect(result).toBe(false); - }); - - it("should return false when componentsTree is missing", () => { - const data = { someKey: "someValue" }; - const result = isLowcodeProjectSchema(data); - expect(result).toBe(false); - }); - - it("should return false when componentsTree is an empty array", () => { - const data = { componentsTree: [] }; - const result = isLowcodeProjectSchema(data); - expect(result).toBe(false); - }); - - it("should return false when the first element of componentsTree is not a component schema", () => { - const data = { componentsTree: [{}] }; - const result = isLowcodeProjectSchema(data); - expect(result).toBe(false); - }); - - it("should return true when all conditions are met", () => { - const data = { componentsTree: [{ prop: "value", componentName: 'Component' }] }; - const result = isLowcodeProjectSchema(data); - expect(result).toBe(true); - }); -}); diff --git a/packages/utils/tests/src/check-types/is-node-schema.test.ts b/packages/utils/tests/src/check-types/is-node-schema.test.ts deleted file mode 100644 index b5a4e39ac..000000000 --- a/packages/utils/tests/src/check-types/is-node-schema.test.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { isNodeSchema } from '../../../src/check-types/is-node-schema'; - -describe('isNodeSchema', () => { - // 测试正常情况 - it('should return true for valid IPublicTypeNodeSchema', () => { - const validData = { - componentName: 'Component', - isNode: false, - }; - expect(isNodeSchema(validData)).toBe(true); - }); - - // 测试 null 或 undefined - it('should return false for null or undefined', () => { - expect(isNodeSchema(null)).toBe(false); - expect(isNodeSchema(undefined)).toBe(false); - }); - - // 测试没有componentName属性的情况 - it('should return false if componentName is missing', () => { - const invalidData = { - isNode: false, - }; - expect(isNodeSchema(invalidData)).toBe(false); - }); - - // 测试isNode为true的情况 - it('should return false if isNode is true', () => { - const invalidData = { - componentName: 'Component', - isNode: true, - }; - expect(isNodeSchema(invalidData)).toBe(false); - }); - - // 测试其他数据类型的情况 - it('should return false for other data types', () => { - expect(isNodeSchema('string')).toBe(false); - expect(isNodeSchema(123)).toBe(false); - expect(isNodeSchema([])).toBe(false); - expect(isNodeSchema({})).toBe(false); - }); -}); diff --git a/packages/utils/tests/src/check-types/is-node.test.ts b/packages/utils/tests/src/check-types/is-node.test.ts deleted file mode 100644 index d6d8dfc03..000000000 --- a/packages/utils/tests/src/check-types/is-node.test.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { isNode } from '../../../src/check-types/is-node'; - -describe('isNode', () => { - it('should return true for a valid node', () => { - const node = { isNode: true }; - expect(isNode(node)).toBeTruthy(); - }); - - it('should return false for an invalid node', () => { - const node = { isNode: false }; - expect(isNode(node)).toBeFalsy(); - }); - - it('should return false for an undefined node', () => { - expect(isNode(undefined)).toBeFalsy(); - }); - - // Add more test cases if needed -}); diff --git a/packages/utils/tests/src/check-types/is-procode-component-type.test.ts b/packages/utils/tests/src/check-types/is-procode-component-type.test.ts deleted file mode 100644 index 58f435b98..000000000 --- a/packages/utils/tests/src/check-types/is-procode-component-type.test.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { isProCodeComponentType } from '../../../src/check-types/is-procode-component-type'; - -describe('isProCodeComponentType', () => { - it('should return true if the given desc object contains "package" property', () => { - const desc = { package: 'packageName' }; - expect(isProCodeComponentType(desc)).toBe(true); - }); - - it('should return false if the given desc object does not contain "package" property', () => { - const desc = { name: 'componentName' }; - expect(isProCodeComponentType(desc)).toBe(false); - }); -}); diff --git a/packages/utils/tests/src/check-types/is-project-schema.test.ts b/packages/utils/tests/src/check-types/is-project-schema.test.ts deleted file mode 100644 index 0ec3f4740..000000000 --- a/packages/utils/tests/src/check-types/is-project-schema.test.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { IPublicTypeProjectSchema } from "@alilc/lowcode-types"; -import { isProjectSchema } from "../../../src/check-types/is-project-schema"; - -describe("isProjectSchema", () => { - it("should return true if data has componentsTree property", () => { - const data: IPublicTypeProjectSchema = { - // ... - componentsTree: { - // ... - }, - }; - expect(isProjectSchema(data)).toBe(true); - }); - - it("should return false if data does not have componentsTree property", () => { - const data = { - // ... - }; - expect(isProjectSchema(data)).toBe(false); - }); - - it("should return false if data is null or undefined", () => { - expect(isProjectSchema(null)).toBe(false); - expect(isProjectSchema(undefined)).toBe(false); - }); - - // 更多的测试用例... -}); diff --git a/packages/utils/tests/src/check-types/is-required-prop-type.test.ts b/packages/utils/tests/src/check-types/is-required-prop-type.test.ts deleted file mode 100644 index 25515f9aa..000000000 --- a/packages/utils/tests/src/check-types/is-required-prop-type.test.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { isRequiredPropType } from '../../../src'; - -describe('test isRequiredType', () => { - it('should work', () => { - expect(isRequiredPropType(null)).toBeFalsy(); - expect(isRequiredPropType(undefined)).toBeFalsy(); - expect(isRequiredPropType({})).toBeFalsy(); - expect(isRequiredPropType({ type: 'any other type' })).toBeFalsy(); - expect(isRequiredPropType('string')).toBeFalsy(); - expect(isRequiredPropType({ type: 'string' })).toBeTruthy(); - expect(isRequiredPropType({ type: 'string', isRequired: true })).toBeTruthy(); - }); -}) diff --git a/packages/utils/tests/src/check-types/is-setter-config.test.ts b/packages/utils/tests/src/check-types/is-setter-config.test.ts deleted file mode 100644 index eee234658..000000000 --- a/packages/utils/tests/src/check-types/is-setter-config.test.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { isSetterConfig } from '../../../src/check-types/is-setter-config'; - -describe('isSetterConfig', () => { - test('should return true for valid setter config', () => { - const config = { - componentName: 'MyComponent', - // Add other required properties here - }; - - expect(isSetterConfig(config)).toBe(true); - }); - - test('should return false for invalid setter config', () => { - const config = { - // Missing componentName property - }; - - expect(isSetterConfig(config)).toBe(false); - expect(isSetterConfig(null)).toBe(false); - expect(isSetterConfig(undefined)).toBe(false); - expect(isSetterConfig(0)).toBe(false); - expect(isSetterConfig(2)).toBe(false); - }); - - // Add more test cases for different scenarios you want to cover -}); diff --git a/packages/utils/tests/src/check-types/is-setting-field.test.ts b/packages/utils/tests/src/check-types/is-setting-field.test.ts deleted file mode 100644 index 5f9bbd623..000000000 --- a/packages/utils/tests/src/check-types/is-setting-field.test.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { isSettingField } from "../../../src/check-types/is-setting-field"; - -describe("isSettingField", () => { - it("should return true for an object that has isSettingField property", () => { - const obj = { isSettingField: true }; - expect(isSettingField(obj)).toBe(true); - }); - - it("should return false for an object that does not have isSettingField property", () => { - const obj = { foo: "bar" }; - expect(isSettingField(obj)).toBe(false); - }); - - it("should return false for a falsy value", () => { - const obj = null; - expect(isSettingField(obj)).toBe(false); - }); -}); diff --git a/packages/utils/tests/src/check-types/is-title-config.test.ts b/packages/utils/tests/src/check-types/is-title-config.test.ts deleted file mode 100644 index 4aa6d219c..000000000 --- a/packages/utils/tests/src/check-types/is-title-config.test.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { isTitleConfig } from '../../../src/check-types/is-title-config'; - -describe('isTitleConfig', () => { - it('should return true for valid config object', () => { - const config = { title: 'My Title' }; - expect(isTitleConfig(config)).toBe(true); - }); - - it('should return false for invalid config object', () => { - const config = { title: 'My Title', type: 'i18n' , i18nData: {} }; - expect(isTitleConfig(config)).toBe(false); - }); - - it('should return false for non-object input', () => { - const config = 'invalid'; - expect(isTitleConfig(config)).toBe(false); - }); -}); diff --git a/packages/utils/tests/src/clone-deep.test.ts b/packages/utils/tests/src/clone-deep.test.ts deleted file mode 100644 index 58fabc6f6..000000000 --- a/packages/utils/tests/src/clone-deep.test.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { cloneDeep } from '../../src/clone-deep'; - -describe('cloneDeep', () => { - it('should clone null', () => { - const src = null; - expect(cloneDeep(src)).toBeNull(); - }); - - it('should clone undefined', () => { - const src = undefined; - expect(cloneDeep(src)).toBeUndefined(); - }); - - it('should clone an array', () => { - const src = [1, 2, 3, 4]; - expect(cloneDeep(src)).toEqual(src); - }); - - it('should clone an object', () => { - const src = { name: 'John', age: 25 }; - expect(cloneDeep(src)).toEqual(src); - }); - - it('should deep clone nested objects', () => { - const src = { person: { name: 'John', age: 25 } }; - const cloned = cloneDeep(src); - expect(cloned).toEqual(src); - expect(cloned.person).not.toBe(src.person); - }); -}); \ No newline at end of file diff --git a/packages/utils/tests/src/clone-enumerable-property.test.ts b/packages/utils/tests/src/clone-enumerable-property.test.ts deleted file mode 100644 index 2eff09e44..000000000 --- a/packages/utils/tests/src/clone-enumerable-property.test.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { cloneEnumerableProperty } from '../../src/clone-enumerable-property'; - -describe('cloneEnumerableProperty', () => { - test('should clone enumerable properties from origin to target', () => { - // Arrange - const target = {}; - const origin = { prop1: 1, prop2: 'hello', prop3: true }; - - // Act - const result = cloneEnumerableProperty(target, origin); - - // Assert - expect(result).toBe(target); - expect(result).toEqual(origin); - }); - - test('should exclude properties specified in excludePropertyNames', () => { - // Arrange - const target = {}; - const origin = { prop1: 1, prop2: 'hello', prop3: true }; - const excludePropertyNames = ['prop2']; - - // Act - const result = cloneEnumerableProperty(target, origin, excludePropertyNames); - - // Assert - expect(result).toBe(target); - expect(result).toEqual({ prop1: 1, prop3: true }); - }); -}); \ No newline at end of file diff --git a/packages/utils/tests/src/create-content.test.tsx b/packages/utils/tests/src/create-content.test.tsx deleted file mode 100644 index c41fb0f0d..000000000 --- a/packages/utils/tests/src/create-content.test.tsx +++ /dev/null @@ -1,38 +0,0 @@ -import React from 'react'; -import { createContent } from '../../src/create-content'; - -const MyComponent = () => { - return
MyComponent
-} -describe('createContent', () => { - test('should return the same content if it is a valid React element', () => { - const content =
Hello
; - const result = createContent(content); - - expect(result).toEqual(content); - }); - - test('should clone the element with props if props are provided', () => { - const content =
; - const props = { className: 'my-class' }; - const result = createContent(content, props); - - expect(result.props).toEqual(props); - }); - - test('should create an element with props if the content is a React component', () => { - const content = MyComponent; - const props = { className: 'my-class' }; - const result = createContent(content, props); - - expect(result.type).toEqual(content); - expect(result.props).toEqual(props); - }); - - test('should return the content if it is not a React element or a React component', () => { - const content = 'Hello'; - const result = createContent(content); - - expect(result).toEqual(content); - }); -}); diff --git a/packages/utils/tests/src/create-defer.test.ts b/packages/utils/tests/src/create-defer.test.ts deleted file mode 100644 index c6ab9207a..000000000 --- a/packages/utils/tests/src/create-defer.test.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { createDefer } from '../../src/create-defer'; - -describe('createDefer', () => { - it('should resolve with given value', async () => { - const defer = createDefer(); - defer.resolve(42); - const result = await defer.promise(); - expect(result).toBe(42); - }); - - it('should reject with given reason', async () => { - const defer = createDefer(); - defer.reject('error'); - await expect(defer.promise()).rejects.toEqual('error'); - }); -}); diff --git a/packages/utils/tests/src/is-object.test.ts b/packages/utils/tests/src/is-object.test.ts deleted file mode 100644 index 7ae984b8f..000000000 --- a/packages/utils/tests/src/is-object.test.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { isObject, isI18NObject } from '../../src/is-object'; - -describe('isObject', () => { - it('should return true for an object', () => { - const obj = { key: 'value' }; - const result = isObject(obj); - expect(result).toBe(true); - }); - - it('should return false for null', () => { - const result = isObject(null); - expect(result).toBe(false); - }); - - it('should return false for a non-object value', () => { - const value = 42; // Not an object - const result = isObject(value); - expect(result).toBe(false); - }); -}); - -describe('isI18NObject', () => { - it('should return true for an I18N object', () => { - const i18nObject = { type: 'i18n', data: 'some data' }; - const result = isI18NObject(i18nObject); - expect(result).toBe(true); - }); - - it('should return false for a non-I18N object', () => { - const nonI18nObject = { type: 'other', data: 'some data' }; - const result = isI18NObject(nonI18nObject); - expect(result).toBe(false); - }); - - it('should return false for null', () => { - const result = isI18NObject(null); - expect(result).toBe(false); - }); - - it('should return false for a non-object value', () => { - const value = 42; // Not an object - const result = isI18NObject(value); - expect(result).toBe(false); - }); -}); diff --git a/packages/utils/tests/src/is-react.test.tsx b/packages/utils/tests/src/is-react.test.tsx deleted file mode 100644 index 9ed2bd6c3..000000000 --- a/packages/utils/tests/src/is-react.test.tsx +++ /dev/null @@ -1,316 +0,0 @@ -import React, { Component, createElement } from "react"; -import { - isReactComponent, - wrapReactClass, - isForwardOrMemoForward, - isMemoType, - isForwardRefType, - acceptsRef, - isReactClass, - REACT_MEMO_TYPE, - REACT_FORWARD_REF_TYPE, - } from "../../src/is-react"; - -class reactDemo extends React.Component { - -} - -const reactMemo = React.memo(reactDemo); - -const reactForwardRef = React.forwardRef((props, ref): any => { - return ''; -}); - -describe('is-react-ut', () => { - it('isReactComponent', () => { - expect(isReactComponent(null)).toBeFalsy(); - expect(isReactComponent(() => {})).toBeTruthy(); - expect(isReactComponent({ - $$typeof: Symbol.for('react.memo') - })).toBeTruthy(); - expect(isReactComponent({ - $$typeof: Symbol.for('react.forward_ref') - })).toBeTruthy(); - expect(isReactComponent(reactDemo)).toBeTruthy(); - expect(isReactComponent(reactMemo)).toBeTruthy(); - expect(isReactComponent(reactForwardRef)).toBeTruthy(); - - }); - - it('wrapReactClass', () => { - const wrap = wrapReactClass(() => {}); - expect(isReactComponent(wrap)).toBeTruthy(); - - const fun = () => {}; - fun.displayName = 'mock'; - expect(wrapReactClass(fun).displayName).toBe('mock'); - }) -}) - -describe('wrapReactClass', () => { - it('should wrap a FunctionComponent', () => { - // Create a mock FunctionComponent - const MockComponent: React.FunctionComponent = (props) => { - return
{props.children}
; - }; - - // Wrap the FunctionComponent using wrapReactClass - const WrappedComponent = wrapReactClass(MockComponent); - const instance = new WrappedComponent(); - - // Check if the WrappedComponent extends Component - expect(instance instanceof React.Component).toBe(true); - }); - - it('should render the FunctionComponent with props', () => { - // Create a mock FunctionComponent - const MockComponent: React.FunctionComponent = (props) => { - return
{props.children}
; - }; - - MockComponent.displayName = 'FunctionComponent'; - - // Wrap the FunctionComponent using wrapReactClass - const WrappedComponent = wrapReactClass(MockComponent); - - // Create some test props - const testProps = { prop1: 'value1', prop2: 'value2' }; - - // Render the WrappedComponent with test props - const rendered = createElement(WrappedComponent, testProps, 'Child Text'); - - // Check if the WrappedComponent renders the FunctionComponent with props - expect(rendered).toMatchSnapshot(); - }); -}); - -describe('isReactComponent', () => { - it('should identify a class component as a React component', () => { - class ClassComponent extends React.Component { - render() { - return
Class Component
; - } - } - - expect(isReactComponent(ClassComponent)).toBe(true); - }); - - it('should identify a functional component as a React component', () => { - const FunctionalComponent = () => { - return
Functional Component
; - }; - - expect(isReactComponent(FunctionalComponent)).toBe(true); - }); - - it('should identify a forward ref component as a React component', () => { - const ForwardRefComponent = React.forwardRef((props, ref) => { - return
Forward Ref Component
; - }); - - expect(isReactComponent(ForwardRefComponent)).toBe(true); - }); - - it('should identify a memo component as a React component', () => { - const MemoComponent = React.memo(() => { - return
Memo Component
; - }); - - expect(isReactComponent(MemoComponent)).toBe(true); - }); - - it('should return false for non-React components', () => { - const plainObject = { prop: 'value' }; - const notAComponent = 'Not a component'; - - expect(isReactComponent(plainObject)).toBe(false); - expect(isReactComponent(notAComponent)).toBe(false); - }); - - it('should return false for null or undefined', () => { - const nullValue = null; - const undefinedValue = undefined; - - expect(isReactComponent(nullValue)).toBe(false); - expect(isReactComponent(undefinedValue)).toBe(false); - }); -}); - -describe('isForwardOrMemoForward', () => { - it('should return true for a forwardRef component', () => { - const forwardRefComponent = React.forwardRef(() => { - return
ForwardRef Component
; - }); - - expect(isForwardOrMemoForward(forwardRefComponent)).toBe(true); - }); - - it('should return true for a memoized forwardRef component', () => { - const forwardRefComponent = React.forwardRef(() => { - return
ForwardRef Component
; - }); - - const memoizedComponent = React.memo(forwardRefComponent); - - expect(isForwardOrMemoForward(memoizedComponent)).toBe(true); - }); - - it('should return false for a memoized component that is not a forwardRef', () => { - const memoizedComponent = React.memo(() => { - return
Memoized Component
; - }); - - expect(isForwardOrMemoForward(memoizedComponent)).toBe(false); - }); - - it('should return false for a plain object', () => { - const plainObject = { prop: 'value' }; - - expect(isForwardOrMemoForward(plainObject)).toBe(false); - }); - - it('should return false for null or undefined', () => { - const nullValue = null; - const undefinedValue = undefined; - - expect(isForwardOrMemoForward(nullValue)).toBe(false); - expect(isForwardOrMemoForward(undefinedValue)).toBe(false); - }); -}); - -describe('isMemoType', () => { - it('should return true for an object with $$typeof matching REACT_MEMO_TYPE', () => { - const memoTypeObject = { $$typeof: REACT_MEMO_TYPE }; - - expect(isMemoType(memoTypeObject)).toBe(true); - }); - - it('should return false for an object with $$typeof not matching REACT_MEMO_TYPE', () => { - const otherTypeObject = { $$typeof: Symbol.for('other.type') }; - - expect(isMemoType(otherTypeObject)).toBe(false); - }); - - it('should return false for an object with no $$typeof property', () => { - const noTypeObject = { key: 'value' }; - - expect(isMemoType(noTypeObject)).toBe(false); - }); - - it('should return false for null or undefined', () => { - const nullValue = null; - const undefinedValue = undefined; - - expect(isMemoType(nullValue)).toBe(false); - expect(isMemoType(undefinedValue)).toBe(false); - }); -}); - -describe('isForwardRefType', () => { - it('should return true for an object with $$typeof matching REACT_FORWARD_REF_TYPE', () => { - const forwardRefTypeObject = { $$typeof: REACT_FORWARD_REF_TYPE }; - - expect(isForwardRefType(forwardRefTypeObject)).toBe(true); - }); - - it('should return false for an object with $$typeof not matching REACT_FORWARD_REF_TYPE', () => { - const otherTypeObject = { $$typeof: Symbol.for('other.type') }; - - expect(isForwardRefType(otherTypeObject)).toBe(false); - }); - - it('should return false for an object with no $$typeof property', () => { - const noTypeObject = { key: 'value' }; - - expect(isForwardRefType(noTypeObject)).toBe(false); - }); - - it('should return false for null or undefined', () => { - const nullValue = null; - const undefinedValue = undefined; - - expect(isForwardRefType(nullValue)).toBe(false); - expect(isForwardRefType(undefinedValue)).toBe(false); - }); -}); - -describe('acceptsRef', () => { - it('should return true for an object with isReactComponent in its prototype', () => { - const objWithIsReactComponent = { - prototype: { - isReactComponent: true, - }, - }; - - expect(acceptsRef(objWithIsReactComponent)).toBe(true); - }); - - it('should return true for an object that is forwardRef or memoized forwardRef', () => { - const forwardRefObject = React.forwardRef(() => { - return null; - }); - - const memoizedForwardRefObject = React.memo(forwardRefObject); - - expect(acceptsRef(forwardRefObject)).toBe(true); - expect(acceptsRef(memoizedForwardRefObject)).toBe(true); - }); - - it('should return false for an object without isReactComponent in its prototype', () => { - const objWithoutIsReactComponent = { - prototype: { - someOtherProperty: true, - }, - }; - - expect(acceptsRef(objWithoutIsReactComponent)).toBe(false); - }); - - it('should return false for null or undefined', () => { - const nullValue = null; - const undefinedValue = undefined; - - expect(acceptsRef(nullValue)).toBe(false); - expect(acceptsRef(undefinedValue)).toBe(false); - }); -}); - -describe('isReactClass', () => { - it('should return true for an object with isReactComponent in its prototype', () => { - class ReactClassComponent extends Component { - render() { - return null; - } - } - - expect(isReactClass(ReactClassComponent)).toBe(true); - }); - - it('should return true for an object with Component in its prototype chain', () => { - class CustomComponent extends Component { - render() { - return null; - } - } - - expect(isReactClass(CustomComponent)).toBe(true); - }); - - it('should return false for an object without isReactComponent in its prototype', () => { - class NonReactComponent { - render() { - return null; - } - } - - expect(isReactClass(NonReactComponent)).toBe(false); - }); - - it('should return false for null or undefined', () => { - const nullValue = null; - const undefinedValue = undefined; - - expect(isReactClass(nullValue)).toBe(false); - expect(isReactClass(undefinedValue)).toBe(false); - }); -}); \ No newline at end of file diff --git a/packages/utils/tests/src/is-shaken.test.ts b/packages/utils/tests/src/is-shaken.test.ts deleted file mode 100644 index 35a27af5f..000000000 --- a/packages/utils/tests/src/is-shaken.test.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { isShaken } from '../../src/is-shaken'; - -describe('isShaken', () => { - it('should return true if e1 has shaken property', () => { - const e1: any = { shaken: true }; - const e2: MouseEvent | DragEvent = { target: null } as MouseEvent | DragEvent; - - expect(isShaken(e1, e2)).toBe(true); - }); - - it('should return true if e1.target and e2.target are different', () => { - const e1: MouseEvent | DragEvent = { target: {} } as MouseEvent | DragEvent; - const e2: MouseEvent | DragEvent = { target: {} } as MouseEvent | DragEvent; - - expect(isShaken(e1, e2)).toBe(true); - }); - - it('should return false if e1 and e2 targets are the same and distance is less than SHAKE_DISTANCE', () => { - const target = {}; - const e1: MouseEvent | DragEvent = { target: target } as MouseEvent | DragEvent; - const e2: MouseEvent | DragEvent = { target: target } as MouseEvent | DragEvent; - - // Assuming SHAKE_DISTANCE is 100 - e1.clientY = 50; - e2.clientY = 50; - - e1.clientX = 60; - e2.clientX = 60; - - expect(isShaken(e1, e2)).toBe(false); - }); - - it('should return true if e1 and e2 targets are the same and distance is greater than SHAKE_DISTANCE', () => { - const e1: MouseEvent | DragEvent = { target: {} } as MouseEvent | DragEvent; - const e2: MouseEvent | DragEvent = { target: {} } as MouseEvent | DragEvent; - - // Assuming SHAKE_DISTANCE is 100 - e1.clientY = 50; - e1.clientX = 50; - e2.clientY = 200; - e2.clientX = 200; - - expect(isShaken(e1, e2)).toBe(true); - }); -}); diff --git a/packages/utils/tests/src/misc.test.ts b/packages/utils/tests/src/misc.test.ts deleted file mode 100644 index 251466150..000000000 --- a/packages/utils/tests/src/misc.test.ts +++ /dev/null @@ -1,326 +0,0 @@ -import { - isVariable, - isUseI18NSetter, - convertToI18NObject, - isString, - waitForThing, - arrShallowEquals, - isFromVC, - executePendingFn, - compatStage, - invariant, - isRegExp, - shouldUseVariableSetter, -} from '../../src/misc'; -import { IPublicModelComponentMeta } from '@alilc/lowcode-types'; - -describe('isVariable', () => { - it('should return true for a variable object', () => { - const variable = { type: 'variable', variable: 'foo', value: 'bar' }; - const result = isVariable(variable); - expect(result).toBe(true); - }); - - it('should return false for non-variable objects', () => { - const obj = { type: 'object' }; - const result = isVariable(obj); - expect(result).toBe(false); - }); -}); - -describe('isUseI18NSetter', () => { - it('should return true for a property with I18nSetter', () => { - const prototype = { options: { configure: [{ name: 'propName', setter: { type: { displayName: 'I18nSetter' } } }] } }; - const propName = 'propName'; - const result = isUseI18NSetter(prototype, propName); - expect(result).toBe(true); - }); - - it('should return false for a property without I18nSetter', () => { - const prototype = { options: { configure: [{ name: 'propName', setter: { type: { displayName: 'OtherSetter' } } }] } }; - const propName = 'propName'; - const result = isUseI18NSetter(prototype, propName); - expect(result).toBe(false); - }); -}); - -describe('convertToI18NObject', () => { - it('should return the input if it is already an I18N object', () => { - const i18nObject = { type: 'i18n', use: 'en', en: 'Hello' }; - const result = convertToI18NObject(i18nObject); - expect(result).toEqual(i18nObject); - }); - - it('should convert a string to an I18N object', () => { - const inputString = 'Hello'; - const result = convertToI18NObject(inputString); - const expectedOutput = { type: 'i18n', use: 'zh-CN', 'zh-CN': inputString }; - expect(result).toEqual(expectedOutput); - }); -}); - -describe('isString', () => { - it('should return true for a string', () => { - const stringValue = 'Hello, world!'; - const result = isString(stringValue); - expect(result).toBe(true); - }); - - it('should return true for an empty string', () => { - const emptyString = ''; - const result = isString(emptyString); - expect(result).toBe(true); - }); - - it('should return false for a number', () => { - const numberValue = 42; // Not a string - const result = isString(numberValue); - expect(result).toBe(false); - }); - - it('should return false for an object', () => { - const objectValue = { key: 'value' }; // Not a string - const result = isString(objectValue); - expect(result).toBe(false); - }); - - it('should return false for null', () => { - const result = isString(null); - expect(result).toBe(false); - }); - - it('should return false for undefined', () => { - const undefinedValue = undefined; - const result = isString(undefinedValue); - expect(result).toBe(false); - }); - - it('should return false for a boolean', () => { - const booleanValue = true; // Not a string - const result = isString(booleanValue); - expect(result).toBe(false); - }); -}); - -describe('waitForThing', () => { - it('should resolve immediately if the thing is available', async () => { - const obj = { prop: 'value' }; - const path = 'prop'; - const result = await waitForThing(obj, path); - expect(result).toBe('value'); - }); - - it('should resolve after a delay if the thing becomes available', async () => { - const obj = { prop: undefined }; - const path = 'prop'; - const delay = 100; // Adjust the delay as needed - setTimeout(() => { - obj.prop = 'value'; - }, delay); - - const result = await waitForThing(obj, path); - expect(result).toBe('value'); - }); -}); - -describe('arrShallowEquals', () => { - it('should return true for two empty arrays', () => { - const arr1 = []; - const arr2 = []; - const result = arrShallowEquals(arr1, arr2); - expect(result).toBe(true); - }); - - it('should return true for two arrays with the same elements in the same order', () => { - const arr1 = [1, 2, 3]; - const arr2 = [1, 2, 3]; - const result = arrShallowEquals(arr1, arr2); - expect(result).toBe(true); - }); - - it('should return true for two arrays with the same elements in a different order', () => { - const arr1 = [1, 2, 3]; - const arr2 = [3, 2, 1]; - const result = arrShallowEquals(arr1, arr2); - expect(result).toBe(true); - }); - - it('should return false for two arrays with different lengths', () => { - const arr1 = [1, 2, 3]; - const arr2 = [1, 2]; - const result = arrShallowEquals(arr1, arr2); - expect(result).toBe(false); - }); - - it('should return false for one array and a non-array', () => { - const arr1 = [1, 2, 3]; - const nonArray = 'not an array'; - const result = arrShallowEquals(arr1, nonArray); - expect(result).toBe(false); - }); - - it('should return false for two arrays with different elements', () => { - const arr1 = [1, 2, 3]; - const arr2 = [3, 4, 5]; - const result = arrShallowEquals(arr1, arr2); - expect(result).toBe(false); - }); - - it('should return true for arrays with duplicate elements', () => { - const arr1 = [1, 2, 2, 3]; - const arr2 = [2, 3, 3, 1]; - const result = arrShallowEquals(arr1, arr2); - expect(result).toBe(true); - }); -}); - -describe('isFromVC', () => { - it('should return true when advanced configuration is present', () => { - // Create a mock meta object with advanced configuration - const meta: IPublicModelComponentMeta = { - getMetadata: () => ({ configure: { advanced: true } }), - }; - - const result = isFromVC(meta); - - expect(result).toBe(true); - }); - - it('should return false when advanced configuration is not present', () => { - // Create a mock meta object without advanced configuration - const meta: IPublicModelComponentMeta = { - getMetadata: () => ({ configure: { advanced: false } }), - }; - - const result = isFromVC(meta); - - expect(result).toBe(false); - }); - - it('should return false when meta is undefined', () => { - const meta: IPublicModelComponentMeta | undefined = undefined; - - const result = isFromVC(meta); - - expect(result).toBe(false); - }); - - it('should return false when meta does not have configure information', () => { - // Create a mock meta object without configure information - const meta: IPublicModelComponentMeta = { - getMetadata: () => ({}), - }; - - const result = isFromVC(meta); - - expect(result).toBe(false); - }); - - it('should return false when configure.advanced is not present', () => { - // Create a mock meta object with incomplete configure information - const meta: IPublicModelComponentMeta = { - getMetadata: () => ({ configure: {} }), - }; - - const result = isFromVC(meta); - - expect(result).toBe(false); - }); -}); - -describe('executePendingFn', () => { - it('should execute the provided function after the specified timeout', async () => { - // Mock the function to execute - const fn = jest.fn(); - - // Call executePendingFn with the mocked function and a short timeout - executePendingFn(fn, 100); - - // Ensure the function has not been called immediately - expect(fn).not.toHaveBeenCalled(); - - // Wait for the specified timeout - await new Promise(resolve => setTimeout(resolve, 100)); - - // Ensure the function has been called after the timeout - expect(fn).toHaveBeenCalled(); - }); - - it('should execute the provided function with a default timeout if not specified', async () => { - // Mock the function to execute - const fn = jest.fn(); - - // Call executePendingFn with the mocked function without specifying a timeout - executePendingFn(fn); - - // Ensure the function has not been called immediately - expect(fn).not.toHaveBeenCalled(); - - // Wait for the default timeout (2000 milliseconds) - await new Promise(resolve => setTimeout(resolve, 2000)); - - // Ensure the function has been called after the default timeout - expect(fn).toHaveBeenCalled(); - }); -}); - -describe('compatStage', () => { - it('should convert a number to an enum stage', () => { - const result = compatStage(3); - expect(result).toBe('save'); - }); - - it('should warn about the deprecated usage', () => { - const warnSpy = jest.spyOn(console, 'warn'); - const result = compatStage(2); - expect(result).toBe('serilize'); - expect(warnSpy).toHaveBeenCalledWith( - 'stage 直接指定为数字的使用方式已经过时,将在下一版本移除,请直接使用 IPublicEnumTransformStage.Render|Serilize|Save|Clone|Init|Upgrade' - ); - warnSpy.mockRestore(); - }); - - it('should return the enum stage if it is already an enum', () => { - const result = compatStage('render'); - expect(result).toBe('render'); - }); -}); - -describe('invariant', () => { - it('should not throw an error if the check is true', () => { - expect(() => invariant(true, 'Test invariant', 'thing')).not.toThrow(); - }); - - it('should throw an error if the check is false', () => { - expect(() => invariant(false, 'Test invariant', 'thing')).toThrowError( - "Invariant failed: Test invariant in 'thing'" - ); - }); -}); - -describe('isRegExp', () => { - it('should return true for a valid RegExp', () => { - const regex = /test/; - const result = isRegExp(regex); - expect(result).toBe(true); - }); - - it('should return false for a non-RegExp object', () => { - const nonRegExp = { test: /test/ }; - const result = isRegExp(nonRegExp); - expect(result).toBe(false); - }); - - it('should return false for null', () => { - const result = isRegExp(null); - expect(result).toBe(false); - }); -}); - -it('shouldUseVariableSetter', () => { - expect(shouldUseVariableSetter(false, true)).toBeFalsy(); - expect(shouldUseVariableSetter(true, true)).toBeTruthy(); - expect(shouldUseVariableSetter(true, false)).toBeTruthy(); - expect(shouldUseVariableSetter(undefined, false)).toBeFalsy(); - expect(shouldUseVariableSetter(undefined, true)).toBeTruthy(); -}); \ No newline at end of file diff --git a/packages/utils/tests/src/navtive-selection.test.ts b/packages/utils/tests/src/navtive-selection.test.ts deleted file mode 100644 index f45d0e1b2..000000000 --- a/packages/utils/tests/src/navtive-selection.test.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { setNativeSelection, nativeSelectionEnabled } from '../../src/navtive-selection'; - -describe('setNativeSelection', () => { - beforeEach(() => { - // 在每个测试运行之前重置nativeSelectionEnabled的值 - setNativeSelection(true); - }); - - test('should enable native selection', () => { - setNativeSelection(true); - expect(nativeSelectionEnabled).toBe(true); - }); - - test('should disable native selection', () => { - setNativeSelection(false); - expect(nativeSelectionEnabled).toBe(false); - }); -}); diff --git a/packages/utils/tests/src/schema.test.ts b/packages/utils/tests/src/schema.test.ts deleted file mode 100644 index 93167de5b..000000000 --- a/packages/utils/tests/src/schema.test.ts +++ /dev/null @@ -1,92 +0,0 @@ -import { - compatibleLegaoSchema, - getNodeSchemaById, -} from '../../src/schema'; - -describe('compatibleLegaoSchema', () => { - it('should handle null input', () => { - const result = compatibleLegaoSchema(null); - expect(result).toBeNull(); - }); - - it('should convert Legao schema to JSExpression', () => { - // Create your test input - const legaoSchema = { - type: 'LegaoType', - source: 'LegaoSource', - compiled: 'LegaoCompiled', - }; - const result = compatibleLegaoSchema(legaoSchema); - - // Define the expected output - const expectedOutput = { - type: 'JSExpression', - value: 'LegaoCompiled', - extType: 'function', - }; - - // Assert that the result matches the expected output - expect(result).toEqual(expectedOutput); - }); - - // Add more test cases for other scenarios -}); - -describe('getNodeSchemaById', () => { - it('should find a node in the schema', () => { - // Create your test schema and node ID - const testSchema = { - id: 'root', - children: [ - { - id: 'child1', - children: [ - { - id: 'child1.1', - }, - ], - }, - ], - }; - const nodeId = 'child1.1'; - - const result = getNodeSchemaById(testSchema, nodeId); - - // Define the expected output - const expectedOutput = { - id: 'child1.1', - }; - - // Assert that the result matches the expected output - expect(result).toEqual(expectedOutput); - }); - - // Add more test cases for other scenarios -}); - -describe('Schema Ut', () => { - it('props', () => { - const schema = { - props: { - mobileSlot: { - type: "JSBlock", - value: { - componentName: "Slot", - children: [ - { - loop: { - variable: "props.content", - type: "variable" - }, - } - ], - } - }, - }, - }; - - const result = compatibleLegaoSchema(schema); - expect(result).toMatchSnapshot(); - expect(result.props.mobileSlot.value[0].loop.type).toBe('JSExpression'); - }); -}) \ No newline at end of file diff --git a/packages/utils/tests/src/script.test.ts b/packages/utils/tests/src/script.test.ts deleted file mode 100644 index d3d4ffd59..000000000 --- a/packages/utils/tests/src/script.test.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { - evaluate, - evaluateExpression, - newFunction, -} from '../../src/script'; - -describe('evaluate', () => { - test('should evaluate the given script', () => { - const script = 'console.log("Hello, world!");'; - global.console = { log: jest.fn() }; - - evaluate(script); - - expect(global.console.log).toHaveBeenCalledWith('Hello, world!'); - }); -}); - -describe('evaluateExpression', () => { - test('should evaluate the given expression', () => { - const expr = 'return 1 + 2'; - - const result = evaluateExpression(expr); - - expect(result).toBe(3); - }); -}); - -describe('newFunction', () => { - test('should create a new function with the given arguments and code', () => { - const args = 'a, b'; - const code = 'return a + b'; - - const result = newFunction(args, code); - - expect(result).toBeInstanceOf(Function); - expect(result(1, 2)).toBe(3); - }); - - test('should return null if an error occurs', () => { - const args = 'a, b'; - const code = 'return a +;'; // Invalid code - - const result = newFunction(args, code); - - expect(result).toBeNull(); - }); -}); diff --git a/packages/utils/tests/src/svg-icon.test.tsx b/packages/utils/tests/src/svg-icon.test.tsx deleted file mode 100644 index bbb6e18b7..000000000 --- a/packages/utils/tests/src/svg-icon.test.tsx +++ /dev/null @@ -1,35 +0,0 @@ -import React from 'react'; -import { render } from '@testing-library/react'; -import { SVGIcon, IconProps } from '../../src/svg-icon'; - -describe('SVGIcon', () => { - it('should render SVG element with correct size', () => { - const iconProps: IconProps = { - size: 'small', - viewBox: '0 0 24 24', - }; - - const { container } = render(); - - const svgElement = container.querySelector('svg'); - - expect(svgElement).toHaveAttribute('width', '12'); - expect(svgElement).toHaveAttribute('height', '12'); - }); - - it('should render SVG element with custom size', () => { - const iconProps: IconProps = { - size: 24, - viewBox: '0 0 24 24', - }; - - const { container } = render(); - - const svgElement = container.querySelector('svg'); - - expect(svgElement).toHaveAttribute('width', '24'); - expect(svgElement).toHaveAttribute('height', '24'); - }); - - // Add more tests for other scenarios if needed -}); diff --git a/packages/utils/tests/src/transaction-manager.test.ts b/packages/utils/tests/src/transaction-manager.test.ts deleted file mode 100644 index 42c7fa8bf..000000000 --- a/packages/utils/tests/src/transaction-manager.test.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { transactionManager } from '../../src/transaction-manager'; -import { IPublicEnumTransitionType } from '@alilc/lowcode-types'; - -const type = IPublicEnumTransitionType.REPAINT; - -describe('TransactionManager', () => { - let fn1: jest.Mock; - let fn2: jest.Mock; - - beforeEach(() => { - fn1 = jest.fn(); - fn2 = jest.fn(); - }); - - afterEach(() => { - jest.clearAllMocks(); - }); - - test('executeTransaction should emit startTransaction and endTransaction events', () => { - const startTransactionSpy = jest.spyOn(transactionManager.emitter, 'emit'); - const endTransactionSpy = jest.spyOn(transactionManager.emitter, 'emit'); - - transactionManager.executeTransaction(() => { - // Perform some action within the transaction - }); - - expect(startTransactionSpy).toHaveBeenCalledWith(`[${type}]startTransaction`); - expect(endTransactionSpy).toHaveBeenCalledWith(`[${type}]endTransaction`); - }); - - test('onStartTransaction should register the provided function for startTransaction event', () => { - const offSpy = jest.spyOn(transactionManager.emitter, 'off'); - - const offFunction = transactionManager.onStartTransaction(fn1); - - expect(transactionManager.emitter.listenerCount(`[${type}]startTransaction`)).toBe(1); - expect(offSpy).not.toHaveBeenCalled(); - - offFunction(); - - expect(transactionManager.emitter.listenerCount(`[${type}]startTransaction`)).toBe(0); - expect(offSpy).toHaveBeenCalledWith(`[${type}]startTransaction`, fn1); - }); - - test('onEndTransaction should register the provided function for endTransaction event', () => { - const offSpy = jest.spyOn(transactionManager.emitter, 'off'); - - const offFunction = transactionManager.onEndTransaction(fn2); - - expect(transactionManager.emitter.listenerCount(`[${type}]endTransaction`)).toBe(1); - expect(offSpy).not.toHaveBeenCalled(); - - offFunction(); - - expect(transactionManager.emitter.listenerCount(`[${type}]endTransaction`)).toBe(0); - expect(offSpy).toHaveBeenCalledWith(`[${type}]endTransaction`, fn2); - }); -}); diff --git a/packages/utils/tests/src/unique-id.test.ts b/packages/utils/tests/src/unique-id.test.ts deleted file mode 100644 index 2b4b6e9e0..000000000 --- a/packages/utils/tests/src/unique-id.test.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { uniqueId } from '../../src/unique-id'; - -test('uniqueId should return a unique id with prefix', () => { - const id = uniqueId('test'); - expect(id.startsWith('test')).toBeTruthy(); -}); - -test('uniqueId should return a unique id without prefix', () => { - const id = uniqueId(); - expect(id).not.toBeFalsy(); -}); diff --git a/packages/utils/tsconfig.declaration.json b/packages/utils/tsconfig.declaration.json deleted file mode 100644 index 54e57efbd..000000000 --- a/packages/utils/tsconfig.declaration.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "emitDeclarationOnly": true, - "declaration": true, - "outDir": "temp", - "stripInternal": true, - "paths": {} - } -} diff --git a/packages/utils/tsconfig.json b/packages/utils/tsconfig.json deleted file mode 100644 index 2ba069036..000000000 --- a/packages/utils/tsconfig.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "../../tsconfig.json", - "compilerOptions": { - "outDir": "dist", - }, - "include": ["src"] -} diff --git a/packages/utils/vite.config.ts b/packages/utils/vite.config.ts deleted file mode 100644 index c19b51f49..000000000 --- a/packages/utils/vite.config.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { defineConfig, } from 'vite'; -import baseConfigFn from '../../vite.base.config' - -export default defineConfig(async () => { - return baseConfigFn({ - name: 'LowCodeUtils', - }) -}); diff --git a/packages/workbench/package.json b/packages/workbench/package.json index e408756c3..96c46dce0 100644 --- a/packages/workbench/package.json +++ b/packages/workbench/package.json @@ -36,12 +36,7 @@ "editor" ], "dependencies": { - "@alifd/next": "^1.27.8", - "@alilc/lowcode-designer": "workspace:*", - "@alilc/lowcode-core": "workspace:*", "@alilc/lowcode-shared": "workspace:*", - "@alilc/lowcode-types": "workspace:*", - "@alilc/lowcode-utils": "workspace:*", "classnames": "^2.2.6", "lodash-es": "^4.17.21", "react": "^18.2.0", @@ -53,12 +48,7 @@ "@types/react-dom": "^18.2.0" }, "peerDependencies": { - "@alifd/next": "^1.27.8", - "@alilc/lowcode-designer": "workspace:*", - "@alilc/lowcode-core": "workspace:*", "@alilc/lowcode-shared": "workspace:*", - "@alilc/lowcode-types": "workspace:*", - "@alilc/lowcode-utils": "workspace:*", "react": "^18.2.0", "react-dom": "^18.2.0" }, diff --git a/packages/workbench/src/area.ts b/packages/workbench/src/area.ts deleted file mode 100644 index 4ed35f384..000000000 --- a/packages/workbench/src/area.ts +++ /dev/null @@ -1,93 +0,0 @@ -import { observable, computed, makeObservable } from '@alilc/lowcode-editor-core'; -import { Logger } from '@alilc/lowcode-utils'; -import { IPublicTypeWidgetBaseConfig } from '@alilc/lowcode-types'; -import { WidgetContainer } from './widget/widget-container'; -import { Skeleton } from './skeleton'; -import { IWidget } from './widget/widget'; - -const logger = new Logger({ level: 'warn', bizName: 'skeleton:area' }); -export interface IArea { - isEmpty(): boolean; - add(config: T | C): T; - remove(config: T | string): number; - setVisible(flag: boolean): void; - hide(): void; - show(): void; -} - -export class Area -implements IArea { - @observable private _visible = true; - - @computed get visible() { - if (this.exclusive) { - return this.container.current != null; - } - return this._visible; - } - - get current() { - if (this.exclusive) { - return this.container.current; - } - return null; - } - - readonly container: WidgetContainer; - - private lastCurrent: T | null = null; - - constructor( - readonly skeleton: Skeleton, - readonly name: string, - handle: (item: T | C) => T, private exclusive?: boolean, - defaultSetCurrent = false - ) { - makeObservable(this); - this.container = skeleton.createContainer( - name, - handle, - exclusive, - () => this.visible, defaultSetCurrent - ); - } - - isEmpty(): boolean { - return this.container.items.length < 1; - } - - add(config: T | C): T { - const item = this.container.get(config.name); - if (item) { - logger.warn(`The ${config.name} has already been added to skeleton.`); - return item; - } - return this.container.add(config); - } - - remove(config: T | string): number { - return this.container.remove(config); - } - - setVisible(flag: boolean) { - if (this.exclusive) { - const { current } = this.container; - if (flag && !current) { - this.container.active(this.lastCurrent || this.container.getAt(0)); - } else if (current) { - this.lastCurrent = current; - this.container.unactive(current); - } - return; - } - this._visible = flag; - } - - hide() { - this.setVisible(false); - } - - show() { - this.setVisible(true); - } -} diff --git a/packages/workbench/src/components/draggable-line/index.less b/packages/workbench/src/components/draggable-line/index.less deleted file mode 100644 index ea27b2d9a..000000000 --- a/packages/workbench/src/components/draggable-line/index.less +++ /dev/null @@ -1,15 +0,0 @@ -.lc-draggable-line-vertical { - position: absolute; - width: 4px; - height: 100%; - background-color: transparent; - cursor: col-resize; -} - -.lc-draggable-line-horizontal { - position: absolute; - width: 100%; - height: 4px; - background-color: transparent; - cursor: row-resize; -} diff --git a/packages/workbench/src/components/draggable-line/index.tsx b/packages/workbench/src/components/draggable-line/index.tsx deleted file mode 100644 index e3871c35f..000000000 --- a/packages/workbench/src/components/draggable-line/index.tsx +++ /dev/null @@ -1,146 +0,0 @@ -import { Component } from 'react'; -import classNames from 'classnames'; -import './index.less'; - -export interface DraggableLineProps { - onDrag: (l: number, e: any) => any; - onDragStart?: () => any; - onDragEnd?: () => any; - position?: 'right' | 'left' | 'top'; - className?: string; - maxIncrement?: number; - maxDecrement?: number; -} - -export default class DraggableLine extends Component { - static displayName = 'DraggableLine'; - - static defaultProps = { - onDrag() {}, - position: 'right', - className: '', - maxIncrement: 100, - maxDecrement: 0, - }; - - private startDrag: boolean; - private canDrag: boolean; - private offset: number; - private currentOffset: number; - private offEvent: any; - private offDragEvent: any; - private startOffset: any; - private shell: HTMLElement | null = null; - - constructor(props: DraggableLineProps) { - super(props); - this.startDrag = false; - this.canDrag = false; - this.offset = 0; - this.currentOffset = 0; - } - - componentDidMount() { - this.offEvent = this.initEvent(); - } - - componentWillUnmount() { - if (this.offEvent) { - this.offEvent(); - } - } - - onSelectStart(e: any) { - if (this.startDrag) { - e.preventDefault(); - } - } - - onStartMove(e: any) { - const { onDragStart } = this.props; - if (!this.startDrag) { - onDragStart && onDragStart(); - } - this.startDrag = true; - this.canDrag = true; - this.currentOffset = 0; - this.offDragEvent = this.initDragEvent(); - this.startOffset = this.getClientPosition(e); - } - - onEndMove() { - const { onDragEnd } = this.props; - if (this.startDrag) { - if (this.offDragEvent) { - this.offDragEvent(); - } - this.startDrag = false; - this.offset = this.currentOffset; - } - onDragEnd && onDragEnd(); - } - - onDrag(e: any) { - const { position, onDrag, maxIncrement = 100, maxDecrement = 0 } = this.props; - if (this.startDrag) { - if (position === 'left' || position === 'top') { - this.currentOffset = this.offset + this.startOffset - this.getClientPosition(e); - } else { - this.currentOffset = this.offset + this.getClientPosition(e) - this.startOffset; - } - - if (this.currentOffset < -maxDecrement) { - this.currentOffset = -maxDecrement; - } else if (this.currentOffset > maxIncrement) { - this.currentOffset = maxIncrement; - } - - onDrag(this.currentOffset, e); - } - } - - getClientPosition(e: any) { - const { position } = this.props; - return position === 'left' || position === 'right' ? e.clientX : e.clientY; - } - - initEvent() { - const selectStart = this.onSelectStart.bind(this); - document.addEventListener('selectstart', selectStart); - return () => document.removeEventListener('selectstart', selectStart); - } - - initDragEvent() { - const onDrag = this.onDrag.bind(this); - const onEndMove = this.onEndMove.bind(this); - document.addEventListener('mousemove', onDrag); - document.addEventListener('mouseup', onEndMove); - return () => { - document.removeEventListener('mousemove', onDrag); - document.removeEventListener('mouseup', onEndMove); - }; - } - - getParent() { - return this.shell?.parentElement; - } - - render() { - const { className = '', position } = this.props; - - return ( -
{ this.shell = ref; }} - className={classNames( - position === 'left' || position === 'right' - ? 'lc-draggable-line-vertical' - : 'lc-draggable-line-horizontal', - { - [className]: !!className, - }, - )} - onMouseDown={(e) => this.onStartMove(e)} - /> - ); - } -} diff --git a/packages/workbench/src/components/field/fields.tsx b/packages/workbench/src/components/field/fields.tsx deleted file mode 100644 index af1885451..000000000 --- a/packages/workbench/src/components/field/fields.tsx +++ /dev/null @@ -1,302 +0,0 @@ -import { Component, ErrorInfo, MouseEvent, type ReactNode } from 'react'; -import { isObject } from 'lodash-es'; -import classNames from 'classnames'; -import { Icon } from '@alifd/next'; -import { Title } from '@alilc/lowcode-editor-core'; -import { IPublicModelEditor, IPublicTypeTitleContent } from '@alilc/lowcode-types'; -import { PopupPipe, PopupContext } from '../popup'; -import './index.less'; -import InlineTip from './inlinetip'; -import { intl } from '../../locale'; -import { Logger } from '@alilc/lowcode-utils'; - -const logger = new Logger({ level: 'warn', bizName: 'skeleton:field' }); - -export interface FieldProps { - className?: string; - meta?: { package: string; componentName: string } | string; - title?: IPublicTypeTitleContent | null; - editor?: IPublicModelEditor; - defaultDisplay?: 'accordion' | 'inline' | 'block' | 'plain' | 'popup' | 'entry'; - collapsed?: boolean; - valueState?: number; - name?: string; - tip?: any; - onExpandChange?: (expandState: boolean) => void; - onClear?: () => void; - children?: ReactNode; -} - -export class Field extends Component { - state = { - collapsed: this.props.collapsed, - display: this.props.defaultDisplay || 'inline', - hasError: false, - }; - - private body: HTMLDivElement | null = null; - - private dispose?: () => void; - - constructor(props: any) { - super(props); - this.handleClear = this.handleClear.bind(this); - this.clickHandler = this.clickHandler.bind(this); - } - - private toggleExpand = () => { - const { onExpandChange } = this.props; - // eslint-disable-next-line react/no-access-state-in-setstate - const collapsed = !this.state.collapsed; - this.setState({ - collapsed, - }); - onExpandChange && onExpandChange(!collapsed); - }; - - private deployBlockTesting() { - if (this.dispose) { - this.dispose(); - } - const { body } = this; - if (!body) { - return; - } - const check = () => { - const setter = body.firstElementChild; - if (setter && setter.classList.contains('lc-block-setter')) { - this.setState({ - display: 'block', - }); - } else { - this.setState({ - display: 'inline', - }); - } - }; - const observer = new MutationObserver(check); - check(); - observer.observe(body, { - childList: true, - subtree: true, - attributes: true, - attributeFilter: ['class'], - }); - this.dispose = () => observer.disconnect(); - } - - private handleClear(e: React.MouseEvent) { - e.stopPropagation(); - this.props.onClear && this.props.onClear(); - } - - componentDidMount() { - const { defaultDisplay } = this.props; - if (!defaultDisplay || defaultDisplay === 'inline') { - this.deployBlockTesting(); - } - } - - componentWillUnmount() { - if (this.dispose) { - this.dispose(); - } - } - - static getDerivedStateFromError() { - return { - hasError: true, - }; - } - - componentDidCatch(error: Error, errorInfo: ErrorInfo) { - logger.error(`${this.props.title} has error`, error, errorInfo); - } - - getTipContent(propName: string, tip?: any): any { - let tipContent = ( -
-
- {intl('Attribute: ')} - {propName} -
-
- ); - - if (isObject(tip)) { - tipContent = ( -
-
- {intl('Attribute: ')} - {propName} -
-
- {intl('Description: ')} - {(tip as any).content} -
-
- ); - } else if (tip) { - tipContent = ( -
-
- {intl('Attribute: ')} - {propName} -
-
- {intl('Description: ')} - {tip} -
-
- ); - } - return tipContent; - } - - clickHandler(event?: MouseEvent) { - const { editor, name, title, meta } = this.props; - editor?.eventBus.emit('setting.setter.field.click', { name, title, meta, event }); - } - - render() { - const { hasError } = this.state; - if (hasError) { - return null; - } - - const { className, children, meta, title, name: propName, tip } = this.props; - const { display, collapsed } = this.state; - const isAccordion = display === 'accordion'; - let hostName = ''; - if (typeof meta === 'object') { - hostName = `${meta?.package || ''}-${meta.componentName || ''}`; - } else if (typeof meta === 'string') { - hostName = meta; - } - const id = `${hostName}-${propName || (title as any)['en-US'] || (title as any)['zh-CN']}`; - const tipContent = this.getTipContent(propName!, tip); - return ( -
- {display !== 'plain' && ( -
-
- {createValueState()} - - <InlineTip position="top">{tipContent}</InlineTip> - </div> - {isAccordion && <Icon className="lc-field-icon" type="arrow-up" size="xs" />} - </div> - )} - <div - key="body" - ref={(shell) => { - this.body = shell; - }} - className="lc-field-body" - > - {children} - </div> - </div> - ); - } -} - -/** - * **交互专利点** - * - * -1 多种值 - * 0 | null 无值 - * 1 类似值,比如数组长度一样 - * 2 单一植 - * 10 必填 - * - * TODO: turn number to enum - */ -function createValueState(/* valueState?: number, onClear?: (e: React.MouseEvent) => void */) { - return null; -} - -export interface PopupFieldProps extends FieldProps { - width?: number; -} - -export class PopupField extends Component<PopupFieldProps> { - static contextType = PopupContext; - - private pipe: any; - - static defaultProps: PopupFieldProps = { - width: 300, - }; - - render() { - const { className, children, title, width } = this.props; - if (!this.pipe) { - this.pipe = (this.context as PopupPipe).create({ width }); - } - - const titleElement = title && ( - <div className="lc-field-title"> - <Title title={title} /> - </div> - ); - - this.pipe.send(<div className="lc-field-body">{children}</div>, titleElement); - - return ( - <div className={classNames('lc-field lc-popup-field', className)}> - {title && ( - <div - className="lc-field-head" - onClick={(e) => { - this.pipe.show((e as any).target); - }} - > - <div className="lc-field-title"> - <Title title={title} /> - </div> - <Icon className="lc-field-icon" type="arrow-left" size="xs" /> - </div> - )} - </div> - ); - } -} - -export interface EntryFieldProps extends FieldProps { - stageName?: string; -} - -export class EntryField extends Component<EntryFieldProps> { - render() { - const { title, className, stageName } = this.props; - const classNameList = classNames('lc-field', 'lc-entry-field', className); - - return ( - <div className={classNameList}> - <div className="lc-field-head" data-stage-target={stageName}> - <div className="lc-field-title"> - <Title title={title || ''} /> - </div> - <Icon className="lc-field-icon" type="arrow-right" size="xs" /> - </div> - </div> - ); - } -} - -export class PlainField extends Component<FieldProps> { - render() { - const { className, children } = this.props; - return ( - <div className={classNames('lc-field lc-plain-field', className)}> - <div className="lc-field-body">{children}</div> - </div> - ); - } -} diff --git a/packages/workbench/src/components/field/index.less b/packages/workbench/src/components/field/index.less deleted file mode 100644 index 8c1facfba..000000000 --- a/packages/workbench/src/components/field/index.less +++ /dev/null @@ -1,124 +0,0 @@ -@x-gap: 12px; -@y-gap: 8px; - -.lc-settings-content > .lc-field:first-child > .lc-field-head { - border-top: none !important; -} - -.lc-field { - .lc-field-head { - display: flex; - align-items: center; - justify-content: space-between; - - .lc-field-title { - display: flex; - align-items: center; - } - .lc-field-icon { - transform-origin: center; - transition: transform 0.1s; - } - } - - &.lc-inline-field { - display: flex; - align-items: center; - margin: 12px; - - > .lc-field-head { - width: 70px; - margin-right: 1px; - .lc-title-label { - width: 70px; - word-break: break-all; - } - } - > .lc-field-body { - flex: 1; - min-width: 0; - display: flex; - align-items: center; - } - } - - &.lc-block-field, &.lc-accordion-field, &.lc-entry-field { - display: block; - - > .lc-field-head { - height: 32px; - display: flex; - align-items: center; - font-weight: 500; - background: var(--color-block-background-shallow, rgba(31,56,88,.06)); - border-top: 1px solid var(--color-line-normal,rgba(31,56,88,.1)); - border-bottom: 1px solid var(--color-line-normal,rgba(31,56,88,.1)); - color: var(--color-title); - padding: 0 12px; - user-select: none; - - > .lc-field-icon { - color: var(--color-icon-normal, #8f9bb3); - } - } - - > .lc-field-body { - padding: 12px; - - .lc-inline-field { - margin: 12px 0; - - &:first-child { - margin-top: 0; - } - &:last-child { - margin-bottom: 0; - } - } - } - } - - &.lc-entry-field { - margin-bottom: 6px; - - > .lc-field-head { - cursor: pointer; - } - } - - .lc-setter-actions { - display: flex; - align-items: center; - } - - &.lc-block-field { - position: relative; - >.lc-field-body>.lc-block-setter>.lc-setter-actions { - position: absolute; - right: 10px; - top: 0; - height: 32px; - } - } - - &.lc-accordion-field { - position: relative; - - > .lc-field-head { - cursor: pointer; - } - - &.lc-field-is-collapsed { - margin-bottom: 6px; - } - - &.lc-field-is-collapsed { - > .lc-field-head .lc-field-icon { - transform: rotate(180deg); - } - > .lc-field-body { - display: none; - } - } - } -} diff --git a/packages/workbench/src/components/field/index.ts b/packages/workbench/src/components/field/index.ts deleted file mode 100644 index 3f7a21330..000000000 --- a/packages/workbench/src/components/field/index.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { ReactNode, createElement } from 'react'; -import { IPublicTypeTitleContent } from '@alilc/lowcode-types'; -import { Field, PopupField, EntryField, PlainField } from './fields'; - -import './index.less'; - -export interface FieldProps { - className?: string; - title?: IPublicTypeTitleContent | null; - display?: 'accordion' | 'inline' | 'block' | 'plain' | 'popup' | 'entry'; - collapsed?: boolean; - valueState?: number; - onExpandChange?: (collapsed: boolean) => void; - onClear?: () => void; - [extra: string]: any; -} - -export function createField( - props: FieldProps, - children:ReactNode, - type?: 'accordion' | 'inline' | 'block' | 'plain' | 'popup' | 'entry' -): ReactNode { - if (type === 'popup') { - return createElement(PopupField, props, children); - } - if (type === 'entry') { - return createElement(EntryField, props, children); - } - if (type === 'plain' || !props.title) { - return createElement(PlainField, props, children); - } - return createElement(Field, { ...props, defaultDisplay: type }, children); -} - -export { Field, PopupField, EntryField, PlainField }; diff --git a/packages/workbench/src/components/field/inlinetip.tsx b/packages/workbench/src/components/field/inlinetip.tsx deleted file mode 100644 index 39dd55543..000000000 --- a/packages/workbench/src/components/field/inlinetip.tsx +++ /dev/null @@ -1,25 +0,0 @@ -import * as React from 'react'; - -export interface InlineTipProps { - position: string; - theme?: 'green' | 'black'; - children: React.ReactNode; -} - -export default class InlineTip extends React.Component<InlineTipProps> { - static displayName = 'InlineTip'; - - static defaultProps = { - position: 'auto', - theme: 'black', - }; - - render(): React.ReactNode { - const { position, theme, children } = this.props; - return ( - <div style={{ display: 'none' }} data-role="tip" data-position={position} data-theme={theme}> - {children} - </div> - ); - } -} diff --git a/packages/workbench/src/components/popup/index.tsx b/packages/workbench/src/components/popup/index.tsx deleted file mode 100644 index 03b67909d..000000000 --- a/packages/workbench/src/components/popup/index.tsx +++ /dev/null @@ -1,214 +0,0 @@ -import { createContext, ReactNode, Component, PureComponent } from 'react'; -import { Drawer, ConfigProvider } from '@alifd/next'; -import { uniqueId } from '@alilc/lowcode-utils'; -import { IEventBus, createModuleEventBus } from '@alilc/lowcode-editor-core'; -import './style.less'; - -export interface PopupExtProps { - width?: number; - hasMask?: boolean; - trigger?: ReactNode; - canCloseByOutSideClick?: boolean; - className?: string; - safeNode?: string[]; -} - -interface PopupProps extends PopupExtProps { - content?: ReactNode; - title?: ReactNode; - actionKey?: string; -} - -export const PopupContext = createContext<PopupPipe>({} as any); - -export class PopupPipe { - private emitter: IEventBus = createModuleEventBus('PopupPipe'); - - private currentId?: string; - - create(props?: PopupExtProps): { - send: (content: ReactNode, title: ReactNode) => void; - show: (target: Element) => void; - } { - let sendContent: ReactNode = null; - let sendTitle: ReactNode = null; - const id = uniqueId('popup'); - return { - send: (content: ReactNode, title: ReactNode) => { - sendContent = content; - sendTitle = title; - if (this.currentId === id) { - this.popup({ - ...props, - content, - title, - }); - } - }, - show: (target: Element, actionKey?: string) => { - this.currentId = id; - this.popup( - { - ...props, - actionKey, - content: sendContent, - title: sendTitle, - }, - target, - ); - }, - }; - } - - private popup(props: PopupProps, target?: Element) { - Promise.resolve().then(() => { - this.emitter.emit('popupchange', props, target); - }); - } - - onPopupChange(fn: (props: PopupProps, target?: Element) => void): () => void { - this.emitter.on('popupchange', fn); - return () => { - this.emitter.removeListener('popupchange', fn); - }; - } - - purge() { - this.emitter.removeAllListeners(); - } -} - -export default class PopupService extends Component<{ - popupPipe?: PopupPipe; - actionKey?: string; - safeId?: string; - popupContainer?: string; - children?: ReactNode; -}> { - private popupPipe = this.props.popupPipe || new PopupPipe(); - - componentWillUnmount() { - this.popupPipe.purge(); - } - - render() { - const { children, actionKey, safeId, popupContainer } = this.props; - return ( - <PopupContext.Provider value={this.popupPipe}> - {children} - <PopupContent key={`pop${actionKey}`} safeId={safeId} popupContainer={popupContainer} /> - </PopupContext.Provider> - ); - } -} - -interface StateType extends PopupProps { - visible?: boolean; - offsetX?: number; - pos?: { top: number; height: number }; -} -export class PopupContent extends PureComponent<{ safeId?: string; popupContainer?: string }> { - static contextType = PopupContext; - - popupContainerId = uniqueId('popupContainer'); - - state: StateType = { - visible: false, - offsetX: -300, - }; - - private dispose = (this.context as PopupPipe).onPopupChange((props, target) => { - const state: StateType = { - ...props, - visible: true, - }; - if (target) { - const rect = target.getBoundingClientRect(); - state.pos = { - top: rect.top, - height: rect.height, - }; - // todo: compute the align method - } - this.setState(state); - }); - - componentDidMount() { - const clientWidth = document.documentElement.clientWidth || document.body.clientWidth; - if (clientWidth >= 1860) { - this.setState({ - offsetX: -400, - }); - } - } - - componentWillUnmount() { - this.dispose(); - } - - onClose = () => { - this.setState({ - visible: false, - }); - }; - - render() { - const { - content, - visible, - title, - actionKey, - pos, - offsetX, - width = 360, - hasMask = false, - canCloseByOutSideClick = true, - safeNode = [], - } = this.state; - if (!visible) { - return null; - } - - let avoidLaterHidden = true; - setTimeout(() => { - avoidLaterHidden = false; - }, 10); - - const id = uniqueId('ball'); - - return ( - <Drawer - width={width} - visible={visible} - offset={[offsetX, 0]} - hasMask={hasMask} - onVisibleChange={(_visible: boolean, type: string) => { - if (avoidLaterHidden) { - return; - } - if (!_visible && type === 'closeClick') { - this.setState({ visible: false }); - } - }} - trigger={<div className="lc-popup-placeholder" style={pos} />} - triggerType="click" - canCloseByOutSideClick={canCloseByOutSideClick} - animation={false} - onClose={this.onClose} - id={this.props.safeId} - safeNode={[id, ...safeNode]} - container={this.props.popupContainer} - > - <div className="lc-ballon-title">{title}</div> - <div className="lc-ballon-content"> - <PopupService actionKey={actionKey} safeId={id} popupContainer={this.popupContainerId}> - <ConfigProvider popupContainer={this.popupContainerId}>{content}</ConfigProvider> - </PopupService> - </div> - <div id={this.popupContainerId} /> - <div id="engine-variable-setter-dialog" /> - <div id="engine-popup-container" /> - </Drawer> - ); - } -} diff --git a/packages/workbench/src/components/popup/style.less b/packages/workbench/src/components/popup/style.less deleted file mode 100644 index 720a5d9c3..000000000 --- a/packages/workbench/src/components/popup/style.less +++ /dev/null @@ -1,28 +0,0 @@ -.lc-popup-placeholder { - position: fixed; - width: 100%; - pointer-events: none; -} - -.lc-ballon { - padding: 10px; - max-width: 640px; - width: 640px; - .lc-ballon-title { - font-size: 14px; - } - .lc-ballon-content { - margin-top: 10px; - // FIXME: popup position is bad - max-height: calc(60vh); - overflow-x: hidden; - overflow-y: auto; - } - &.next-balloon-closable { - padding: 10px !important; - } - .next-balloon-close { - top: 4px !important; - right: 4px !important; - } -} diff --git a/packages/workbench/src/components/settings/index.ts b/packages/workbench/src/components/settings/index.ts deleted file mode 100644 index 0758f6a21..000000000 --- a/packages/workbench/src/components/settings/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import './style.less'; - -export * from './settings-primary-pane'; -export * from './settings-pane'; diff --git a/packages/workbench/src/components/settings/main.ts b/packages/workbench/src/components/settings/main.ts deleted file mode 100644 index 4d4c9b06a..000000000 --- a/packages/workbench/src/components/settings/main.ts +++ /dev/null @@ -1,93 +0,0 @@ -import { Node, Designer, Selection, SettingTopEntry } from '@alilc/lowcode-designer'; -import { - Editor, - observable, - computed, - makeObservable, - action, - IEventBus, - createModuleEventBus, -} from '@alilc/lowcode-editor-core'; - -function generateSessionId(nodes: Node[]) { - return nodes - .map((node) => node.id) - .sort() - .join(','); -} - -export class SettingsMain { - private emitter: IEventBus = createModuleEventBus('SettingsMain'); - - private _sessionId = ''; - - @observable.ref private _settings?: SettingTopEntry; - - @computed get length(): number | undefined { - return this._settings?.nodes.length; - } - - @computed get componentMeta() { - return this._settings?.componentMeta; - } - - @computed get settings() { - return this._settings; - } - - private disposeListener: () => void; - - private designer?: Designer; - - constructor(readonly editor: Editor) { - makeObservable(this); - this.init(); - } - - private async init() { - const setupSelection = (selection?: Selection) => { - if (selection) { - this.setup(selection.getNodes()); - } else { - this.setup([]); - } - }; - this.editor.eventBus.on('designer.selection.change', setupSelection); - this.disposeListener = () => { - this.editor.removeListener('designer.selection.change', setupSelection); - }; - const designer = await this.editor.onceGot('designer'); - this.designer = designer; - setupSelection(designer.currentSelection); - } - - @action - private setup(nodes: Node[]) { - // check nodes change - const sessionId = generateSessionId(nodes); - if (sessionId === this._sessionId) { - return; - } - this._sessionId = sessionId; - if (nodes.length < 1) { - this._settings = undefined; - return; - } - - if (!this.designer) { - this.designer = nodes[0].document.designer; - } - // 当节点只有一个时,复用 node 上挂载的 settingEntry,不会产生平行的两个实例,这样在整个系统中对 - // 某个节点操作的 SettingTopEntry 只有一个实例,后续的 getProp() 也会拿到相同的 SettingField 实例 - if (nodes.length === 1) { - this._settings = nodes[0].settingEntry as any; - } else { - this._settings = this.designer.createSettingEntry(nodes) as any; - } - } - - purge() { - this.disposeListener(); - this.emitter.removeAllListeners(); - } -} diff --git a/packages/workbench/src/components/settings/settings-pane.tsx b/packages/workbench/src/components/settings/settings-pane.tsx deleted file mode 100644 index ab297006e..000000000 --- a/packages/workbench/src/components/settings/settings-pane.tsx +++ /dev/null @@ -1,536 +0,0 @@ -import { Component, MouseEvent, Fragment, ReactNode } from 'react'; -import { - observer, - observable, - engineConfig, - runInAction, -} from '@alilc/lowcode-editor-core'; -import { - createContent, - isJSSlot, - isSetterConfig, - shouldUseVariableSetter, - isSettingField, -} from '@alilc/lowcode-utils'; -import { Skeleton } from '../../skeleton'; -import { Stage } from '../../widget/stage'; -import { - IPublicApiSetters, - IPublicTypeCustomView, - IPublicTypeDynamicProps, -} from '@alilc/lowcode-types'; -import { - ISettingEntry, - IComponentMeta, - ISettingField, - ISettingTopEntry, -} from '@alilc/lowcode-designer'; -import { createField } from '../field'; -import PopupService, { PopupPipe } from '../popup'; -import { SkeletonContext } from '../../context'; -import { intl } from '../../locale'; - -function isStandardComponent(componentMeta: IComponentMeta | null) { - if (!componentMeta) return false; - const { prototype } = componentMeta; - return prototype == null; -} - -/** - * 判断 initialValue 是否为非空,非空条件: - * 1. 当为 slot 结构时,value 为有长度的数组且 visible 不为 false - * 2. 不为 slot 结构,为非 undefined / null 值 - * @param initialValue - * @returns - */ -function isInitialValueNotEmpty(initialValue: any) { - if (isJSSlot(initialValue)) { - return ( - // @ts-expect-error visible 为 false 代表默认不展示 - initialValue.visible !== false && - Array.isArray(initialValue.value) && - initialValue.value.length > 0 - ); - } - return initialValue !== undefined && initialValue !== null; -} - -type SettingFieldViewProps = { field: ISettingField }; -type SettingFieldViewState = { fromOnChange: boolean; value: any }; - -@observer -class SettingFieldView extends Component< - SettingFieldViewProps, - SettingFieldViewState -> { - static contextType = SkeletonContext; - - stageName: string | undefined; - - setters?: IPublicApiSetters; - - constructor(props: SettingFieldViewProps) { - super(props); - - const { field } = this.props; - const { extraProps } = field; - const { display } = extraProps; - - const editor = field.designer?.editor; - const skeleton = editor?.get('skeleton') as Skeleton; - const { stages } = skeleton || {}; - this.setters = editor?.get('setters'); - let stageName; - if (display === 'entry') { - runInAction(() => { - stageName = `${field.getNode().id}_${field.name?.toString()}`; - // 清除原 stage,不然 content 引用的一直是老的 field,导致数据无法得到更新 - stages.container.remove(stageName); - stages.add({ - type: 'Widget', - name: stageName, - content: ( - <Fragment> - {field.items.map((item, index) => - createSettingFieldView(item, field, index), - )} - </Fragment> - ), - props: { - title: field.title, - }, - }); - }); - } - this.stageName = stageName; - } - - get field() { - return this.props.field; - } - - get visible() { - const { extraProps } = this.field; - const { condition } = extraProps; - try { - return typeof condition === 'function' - ? condition(this.field.internalToShellField()) !== false - : true; - } catch (error) { - console.error('exception when condition (hidden) is excuted', error); - } - - return true; - } - - get ignoreDefaultValue(): boolean { - const { extraProps } = this.field; - const { ignoreDefaultValue } = extraProps; - try { - if (typeof ignoreDefaultValue === 'function') { - return ignoreDefaultValue(this.field.internalToShellField()); - } - return false; - } catch (error) { - console.error('exception when ignoreDefaultValue is excuted', error); - } - - return false; - } - - get setterInfo(): { - setterProps: any; - initialValue: any; - setterType: any; - } { - const { extraProps, componentMeta } = this.field; - const { defaultValue } = extraProps; - - const { setter } = this.field; - let setterProps: - | ({ - setters?: (ReactNode | string)[]; - } & Record<string, unknown>) - | IPublicTypeDynamicProps = {}; - let setterType: any; - let initialValue: any = null; - - if (Array.isArray(setter)) { - setterType = 'MixedSetter'; - setterProps = { - setters: setter as any, - }; - } else if (isSetterConfig(setter)) { - setterType = setter.componentName; - if (setter.props) { - setterProps = setter.props; - if (typeof setterProps === 'function') { - setterProps = setterProps(this.field.internalToShellField()); - } - } - if (setter.initialValue != null) { - initialValue = setter.initialValue; - } - } else if (setter) { - setterType = setter; - } - - if (defaultValue != null && !('defaultValue' in setterProps)) { - setterProps.defaultValue = defaultValue; - if (initialValue == null) { - initialValue = defaultValue; - } - } - - if (this.field.valueState === -1) { - setterProps.multiValue = true; - if (!('placeholder' in setterProps)) { - setterProps.placeholder = intl('Multiple Value'); - } - } - - // 根据是否支持变量配置做相应的更改 - const supportVariable = this.field.extraProps?.supportVariable; - // supportVariableGlobally 只对标准组件生效,vc 需要单独配置 - const supportVariableGlobally = - engineConfig.get('supportVariableGlobally', false) && - isStandardComponent(componentMeta); - const isUseVariableSetter = shouldUseVariableSetter( - supportVariable, - supportVariableGlobally, - ); - if (isUseVariableSetter === false) { - return { - setterProps, - initialValue, - setterType, - }; - } - - if (setterType === 'MixedSetter') { - // VariableSetter 不单独使用 - if ( - Array.isArray(setterProps.setters) && - !setterProps.setters.includes('VariableSetter') - ) { - setterProps.setters.push('VariableSetter'); - } - } else { - setterType = 'MixedSetter'; - setterProps = { - setters: [setter as any, 'VariableSetter'], - }; - } - return { - setterProps, - initialValue, - setterType, - }; - } - - get value() { - return this.field.valueState === -1 ? null : this.field.getValue(); - } - - initDefaultValue() { - const { initialValue } = this.setterInfo; - if ( - this.state?.fromOnChange || - !isInitialValueNotEmpty(initialValue) || - this.ignoreDefaultValue || - this.value !== undefined - ) { - return; - } - // 当前 field 没有 value 值时,将 initialValue 写入 field - // 之所以用 initialValue,而不是 defaultValue 是为了保持跟 props.onInitial 的逻辑一致 - const _initialValue = - typeof initialValue === 'function' - ? initialValue(this.field.internalToShellField()) - : initialValue; - this.field.setValue(_initialValue); - } - - componentDidMount() { - this.initDefaultValue(); - } - - render() { - const field = this.field; - const { extraProps } = field; - const visible = this.visible; - - if (!visible) { - return null; - } - - const stageName = this.stageName; - - const { - setterProps = {}, - setterType, - initialValue = null, - } = this.setterInfo; - const onChangeAPI = extraProps?.onChange; - - const createSetterContent = ( - setter: any, - props: Record<string, any>, - ): ReactNode => { - if (typeof setter === 'string') { - setter = this.setters?.getSetter(setter); - if (!setter) { - return null; - } - if (setter.defaultProps) { - props = { - ...setter.defaultProps, - ...props, - }; - } - setter = setter.component; - } - - // Fusion 的表单组件都是通过 'value' in props 来判断是否使用 defaultValue - if ('value' in props && typeof props.value === 'undefined') { - delete props.value; - } - - return createContent(setter, props); - }; - - function shallowIntl(data: any): any { - if (!data || typeof data !== 'object') { - return data; - } - const maps: any = {}; - Object.keys(data).forEach((key) => { - maps[key] = intl(data[key]); - }); - return maps; - } - - return createField( - { - meta: - field?.componentMeta?.npm || - field?.componentMeta?.componentName || - '', - title: field.title, - // editor: field.editor, - collapsed: !field.expanded, - valueState: field.isRequired ? 10 : field.valueState, - onExpandChange: (expandState) => field.setExpanded(expandState), - onClear: () => field.clearValue(), - // field: field, - // stages, - stageName, - ...extraProps, - }, - !stageName && - createSetterContent(setterType, { - ...shallowIntl(setterProps), - forceInline: extraProps.forceInline, - key: field.id, - // === injection - prop: field.internalToShellField(), // for compatible vision - selected: field.top?.getNode()?.internalToShellNode(), - field: field.internalToShellField(), - // === IO - value: this.value, // reaction point - initialValue, - onChange: (value: any) => { - this.setState({ - fromOnChange: true, - value, - }); - field.setValue(value, true); - if (onChangeAPI) onChangeAPI(value, field.internalToShellField()); - }, - onInitial: () => { - if (initialValue == null) { - return; - } - const value = - typeof initialValue === 'function' - ? initialValue(field.internalToShellField()) - : initialValue; - this.setState({ - value, - }); - field.setValue(value, true); - }, - - removeProp: () => { - if (field.name) { - field.parent.clearPropValue(field.name); - } - }, - }), - extraProps.forceInline ? 'plain' : extraProps.display, - ); - } -} - -type SettingGroupViewProps = SettingFieldViewProps; -@observer -class SettingGroupView extends Component<SettingGroupViewProps> { - static contextType = SkeletonContext; - - stageName: string | undefined; - - constructor(props: SettingGroupViewProps) { - super(props); - const { field } = this.props; - const { extraProps } = field; - const { display } = extraProps; - const editor = this.props.field.designer?.editor; - const { stages } = editor?.get('skeleton') as Skeleton; - // const items = field.items; - - let stageName; - if (display === 'entry') { - runInAction(() => { - stageName = `${field.getNode().id}_${field.name?.toString()}`; - // 清除原 stage,不然 content 引用的一直是老的 field,导致数据无法得到更新 - stages.container.remove(stageName); - stages.add({ - type: 'Widget', - name: stageName, - content: ( - <Fragment> - {field.items.map((item, index) => - createSettingFieldView(item, field, index), - )} - </Fragment> - ), - props: { - title: field.title, - }, - }); - }); - } - this.stageName = stageName; - } - - render() { - const { field } = this.props; - const { extraProps } = field; - const { condition, display } = extraProps; - const visible = - field.isSingle && typeof condition === 'function' - ? condition(field.internalToShellField()) !== false - : true; - - if (!visible) { - return null; - } - - // todo: split collapsed state | field.items for optimize - return createField( - { - meta: - field.componentMeta?.npm || field.componentMeta?.componentName || '', - title: field.title, - // editor: field.editor, - collapsed: !field.expanded, - onExpandChange: (expandState) => field.setExpanded(expandState), - // field: field, - // stages, - stageName: this.stageName, - }, - field.items.map((item, index) => - createSettingFieldView(item, field, index), - ), - display, - ); - } -} - -export function createSettingFieldView( - field: ISettingField | IPublicTypeCustomView, - fieldEntry: ISettingEntry, - index?: number, -) { - if (isSettingField(field)) { - if (field.isGroup) { - return <SettingGroupView field={field} key={field.id} />; - } else { - return <SettingFieldView field={field} key={field.id} />; - } - } else { - return createContent(field, { key: index, field: fieldEntry }); - } -} - -export type SettingsPaneProps = { - target: ISettingTopEntry | ISettingField; - usePopup?: boolean; -}; - -@observer -export class SettingsPane extends Component<SettingsPaneProps> { - static contextType = SkeletonContext; - - @observable private currentStage?: Stage; - - private popupPipe = new PopupPipe(); - - private pipe = this.popupPipe.create(); - - private handleClick = (e: MouseEvent) => { - // compatiable vision stageBox - // TODO: optimize these codes - const { usePopup = true } = this.props; - if (!usePopup) return; - const pane = e.currentTarget as HTMLDivElement; - function getTarget(node: any): any { - if ( - !pane.contains(node) || - (node.nodeName === 'A' && node.getAttribute('href')) - ) { - return null; - } - - const target = node.dataset ? node.dataset.stageTarget : null; - if (target) { - return target; - } - return getTarget(node.parentNode); - } - const target = getTarget(e.target); - if (!target) { - return; - } - - const skeleton = this.context as Skeleton; - if (!skeleton || !skeleton.stages) { - return; - } - const stage = skeleton.stages.container.get(target); - if (stage) { - if (this.currentStage) { - stage.setPrevious(this.currentStage); - } - this.currentStage = stage; - } - }; - - render() { - const { target } = this.props; - const { items } = target; - - return ( - <div className="lc-settings-pane" onClick={this.handleClick}> - {/* todo: add head for single use */} - <PopupService popupPipe={this.popupPipe}> - <div className="lc-settings-content"> - {items.map((item, index) => - createSettingFieldView(item, target, index), - )} - </div> - </PopupService> - </div> - ); - } -} diff --git a/packages/workbench/src/components/settings/settings-primary-pane.tsx b/packages/workbench/src/components/settings/settings-primary-pane.tsx deleted file mode 100644 index c07262b5c..000000000 --- a/packages/workbench/src/components/settings/settings-primary-pane.tsx +++ /dev/null @@ -1,280 +0,0 @@ -import React, { Component } from 'react'; -import { Tab, Breadcrumb } from '@alifd/next'; -import { - observer, - Editor, - observable, - globalContext, - engineConfig, - makeObservable, -} from '@alilc/lowcode-editor-core'; -import { Node, SettingField, INode, Title } from '@alilc/lowcode-designer'; -import classNames from 'classnames'; -import { SettingsMain } from './main'; -import { SettingsPane } from './settings-pane'; -import { StageBox } from '../stage-box'; -import { SkeletonContext } from '../../context'; -import { intl } from '../../locale'; -import { createIcon, isSettingField } from '@alilc/lowcode-utils'; - -import './style.less'; - -interface ISettingsPrimaryPaneProps { - engineEditor: Editor; - config?: any; -} - -@observer -export class SettingsPrimaryPane extends Component< - ISettingsPrimaryPaneProps, - { shouldIgnoreRoot: boolean } -> { - state = { - shouldIgnoreRoot: false, - }; - private main = new SettingsMain(this.props.engineEditor); - - @observable.ref private _activeKey?: any; - - constructor(props: ISettingsPrimaryPaneProps) { - super(props); - makeObservable(this); - } - - componentDidMount() { - this.setShouldIgnoreRoot(); - - const editor = this.props.engineEditor; - - editor.eventBus.on('designer.selection.change', () => { - if (!engineConfig.get('stayOnTheSameSettingTab', false)) { - this._activeKey = null; - } - }); - } - - async setShouldIgnoreRoot() { - const designMode = await globalContext.get('editor').get('designMode'); - this.setState({ - shouldIgnoreRoot: designMode === 'live', - }); - } - - componentWillUnmount() { - this.main.purge(); - } - - renderBreadcrumb() { - const { settings, editor } = this.main; - // const shouldIgnoreRoot = config.props?.ignoreRoot; - const { shouldIgnoreRoot } = this.state; - if (!settings) { - return null; - } - if (settings.isMultiple) { - return ( - <div className="lc-settings-navigator"> - {createIcon(settings.componentMeta?.icon, { - className: 'lc-settings-navigator-icon', - })} - <div style={{ marginLeft: '5px' }}> - <Title title={settings.componentMeta!.title} /> - <span> x {settings.nodes.length}</span> - </div> - </div> - ); - } - - const designer = editor.get('designer'); - const current = designer?.currentSelection?.getNodes()?.[0]; - let node: INode | null = settings.first; - const focusNode = node.document?.focusNode; - - const items = []; - let l = 3; - while (l-- > 0 && node) { - const _node = node; - // dirty code: should remove - if (shouldIgnoreRoot && node.isRoot()) { - break; - } - if (focusNode && node.contains(focusNode)) { - l = 0; - } - const props = - l === 2 - ? {} - : { - onMouseOver: hoverNode.bind(null, _node, true), - onMouseOut: hoverNode.bind(null, _node, false), - onClick: () => { - if (!_node) { - return; - } - selectNode.call(null, _node); - const getName = (node: any) => { - const npm = node?.componentMeta?.npm; - return ( - [npm?.package, npm?.componentName].filter((item) => !!item).join('-') || - node?.componentMeta?.componentName || - '' - ); - }; - const selected = getName(current); - const target = getName(_node); - editor?.eventBus.emit('skeleton.settingsPane.Breadcrumb', { - selected, - target, - }); - }, - }; - items.unshift( - <Breadcrumb.Item {...props} key={node.id}> - <Title title={node.title} /> - </Breadcrumb.Item>, - ); - node = node.parent; - } - - return ( - <div className="lc-settings-navigator"> - {createIcon(this.main.componentMeta?.icon, { - className: 'lc-settings-navigator-icon' - })} - <Breadcrumb className="lc-settings-node-breadcrumb">{items}</Breadcrumb> - </div> - ); - } - - render() { - const { settings } = this.main; - const editor = this.props.engineEditor; - if (!settings) { - // 未选中节点,提示选中 或者 显示根节点设置 - return ( - <div className="lc-settings-main"> - <div className="lc-settings-notice"> - <p>{intl('Please select a node in canvas')}</p> - </div> - </div> - ); - } - - // 当节点被锁定,且未开启锁定后容器可设置属性 - if (settings.isLocked && !engineConfig.get('enableLockedNodeSetting', false)) { - return ( - <div className="lc-settings-main"> - <div className="lc-settings-notice"> - <p>{intl('Current node is locked')}</p> - </div> - </div> - ); - } - if (Array.isArray(settings.items) && settings.items.length === 0) { - return ( - <div className="lc-settings-main"> - <div className="lc-settings-notice"> - <p>{intl('No config found for this type of component')}</p> - </div> - </div> - ); - } - - if (!settings.isSameComponent) { - // TODO: future support 获取设置项交集编辑 - return ( - <div className="lc-settings-main"> - <div className="lc-settings-notice"> - <p>{intl('Please select same kind of components')}</p> - </div> - </div> - ); - } - - const { items } = settings; - if (items.length > 5 || items.some((item: any) => !isSettingField(item) || !item.isGroup)) { - return ( - <div className="lc-settings-main"> - {this.renderBreadcrumb()} - <div className="lc-settings-body"> - <SkeletonContext.Consumer> - {(skeleton) => { - if (skeleton) { - return ( - <StageBox skeleton={skeleton} target={settings} key={settings.id}> - <SettingsPane target={settings} usePopup={false} /> - </StageBox> - ); - } - return null; - }} - </SkeletonContext.Consumer> - </div> - </div> - ); - } - - let matched = false; - const tabs = (items as SettingField[]).map((field) => { - if (this._activeKey === field.name) { - matched = true; - } - return ( - <Tab.Item - className="lc-settings-tab-item" - title={<Title title={field.title} />} - key={field.name} - onClick={() => { - editor?.eventBus.emit('skeleton.settingsPane.change', { - name: field.name, - title: field.title, - }); - }} - > - <SkeletonContext.Consumer> - {(skeleton) => { - if (skeleton) { - return ( - <StageBox skeleton={skeleton} target={field} key={field.id}> - <SettingsPane target={field} key={field.id} usePopup={false} /> - </StageBox> - ); - } - return null; - }} - </SkeletonContext.Consumer> - </Tab.Item> - ); - }); - const activeKey = matched ? this._activeKey : (items[0] as SettingField).name; - - const className = classNames('lc-settings-main', { - 'lc-settings-hide-tabs': - items.length === 1 && engineConfig.get('hideSettingsTabsWhenOnlyOneItem', false), - }); - return ( - <div className={className}> - {this.renderBreadcrumb()} - <Tab - activeKey={activeKey} - onChange={(tabKey) => { - this._activeKey = tabKey; - }} - navClassName="lc-settings-tabs" - animation={false} - excessMode="dropdown" - contentClassName="lc-settings-tabs-content" - > - {tabs} - </Tab> - </div> - ); - } -} - -function hoverNode(node: Node, flag: boolean) { - node.hover(flag); -} -function selectNode(node: Node) { - node?.select(); -} diff --git a/packages/workbench/src/components/settings/style.less b/packages/workbench/src/components/settings/style.less deleted file mode 100644 index 4599ed55c..000000000 --- a/packages/workbench/src/components/settings/style.less +++ /dev/null @@ -1,165 +0,0 @@ -.lc-settings-main { - position: relative; - height: 100%; - overflow: hidden; - - ul { - margin: 0; - } - - .lc-settings-content { - position: absolute; - top: 0; - bottom: 0; - width: 100%; - overflow-y: auto; - } - - .lc-setting-stage-back + .lc-settings-content { - top: 38px; - } - - .lc-setting-stage-back { - height: 32px; - width: 100%; - display: flex; - align-items: center; - justify-content: center; - font-weight: 500; - background: var(--color-block-background-shallow, rgba(31,56,88,.06)); - color: var(--color-title); - padding: 0 16px; - user-select: none; - position: relative; - margin-bottom: 4px; - position: absolute; - } - - .lc-settings-notice { - text-align: center; - font-size: 12px; - font-family: PingFang SC, Hiragino Sans GB, Microsoft YaHei, Helvetica, Arial, sans-serif; - color: var(--color-text ,rgba(0,0,0,.6)); - padding: 50px 15px 0; - } - - .lc-settings-navigator { - height: 30px; - display: flex; - align-items: center; - padding: 0 16px; - border-bottom: 1px solid var(--color-line-normal); - .lc-settings-navigator-icon { - width: 16px; - height: 16px; - * { - fill: var(--color-icon-normal, rgba(31, 56, 88, 0.4)); - } - } - .lc-settings-node-breadcrumb { - margin-left: 5px; - .next-breadcrumb { - display: inline-flex; - align-items: stretch; - height: 24px; - } - .next-breadcrumb-item { - display: inline-flex; - align-items: center; - cursor: default; - &:not(:last-child):hover { - cursor: pointer; - } - .next-breadcrumb-text { - font-size: 12px; - } - } - } - } - - .lc-settings-body { - position: absolute; - top: 30px; - right: 0; - left: 0; - bottom: 0; - overflow-y: auto; - } - - // ====== reset fusion-tabs ===== - .lc-settings-tabs { - position: relative; - overflow: visible; - > .next-tabs-nav-extra { - position: absolute !important; - top: 40px !important; - left: 0 !important; - height: 30px; - right: 0; - transform: none !important; - - } - .next-tabs-nav-container { - .next-tabs-nav { - display: flex; - .next-tabs-tab.lc-settings-tab-item { - flex: 1; - min-width: 0; - outline: none; - .next-tabs-tab-inner { - text-align: center; - padding: 12px 0; - } - } - } - } - } - - .lc-settings-tabs-content { - position: absolute; - top: 70px; - left: 0; - right: 0; - bottom: 0; - .next-tabs-tabpane { - position: absolute; - top: 0; - right: 0; - left: 0; - bottom: 0; - overflow-y: auto; - outline: none !important; - box-shadow: none !important; - } - } - .lc-outline-pane { - position: absolute; - z-index: 100; - top: 0; - bottom: 0; - display: none; - } -} - -.lc-workbench .lc-workbench-body .lc-right-area .lc-settings-hide-tabs { - .lc-settings-tabs { - display: none; - } - - .lc-settings-tabs-content { - top: 30px; - } -} - -.lc-settings-pane { - padding-bottom: 50px; - .next-btn { - line-height: 1 !important; - } -} - -html.lc-cursor-dragging:not(.lowcode-has-fixed-tree) { - .lc-settings-main .lc-outline-pane { - display: block; - } -} diff --git a/packages/workbench/src/components/settings/utils.ts b/packages/workbench/src/components/settings/utils.ts deleted file mode 100644 index 80b3d449a..000000000 --- a/packages/workbench/src/components/settings/utils.ts +++ /dev/null @@ -1,47 +0,0 @@ -function getHotterFromSetter(setter: any) { - return (setter && (setter.Hotter || (setter.type && setter.type.Hotter))) || []; // eslint-disable-line -} - -function getTransducerFromSetter(setter: any) { - return ( - (setter && - (setter.transducer || - setter.Transducer || - (setter.type && (setter.type.transducer || setter.type.Transducer)))) || - null - ); // eslint-disable-line -} - -function combineTransducer(transducer: any, arr: any, context: any) { - if (!transducer && Array.isArray(arr)) { - const [toHot, toNative] = arr; - transducer = { toHot, toNative }; - } - - return { - toHot: ((transducer && transducer.toHot) || ((x: any) => x)).bind(context), // eslint-disable-line - toNative: ((transducer && transducer.toNative) || ((x: any) => x)).bind(context), // eslint-disable-line - }; -} - -export class Transducer { - context: any; - setterTransducer: any; - - constructor(context: any, config: any) { - this.setterTransducer = combineTransducer( - getTransducerFromSetter(config.setter), - getHotterFromSetter(config.setter), - context, - ); - this.context = context; - } - - toHot(data: any) { - return this.setterTransducer.toHot(data); - } - - toNative(data: any) { - return this.setterTransducer.toNative(data); - } -} diff --git a/packages/workbench/src/components/stage-box/index.less b/packages/workbench/src/components/stage-box/index.less deleted file mode 100644 index fe62081f1..000000000 --- a/packages/workbench/src/components/stage-box/index.less +++ /dev/null @@ -1,79 +0,0 @@ -@import '../../less-variables.less'; - -.skeleton-stagebox { - overflow-x: hidden; - overflow-y: auto; - position: absolute; - top: 0; - left: 0; - bottom: 0; - right: 0; - .skeleton-stagebox-stage { - height: auto; - overflow: hidden; - - transition: transform 0.2s; - - &.skeleton-stagebox-refer { - position: absolute; - top: 0; - left: 0; - right: 0; - height: auto; - } - - &.skeleton-stagebox-stageout-left, &.skeleton-stagebox-stagein-right { - transform: translateX(-100%); - } - - &.skeleton-stagebox-stageout-right, &.skeleton-stagebox-stagein-left { - transform: translateX(100%); - } - - .skeleton-stagebox-stagebacker { - cursor: pointer; - height: 30px; - display: flex; - align-items: center; - background: var(--color-block-background-light, @normal-alpha-9); - justify-content: center; - position: relative; - - .skeleton-stagebox-stage-arrow { - position: absolute; - left: 8px; - top: 50%; - transform: translateY(-50%) rotate(90deg); - opacity: 0.6; - width: 12px; - } - .skeleton-stagebox-stage-title { - font-weight: bold; - } - &:hover { - background: var(--color-block-background-dark, @normal-alpha-7); - .skeleton-stagebox-stage-arrow { - opacity: 1; - } - } - .skeleton-stagebox-stage-exit { - position: absolute; - right: 8px; - top: 50%; - transform: translateY(-50%); - opacity: 0.6; - } - } - - .skeleton-stagebox-stage-content { - overflow: hidden; - box-sizing: border-box; - } - - &.skeleton-stagebox-has-backer { - .skeleton-stagebox-stage-content { - padding-top: 30px; - } - } - } -} diff --git a/packages/workbench/src/components/stage-box/index.ts b/packages/workbench/src/components/stage-box/index.ts deleted file mode 100644 index ee6dc3b8e..000000000 --- a/packages/workbench/src/components/stage-box/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import StageBox from './stage-box'; -import './index.less'; - -export { StageBox }; diff --git a/packages/workbench/src/components/stage-box/stage-box.tsx b/packages/workbench/src/components/stage-box/stage-box.tsx deleted file mode 100644 index 0682a51b4..000000000 --- a/packages/workbench/src/components/stage-box/stage-box.tsx +++ /dev/null @@ -1,132 +0,0 @@ -import React, { Component } from 'react'; -import classNames from 'classnames'; -import { observer } from '@alilc/lowcode-editor-core'; -import StageChain from './stage-chain'; -import Stage from './stage'; -import { ISkeleton } from '../../skeleton'; -import PopupService, { PopupPipe } from '../popup'; -import { Stage as StageWidget } from '../../widget/stage'; - -export const StageBoxDefaultProps = {}; - -export type StageBoxProps = typeof StageBoxDefaultProps & { - stageChain?: StageChain; - className?: string; - children: React.ReactNode; - skeleton: ISkeleton; -}; - -type WillDetachMember = () => void; - -@observer -export default class StageBox extends Component<StageBoxProps> { - static defaultProps = StageBoxDefaultProps; - - static displayName = 'StageBox'; - - private stageChain: StageChain; - - private willDetach: WillDetachMember[] = []; - - private shell: HTMLElement | null; - - private popupPipe = new PopupPipe(); - - private pipe = this.popupPipe.create(); - - constructor(props: StageBoxProps) { - super(props); - const { stageChain, children, skeleton } = this.props; - if (stageChain) { - this.stageChain = stageChain; - } else { - const stateName = skeleton.createStage({ - content: children, - isRoot: true, - }); - this.stageChain = new StageChain(skeleton.getStage(stateName as string) as StageWidget); - } - this.willDetach.push(this.stageChain.onStageChange(() => this.forceUpdate())); - } - - componentDidMount() { - const { shell } = this; - - /** - * 向上层递归寻找 target - * @param node 节点 - * @returns 节点的 dataset.stageTarget 信息 - */ - const getTarget = (node: HTMLElement | null): null | string => { - if (!node || !shell?.contains(node) || (node.nodeName === 'A' && node.getAttribute('href'))) { - return null; - } - - const target = node.dataset ? node.dataset.stageTarget : null; - if (target) { - return target; - } - return getTarget(node.parentNode as HTMLElement); - }; - - const click = (e: MouseEvent) => { - const target = getTarget(e.target as HTMLElement); - if (!target) { - return; - } - - if (target === 'stageback') { - this.stageChain.stageBack(); - } else if (target === 'stageexit') { - this.stageChain.stageBackToRoot(); - } else { - const { skeleton } = this.props; - this.stageChain.stagePush(skeleton.getStage(target)); - } - }; - - shell?.addEventListener('click', click, false); - this.willDetach.push(() => shell?.removeEventListener('click', click, false)); - } - - componentWillUnmount() { - if (this.willDetach) { - this.willDetach.forEach((off: () => void) => off()); - } - } - - render() { - const className = classNames('skeleton-stagebox', this.props.className); - const stage = this.stageChain.getCurrentStage(); - const refer = stage?.getRefer(); - - let contentCurrent = null; - let contentRefer = null; - - if (refer) { - contentCurrent = ( - <Stage key={stage.getId()} stage={stage} direction={refer.direction} current /> - ); - contentRefer = ( - <Stage key={refer?.stage?.getId()} stage={refer?.stage} direction={refer.direction} /> - ); - } else { - contentCurrent = <Stage key={stage.getId()} stage={stage} current />; - } - - return ( - <div - ref={(ref) => { - this.shell = ref; - }} - className={className} - > - {/* @ts-ignore */} - <PopupService popupPipe={this.popupPipe}> - {contentRefer} - {contentCurrent} - </PopupService> - </div> - ); - } -} diff --git a/packages/workbench/src/components/stage-box/stage-chain.ts b/packages/workbench/src/components/stage-box/stage-chain.ts deleted file mode 100644 index fe931769f..000000000 --- a/packages/workbench/src/components/stage-box/stage-chain.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { Stage as StageWidget } from '../../widget/stage'; -import { createModuleEventBus, IEventBus } from '@alilc/lowcode-editor-core'; - -export default class StageChain { - private emitter: IEventBus; - - private stage: StageWidget; - - constructor(stage: StageWidget) { - this.emitter = createModuleEventBus('StageChain'); - this.stage = stage; - } - - stagePush(stage: StageWidget | null) { - if (!stage) return; - stage.setPrevious(this.stage); - stage.setReferLeft(this.stage); - this.stage = stage; - this.emitter.emit('stagechange'); - } - - stageBack() { - const stage = this.stage.getPrevious(); - if (!stage) return; - stage.setReferRight(this.stage); - this.stage = stage; - this.emitter.emit('stagechange'); - } - - /** - * 回到最开始 - */ - stageBackToRoot() { - let rootStage = this.stage.getPrevious(); - while (rootStage && !rootStage.isRoot) { - rootStage = rootStage.getPrevious(); - } - if (!rootStage) return; - rootStage.setReferRight(this.stage); - this.stage = rootStage; - this.emitter.emit('stagechange'); - } - - getCurrentStage() { - return this.stage; - } - - onStageChange(func: () => void) { - this.emitter.on('stagechange', func); - return () => { - this.emitter.removeListener('stagechange', func); - }; - } -} diff --git a/packages/workbench/src/components/stage-box/stage.tsx b/packages/workbench/src/components/stage-box/stage.tsx deleted file mode 100644 index 49b62d652..000000000 --- a/packages/workbench/src/components/stage-box/stage.tsx +++ /dev/null @@ -1,107 +0,0 @@ -// @todo 改成 hooks -import React, { Component } from 'react'; -import classNames from 'classnames'; -import { IconArrow } from '../../icons/arrow'; -import { IconExit } from '../../icons/exit'; -import { Stage as StageWidget } from '../../widget/stage'; -import { isTitleConfig } from '@alilc/lowcode-utils'; - -export const StageDefaultProps = { - current: false, -}; - -export type StageProps = typeof StageDefaultProps & { - stage?: StageWidget; - current: boolean; - direction?: string; -}; - -export default class Stage extends Component<StageProps> { - static defaultProps = StageDefaultProps; - - private timer: number; - - private additionClassName: string | null; - - private shell: any; - - componentDidMount() { - this.doSkate(); - } - - componentDidUpdate() { - this.doSkate(); - } - - componentWillUnmount() { - window.clearTimeout(this.timer); - } - - doSkate() { - window.clearTimeout(this.timer); - if (this.additionClassName) { - this.timer = window.setTimeout(() => { - const elem = this.shell; - if (elem) { - if (this.props.current) { - elem.classList.remove(this.additionClassName); - } else { - elem.classList.add(this.additionClassName); - } - this.additionClassName = null; - } - }, 15); - } - } - - render() { - const { stage, current, direction } = this.props; - const content = stage?.getContent(); - const { title } = stage!; - const newTitle = isTitleConfig(title) ? title.label : title; - - if (current) { - if (direction) { - this.additionClassName = `skeleton-stagebox-stagein-${direction}`; - } - } else if (direction) { - this.additionClassName = `skeleton-stagebox-stageout-${direction}`; - } - - const className = classNames( - 'skeleton-stagebox-stage', - { - 'skeleton-stagebox-refer': !current, - }, - this.additionClassName, - ); - - const stageBacker = stage?.hasBack() ? ( - <div className="skeleton-stagebox-stagebacker"> - <IconArrow - className="skeleton-stagebox-stage-arrow" - size="medium" - data-stage-target="stageback" - /> - <span className="skeleton-stagebox-stage-title">{newTitle as any}</span> - <IconExit - className="skeleton-stagebox-stage-exit" - size="medium" - data-stage-target="stageexit" - /> - </div> - ) : null; - - return ( - <div - ref={(ref) => { - this.shell = ref; - }} - className={className} - > - {stageBacker} - <div className="skeleton-stagebox-stage-content">{content}</div> - </div> - ); - } -} diff --git a/packages/workbench/src/components/widget-views/index.less b/packages/workbench/src/components/widget-views/index.less deleted file mode 100644 index b392752be..000000000 --- a/packages/workbench/src/components/widget-views/index.less +++ /dev/null @@ -1,28 +0,0 @@ -.lc-widget-view-container { - height: 100%; - width: 100%; - - &.hidden { - display: none; - } -} - -.lc-widget-disabled { - pointer-events: none; - opacity: 0.4; -} - -.lc-draggable-line-vertical { - position: absolute; - width: 4px; - height: 100%; - top: 0; - background-color: transparent; - cursor: col-resize; - right: -2px; - z-index: 99; -} - -.lc-engine-slate-draggable-line-right { - right: -2px; -} diff --git a/packages/workbench/src/components/widget-views/index.tsx b/packages/workbench/src/components/widget-views/index.tsx deleted file mode 100644 index d4ace6c2c..000000000 --- a/packages/workbench/src/components/widget-views/index.tsx +++ /dev/null @@ -1,430 +0,0 @@ -import { Component, ReactElement } from 'react'; -import classNames from 'classnames'; -import { observer } from '@alilc/lowcode-editor-core'; -import { Title, HelpTip } from '@alilc/lowcode-designer'; -import { DockProps } from '../../types'; -import { PanelDock } from '../../widget/panel-dock'; -import { composeTitle } from '../../widget/utils'; -import { WidgetContainer } from '../../widget/widget-container'; -import { Panel } from '../../widget/panel'; -import { IWidget } from '../../widget/widget'; -import { SkeletonEvents } from '../../skeleton'; -import DraggableLine from '../draggable-line'; -import PanelOperationRow from './panel-operation-row'; - -import './index.less'; - -export function DockView({ - title, - icon, - description, - size, - className, - onClick, -}: DockProps) { - return ( - <Title - title={composeTitle(title, icon, description)} - className={classNames('lc-dock', className, { - [`lc-dock-${size}`]: size, - })} - onClick={onClick} - /> - ); -} - -@observer -export class PanelDockView extends Component<DockProps & { dock: PanelDock }> { - private lastActived = false; - - componentDidMount() { - this.checkActived(); - } - - componentDidUpdate() { - this.checkActived(); - } - - checkActived() { - const { dock } = this.props; - if (dock.actived !== this.lastActived) { - this.lastActived = dock.actived; - if (this.lastActived) { - dock.skeleton.postEvent( - SkeletonEvents.PANEL_DOCK_ACTIVE, - dock.name, - dock, - ); - } else { - dock.skeleton.postEvent( - SkeletonEvents.PANEL_DOCK_UNACTIVE, - dock.name, - dock, - ); - } - } - } - - render() { - const { dock, className, onClick, ...props } = this.props; - return DockView({ - ...props, - className: classNames(className, { - actived: dock.actived, - }), - onClick: () => { - onClick && onClick(); - dock.togglePanel(); - }, - }); - } -} - -export class DialogDockView extends Component {} - -export class DraggableLineView extends Component<{ panel: Panel }> { - private shell: any; - private defaultWidth: number; - - private getDefaultWidth() { - const configWidth = this.props.panel?.config.props?.width; - if (configWidth) { - return configWidth; - } - if (this.defaultWidth) { - return this.defaultWidth; - } - const containerRef = this.shell?.getParent(); - if (containerRef) { - this.defaultWidth = containerRef.offsetWidth; - return this.defaultWidth; - } - return 300; - } - - onDrag(value: number) { - const defaultWidth = this.getDefaultWidth(); - const width = defaultWidth + value; - - const containerRef = this.shell?.getParent(); - if (containerRef) { - containerRef.style.width = `${width}px`; - } - - // 抛出事件,对于有些需要 panel 插件随着变化进行再次渲染的,由panel插件内部监听事件实现 - const editor = this.props.panel.skeleton.editor; - editor?.eventBus.emit('dockpane.drag', width); - } - - onDragChange(type: 'start' | 'end') { - const editor = this.props.panel.skeleton.editor; - editor?.eventBus.emit('dockpane.dragchange', type); - // builtinSimulator 屏蔽掉 鼠标事件 - editor?.eventBus.emit( - 'designer.builtinSimulator.disabledEvents', - type === 'start', - ); - } - - render() { - // left fixed 下不允许改变宽度 - // 默认 关闭,通过配置开启 - const enableDrag = this.props.panel.config.props?.enableDrag; - const isRightArea = this.props.panel.config?.area === 'rightArea'; - if ( - isRightArea || - !enableDrag || - this.props.panel?.parent?.name === 'leftFixedArea' - ) { - return null; - } - return ( - <DraggableLine - ref={(ref) => { - this.shell = ref; - }} - position="right" - className="lc-engine-slate-draggable-line-right" - onDrag={(e) => this.onDrag(e)} - onDragStart={() => this.onDragChange('start')} - onDragEnd={() => this.onDragChange('end')} - maxIncrement={500} - maxDecrement={0} - // TODO: 优化 - // maxIncrement={dock.getMaxWidth() - this.cachedSize.width} - // maxDecrement={this.cachedSize.width - dock.getWidth()} - /> - ); - } -} - -@observer -export class TitledPanelView extends Component<{ - panel: Panel; - area?: string; -}> { - private lastVisible = false; - - componentDidMount() { - this.checkVisible(); - } - - componentDidUpdate() { - this.checkVisible(); - } - - checkVisible() { - const { panel } = this.props; - const currentVisible = panel.inited && panel.visible; - if (currentVisible !== this.lastVisible) { - this.lastVisible = currentVisible; - if (this.lastVisible) { - panel.skeleton.postEvent(SkeletonEvents.PANEL_SHOW, panel.name, panel); - } else { - panel.skeleton.postEvent(SkeletonEvents.PANEL_HIDE, panel.name, panel); - } - } - } - - render() { - const { panel, area } = this.props; - if (!panel.inited) { - return null; - } - const editor = panel.skeleton.editor; - const panelName = area ? `${area}-${panel.name}` : panel.name; - editor?.eventBus.emit('skeleton.panel.toggle', { - name: panelName || '', - status: panel.visible ? 'show' : 'hide', - }); - return ( - <div - className={classNames('lc-titled-panel', { - hidden: !panel.visible, - })} - id={panelName} - data-keep-visible-while-dragging={ - panel.config.props?.keepVisibleWhileDragging - } - > - <PanelOperationRow panel={panel} /> - <PanelTitle panel={panel} /> - <div className="lc-panel-body">{panel.body}</div> - <DraggableLineView panel={panel} /> - </div> - ); - } -} - -@observer -export class PanelView extends Component<{ - panel: Panel; - area?: string; - hideOperationRow?: boolean; - hideDragLine?: boolean; -}> { - private lastVisible = false; - - componentDidMount() { - this.checkVisible(); - } - - componentDidUpdate() { - this.checkVisible(); - } - - checkVisible() { - const { panel } = this.props; - const currentVisible = panel.inited && panel.visible; - if (currentVisible !== this.lastVisible) { - this.lastVisible = currentVisible; - if (this.lastVisible) { - panel.skeleton.postEvent(SkeletonEvents.PANEL_SHOW, panel.name, panel); - } else { - panel.skeleton.postEvent(SkeletonEvents.PANEL_HIDE, panel.name, panel); - } - } - } - - render() { - const { panel, area, hideOperationRow, hideDragLine } = this.props; - if (!panel.inited) { - return null; - } - const editor = panel.skeleton.editor; - const panelName = area ? `${area}-${panel.name}` : panel.name; - editor?.eventBus.emit('skeleton.panel.toggle', { - name: panelName || '', - status: panel.visible ? 'show' : 'hide', - }); - return ( - <div - className={classNames('lc-panel', { - hidden: !panel.visible, - })} - id={panelName} - data-keep-visible-while-dragging={ - panel.config.props?.keepVisibleWhileDragging - } - > - {!hideOperationRow && <PanelOperationRow panel={panel} />} - {panel.body} - {!hideDragLine && <DraggableLineView panel={panel} />} - </div> - ); - } -} - -@observer -export class TabsPanelView extends Component<{ - container: WidgetContainer<Panel>; - // shouldHideSingleTab: 一个布尔值,用于控制当 Tabs 组件只有一个标签时是否隐藏该标签。 - shouldHideSingleTab?: boolean; -}> { - render() { - const { container } = this.props; - const titles: ReactElement[] = []; - const contents: ReactElement[] = []; - // 如果只有一个标签且 shouldHideSingleTab 为 true,则不显示 Tabs - if (this.props.shouldHideSingleTab && container.items.length === 1) { - contents.push( - <PanelView - key={container.items[0].id} - panel={container.items[0]} - hideOperationRow - hideDragLine - />, - ); - } else { - container.items.forEach((item: any) => { - titles.push( - <PanelTitle key={item.id} panel={item} className="lc-tab-title" />, - ); - contents.push( - <PanelView - key={item.id} - panel={item} - hideOperationRow - hideDragLine - />, - ); - }); - } - - if (!titles.length) { - return contents; - } - - return ( - <div className="lc-tabs"> - <div - className="lc-tabs-title" - onClick={(e) => { - const shell = e.currentTarget; - const t = e.target as Element; - let elt = shell.firstElementChild; - while (elt) { - if (elt.contains(t)) { - break; - } - elt = elt.nextElementSibling; - } - if (elt) { - container.active((elt as any).dataset.name); - } - }} - > - {titles} - </div> - <div className="lc-tabs-content">{contents}</div> - </div> - ); - } -} - -@observer -class PanelTitle extends Component<{ panel: Panel; className?: string }> { - render() { - const { panel, className } = this.props; - return ( - <div - className={classNames('lc-panel-title', className, { - actived: panel.actived, - })} - data-name={panel.name} - > - <Title title={panel.title || panel.name} /> - {panel.help ? <HelpTip help={panel.help} /> : null} - </div> - ); - } -} - -@observer -export class WidgetView extends Component<{ widget: IWidget }> { - private lastVisible = false; - private lastDisabled: boolean | undefined = false; - - componentDidMount() { - this.checkVisible(); - this.checkDisabled(); - } - - componentDidUpdate() { - this.checkVisible(); - this.checkDisabled(); - } - - checkVisible() { - const { widget } = this.props; - const currentVisible = widget.visible; - if (currentVisible !== this.lastVisible) { - this.lastVisible = currentVisible; - if (this.lastVisible) { - widget.skeleton.postEvent( - SkeletonEvents.WIDGET_SHOW, - widget.name, - widget, - ); - } else { - widget.skeleton.postEvent( - SkeletonEvents.WIDGET_SHOW, - widget.name, - widget, - ); - } - } - } - - checkDisabled() { - const { widget } = this.props; - const currentDisabled = widget.disabled; - if (currentDisabled !== this.lastDisabled) { - this.lastDisabled = currentDisabled; - if (this.lastDisabled) { - widget.skeleton.postEvent( - SkeletonEvents.WIDGET_DISABLE, - widget.name, - widget, - ); - } else { - widget.skeleton.postEvent( - SkeletonEvents.WIDGET_ENABLE, - widget.name, - widget, - ); - } - } - } - - render() { - const { widget } = this.props; - if (!widget.visible) { - return null; - } - if (widget.disabled) { - return <div className="lc-widget-disabled">{widget.body}</div>; - } - return widget.body; - } -} diff --git a/packages/workbench/src/components/widget-views/panel-operation-row.tsx b/packages/workbench/src/components/widget-views/panel-operation-row.tsx deleted file mode 100644 index ef727d4e4..000000000 --- a/packages/workbench/src/components/widget-views/panel-operation-row.tsx +++ /dev/null @@ -1,66 +0,0 @@ -import { Component, Fragment } from 'react'; -import { Button, Icon } from '@alifd/next'; -import { action, makeObservable } from '@alilc/lowcode-editor-core'; -import { IconFix } from '../../icons/fix'; -import { IconFloat } from '../../icons/float'; -import { Panel } from '../../widget/panel'; - -export default class PanelOperationRow extends Component<{ panel: Panel }> { - constructor(props: any) { - super(props); - makeObservable(this); - } - // fix or float - @action - setDisplay() { - const { panel } = this.props; - const current = panel; - if (!current) { - return; - } - - panel.skeleton.toggleFloatStatus(panel); - } - - render() { - const { panel } = this.props; - const isRightArea = this.props.panel.config?.area === 'rightArea'; - if (isRightArea) { - return null; - } - // can be set fixed by default - let canSetFixed = true; - if (panel?.config.props?.canSetFixed === false) { - canSetFixed = false; - } - - const hideTitleBar = panel?.config.props?.hideTitleBar; - - const areaName = panel?.parent?.name ?? ''; - const area = (panel.skeleton as any)[areaName]; - - return ( - <Fragment> - {!hideTitleBar && ( - <Fragment> - {canSetFixed && ( - // eslint-disable-next-line react/jsx-no-bind - <Button text className="lc-pane-icon-fix" onClick={this.setDisplay.bind(this)}> - {areaName === 'leftFloatArea' ? <IconFix /> : <IconFloat />} - </Button> - )} - <Button - text - className="lc-pane-icon-close" - onClick={() => { - area && area.setVisible(false); - }} - > - <Icon type="close" /> - </Button> - </Fragment> - )} - </Fragment> - ); - } -} diff --git a/packages/workbench/src/context.ts b/packages/workbench/src/context.ts deleted file mode 100644 index ee213e886..000000000 --- a/packages/workbench/src/context.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { createContext } from 'react'; -import { Skeleton } from './skeleton'; - -export const SkeletonContext = createContext<Skeleton>({} as any); diff --git a/packages/core/src/hotkey.ts b/packages/workbench/src/hotkey.ts similarity index 100% rename from packages/core/src/hotkey.ts rename to packages/workbench/src/hotkey.ts diff --git a/packages/workbench/src/icons/arrow.tsx b/packages/workbench/src/icons/arrow.tsx deleted file mode 100644 index ab96e0894..000000000 --- a/packages/workbench/src/icons/arrow.tsx +++ /dev/null @@ -1,11 +0,0 @@ - -import { SVGIcon, IconProps } from '@alilc/lowcode-utils'; - -export function IconArrow(props: IconProps) { - return ( - <SVGIcon viewBox="0 0 1024 1024" {...props}> - <path d="M512.002047 771.904425c-10.152221 0.518816-20.442588-2.800789-28.202319-10.598382L77.902254 315.937602c-14.548344-14.618952-14.548344-38.318724 0-52.933583 14.544251-14.614859 38.118156-14.614859 52.662407 0l381.437385 418.531212L893.432269 263.004019c14.544251-14.614859 38.125319-14.614859 52.662407 0 14.552437 14.614859 14.552437 38.314631 0 52.933583L540.205389 761.307066C532.451798 769.103636 522.158361 772.424264 512.002047 771.904425z" /> - </SVGIcon> - ); -} -IconArrow.displayName = 'Arrow'; diff --git a/packages/workbench/src/icons/clear.tsx b/packages/workbench/src/icons/clear.tsx deleted file mode 100644 index ff4287e90..000000000 --- a/packages/workbench/src/icons/clear.tsx +++ /dev/null @@ -1,11 +0,0 @@ -import { SVGIcon, IconProps } from '@alilc/lowcode-utils'; - -export function IconClear(props: IconProps) { - return ( - <SVGIcon viewBox="0 0 1024 1024" {...props}> - <path d="M761.6 701.44a21.333333 21.333333 0 0 1 0 30.293333l-29.866667 29.866667a21.333333 21.333333 0 0 1-30.293333 0L512 572.16l-189.44 189.44a21.333333 21.333333 0 0 1-30.293333 0l-29.866667-29.866667a21.333333 21.333333 0 0 1 0-30.293333L451.84 512 262.4 322.56a21.333333 21.333333 0 0 1 0-30.293333l29.866667-29.866667a21.333333 21.333333 0 0 1 30.293333 0L512 451.84l189.44-189.44a21.333333 21.333333 0 0 1 30.293333 0l29.866667 29.866667a21.333333 21.333333 0 0 1 0 30.293333L572.16 512z" /> - </SVGIcon> - ); -} - -IconClear.displayName = 'Clear'; diff --git a/packages/workbench/src/icons/convert.tsx b/packages/workbench/src/icons/convert.tsx deleted file mode 100644 index 62a877d33..000000000 --- a/packages/workbench/src/icons/convert.tsx +++ /dev/null @@ -1,11 +0,0 @@ -import { SVGIcon, IconProps } from '@alilc/lowcode-utils'; - -export function IconConvert(props: IconProps) { - return ( - <SVGIcon viewBox="0 0 1024 1024" {...props}> - <path d="M620.8 256c-12.8-12.8-32-12.8-44.8 0s-12.8 32 0 44.8l83.2 83.2H288c-19.2 0-32 12.8-32 32s12.8 32 32 32h448c6.4 0 32 0 32-32 0-19.2-6.4-25.6-6.4-25.6L620.8 256zM736 576H288c-6.4 0-32 0-32 32 0 19.2 6.4 25.6 6.4 25.6L403.2 768c12.8 12.8 32 12.8 44.8 0s12.8-32 0-44.8L364.8 640H736c19.2 0 32-12.8 32-32s-12.8-32-32-32zM512 64C262.4 64 64 262.4 64 512s198.4 448 448 448 448-198.4 448-448S761.6 64 512 64z m0 832c-211.2 0-384-172.8-384-384s172.8-384 384-384 384 172.8 384 384-172.8 384-384 384z" /> - </SVGIcon> - ); -} - -IconConvert.displayName = 'Convert'; diff --git a/packages/workbench/src/icons/exit.tsx b/packages/workbench/src/icons/exit.tsx deleted file mode 100644 index 8583ce3a2..000000000 --- a/packages/workbench/src/icons/exit.tsx +++ /dev/null @@ -1,11 +0,0 @@ - -import { SVGIcon, type IconProps } from '@alilc/lowcode-utils'; - -export function IconExit(props: IconProps) { - return ( - <SVGIcon viewBox="0 0 1024 1024" {...props}> - <path d="M723.872 478.4l-81.12-81.152L688 352l135.776 135.776L846.4 510.4 688 668.8l-45.248-45.28 81.12-81.12H384v-64h339.872zM576 896H256.192A64.16 64.16 0 0 1 192 831.84V192.16c0-35.424 28.704-64.16 64.192-64.16H576v64H288.224A31.968 31.968 0 0 0 256 223.744v576.512C256 817.44 270.4 832 288.224 832H576v64z" /> - </SVGIcon> - ); -} -IconExit.displayName = 'Exit'; diff --git a/packages/workbench/src/icons/fix.tsx b/packages/workbench/src/icons/fix.tsx deleted file mode 100644 index 6973c77b4..000000000 --- a/packages/workbench/src/icons/fix.tsx +++ /dev/null @@ -1,15 +0,0 @@ -import { SVGIcon, IconProps } from '@alilc/lowcode-utils'; - -export function IconFix(props: IconProps) { - const rect = { - width: 13, - height: 13, - }; - return ( - <SVGIcon viewBox="0 0 1024 1024" {...props} {...rect}> - <path d="M750.848 28.928l245.248 242.944a66.048 66.048 0 1 1-93.184 93.184l-25.6-19.456-249.6 353.792 78.336 78.336a66.048 66.048 0 0 1-93.184 92.672l-460.8-464.64a66.048 66.048 0 0 1 93.184-93.184l76.8 78.336 354.048-249.856-18.176-18.944a66.048 66.048 0 1 1 93.184-93.184zM380.672 732.416l-91.904-90.88c-74.24 89.6-191.488 219.904-212.736 247.04a419.84 419.84 0 0 0-70.656 128 419.84 419.84 0 0 0 128-70.144c27.136-21.248 157.44-138.496 246.528-214.016z" /> - </SVGIcon> - ); -} - -IconFix.displayName = 'Fix'; diff --git a/packages/workbench/src/icons/float.tsx b/packages/workbench/src/icons/float.tsx deleted file mode 100644 index afc42036a..000000000 --- a/packages/workbench/src/icons/float.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import { SVGIcon, IconProps } from '@alilc/lowcode-utils'; - -export function IconFloat(props: IconProps) { - return ( - <SVGIcon viewBox="0 0 1024 1024" {...props}> - <path d="M160.256 816.64C116.224 872.448 102.4 921.6 102.4 921.6s49.152-13.824 104.96-57.856c22.016-17.408 128-112.64 200.704-174.08l-73.728-73.728c-61.44 72.704-157.184 178.688-174.08 200.704zM648.704 209.408L442.368 355.328l226.304 226.304 145.92-206.336 15.872 15.872c20.992 20.992 54.784 20.992 75.776 0s20.992-54.784 0-75.776l-197.12-197.12c-20.992-20.992-54.784-20.992-75.776 0-20.992 20.992-20.992 54.784 0 75.776l15.36 15.36zM247.808 334.848c-9.728 2.048-18.944 6.656-26.624 14.336-20.992 20.992-20.992 54.784 0 75.776l377.856 377.856c20.992 20.992 54.784 20.992 75.776 0 7.68-7.68 12.288-16.896 14.336-26.624L247.808 334.848z" /> - <path d="M840.704 879.104c-9.728 0-19.456-3.584-27.136-11.264L155.648 210.432c-14.848-14.848-14.848-39.424 0-54.272 14.848-14.848 39.424-14.848 54.272 0L867.84 814.08c14.848 14.848 14.848 39.424 0 54.272-7.168 7.168-16.896 10.752-27.136 10.752z" /> - </SVGIcon> - ); -} - -IconFloat.displayName = 'Float'; diff --git a/packages/workbench/src/icons/slot.tsx b/packages/workbench/src/icons/slot.tsx deleted file mode 100644 index 8dadc4b75..000000000 --- a/packages/workbench/src/icons/slot.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import { SVGIcon, IconProps } from '@alilc/lowcode-utils'; - -export function IconSlot(props: IconProps) { - return ( - <SVGIcon viewBox="0 0 1024 1024" {...props}> - <path d="M682.325333 135.509333V204.8H819.2v613.376h-614.741333V204.8h136.874666v-69.290667h-206.165333v752.298667h754.346667V135.509333z" /> - <path d="M512 512m-170.325333 0a170.325333 170.325333 0 1 0 340.650666 0 170.325333 170.325333 0 1 0-340.650666 0Z" /> - </SVGIcon> - ); -} - -IconSlot.displayName = 'IconSlot'; diff --git a/packages/workbench/src/icons/variable.tsx b/packages/workbench/src/icons/variable.tsx deleted file mode 100644 index ce2e7a295..000000000 --- a/packages/workbench/src/icons/variable.tsx +++ /dev/null @@ -1,11 +0,0 @@ -import { SVGIcon, IconProps } from '@alilc/lowcode-utils'; - -export function IconVariable(props: IconProps) { - return ( - <SVGIcon viewBox="0 0 1024 1024" {...props}> - <path d="M596.32 263.392c18.048 6.56 27.328 26.496 20.8 44.512l-151.04 414.912a34.72 34.72 0 1 1-65.28-23.744l151.04-414.912a34.72 34.72 0 0 1 44.48-20.768zM220.64 192H273.6v55.488H233.024c-26.112 0-38.464 14.4-38.464 44.544v134.304c0 42.496-19.936 71.264-59.104 85.664 39.168 16.448 59.104 44.544 59.104 85.664v134.976c0 28.8 12.352 43.84 38.464 43.84H273.6V832H220.672c-30.24 0-53.6-10.272-70.08-29.44-15.136-17.856-22.72-42.496-22.72-72.64v-128.832c0-19.872-4.096-34.24-12.352-43.2-9.6-10.944-26.784-16.416-51.52-17.792v-56.192c24.736-1.376 41.92-7.52 51.52-17.824 8.256-9.6 12.384-24 12.384-43.168V294.784c0-30.848 7.552-55.488 22.688-73.312C167.04 201.6 190.4 192 220.672 192z m529.792 0h52.896c30.24 0 53.6 9.6 70.08 29.44 15.136 17.856 22.72 42.496 22.72 73.344v128.128c0 19.2 4.096 34.24 13.024 43.84 8.96 9.6 26.112 15.776 50.848 17.152v56.192c-24.736 1.376-41.92 6.848-51.52 17.824-8.256 8.896-12.384 23.296-12.384 43.168v128.8c0 30.176-7.552 54.816-22.688 72.64-16.48 19.2-39.84 29.472-70.08 29.472h-52.896v-55.488h40.544c25.408 0 38.464-15.104 38.464-43.84v-135.04c0-41.088 19.232-69.184 59.104-85.632-39.872-14.4-59.104-43.168-59.104-85.664V292.032c0-30.144-13.056-44.544-38.464-44.544H750.4V192z" /> - </SVGIcon> - ); -} - -IconVariable.displayName = 'Variable'; diff --git a/packages/workbench/src/index.ts b/packages/workbench/src/index.ts index a39b445d1..e69de29bb 100644 --- a/packages/workbench/src/index.ts +++ b/packages/workbench/src/index.ts @@ -1,11 +0,0 @@ -export * from './area'; -export { Workbench } from './layouts/workbench'; -export * from './skeleton'; -export * from './types'; -export * from './components/settings'; -export * from './components/field'; -export * from './components/popup'; -export * from './context'; -export * from './register-defaults'; -export * from './widget'; -export * from './layouts'; diff --git a/packages/workbench/src/layouts/bottom-area.tsx b/packages/workbench/src/layouts/bottom-area.tsx deleted file mode 100644 index 2981cc596..000000000 --- a/packages/workbench/src/layouts/bottom-area.tsx +++ /dev/null @@ -1,35 +0,0 @@ -import { Component, Fragment } from 'react'; -import classNames from 'classnames'; -import { observer } from '@alilc/lowcode-editor-core'; -import { Area } from '../area'; -import { Panel } from '../widget/panel'; - -@observer -export default class BottomArea extends Component<{ area: Area<any, Panel> }> { - render() { - const { area } = this.props; - if (area.isEmpty()) { - return null; - } - return ( - <div className={classNames('lc-bottom-area', { - 'lc-area-visible': area.visible, - })} - > - <Contents area={area} /> - </div> - ); - } -} - -@observer -class Contents extends Component<{ area: Area<any, Panel> }> { - render() { - const { area } = this.props; - return ( - <Fragment> - {area.container.items.map((item) => item.content)} - </Fragment> - ); - } -} diff --git a/packages/workbench/src/layouts/index.ts b/packages/workbench/src/layouts/index.ts deleted file mode 100644 index 16bcaef4d..000000000 --- a/packages/workbench/src/layouts/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -export { default as LeftArea } from './left-area'; -export { default as LeftFloatPane } from './left-float-pane'; -export { default as LeftFixedPane } from './left-fixed-pane'; -export { default as MainArea } from './main-area'; -export { default as BottomArea } from './bottom-area'; -export { default as TopArea } from './top-area'; -export { default as SubTopArea } from './sub-top-area'; diff --git a/packages/workbench/src/layouts/left-area.tsx b/packages/workbench/src/layouts/left-area.tsx deleted file mode 100644 index d30dcfa86..000000000 --- a/packages/workbench/src/layouts/left-area.tsx +++ /dev/null @@ -1,49 +0,0 @@ -import { Component, Fragment } from 'react'; -import classNames from 'classnames'; -import { observer } from '@alilc/lowcode-editor-core'; -import { Area } from '../area'; - -@observer -export default class LeftArea extends Component<{ area: Area; className?: string }> { - render() { - const { area, className = 'lc-left-area' } = this.props; - if (area.isEmpty()) { - return null; - } - return ( - <div className={classNames(className, { - 'lc-area-visible': area.visible, - })} - > - <Contents area={area} /> - </div> - ); - } -} - -@observer -class Contents extends Component<{ area: Area }> { - render() { - const { area } = this.props; - const top: any[] = []; - const bottom: any[] = []; - area.container.items.slice().sort((a, b) => { - const index1 = a.config?.index || 0; - const index2 = b.config?.index || 0; - return index1 === index2 ? 0 : (index1 > index2 ? 1 : -1); - }).forEach((item) => { - const content = <div key={`left-area-${item.name}`}>{item.content}</div>; - if (item.align === 'bottom') { - bottom.push(content); - } else { - top.push(content); - } - }); - return ( - <Fragment> - <div className="lc-left-area-top">{top}</div> - <div className="lc-left-area-bottom">{bottom}</div> - </Fragment> - ); - } -} diff --git a/packages/workbench/src/layouts/left-fixed-pane.tsx b/packages/workbench/src/layouts/left-fixed-pane.tsx deleted file mode 100644 index a56b44907..000000000 --- a/packages/workbench/src/layouts/left-fixed-pane.tsx +++ /dev/null @@ -1,43 +0,0 @@ -import { Component, Fragment } from 'react'; -import classNames from 'classnames'; -import { observer } from '@alilc/lowcode-editor-core'; -import { Area } from '../area'; -import { Panel } from '../widget/panel'; -import { IPublicTypePanelConfig } from '@alilc/lowcode-types'; - -@observer -export default class LeftFixedPane extends Component<{ area: Area<IPublicTypePanelConfig, Panel> }> { - componentDidUpdate() { - // FIXME: dirty fix, need deep think - this.props.area.skeleton.editor.get('designer')?.touchOffsetObserver(); - } - - render() { - const { area } = this.props; - const width = area.current?.config.props?.width; - const style = width - ? { - width, - } - : undefined; - - return ( - <div - className={classNames('lc-left-fixed-pane', { - 'lc-area-visible': area.visible, - })} - style={style} - > - <Contents area={area} /> - </div> - ); - } -} - -@observer -class Contents extends Component<{ area: Area<IPublicTypePanelConfig, Panel> }> { - render() { - const { area } = this.props; - return <Fragment>{area.container.items.map((panel) => panel.content)}</Fragment>; - } -} diff --git a/packages/workbench/src/layouts/left-float-pane.tsx b/packages/workbench/src/layouts/left-float-pane.tsx deleted file mode 100644 index 296f08321..000000000 --- a/packages/workbench/src/layouts/left-float-pane.tsx +++ /dev/null @@ -1,137 +0,0 @@ -import { Component, Fragment } from 'react'; -import classNames from 'classnames'; -import { observer, Focusable } from '@alilc/lowcode-editor-core'; -import { Area } from '../area'; -import { Panel } from '../widget/panel'; -import { IPublicApiProject, IPublicTypePanelConfig } from '@alilc/lowcode-types'; - -@observer -export default class LeftFloatPane extends Component<{ area: Area<IPublicTypePanelConfig, Panel> }> { - private dispose?: () => void; - - private focusing?: Focusable; - - private shell: HTMLElement | null = null; - - componentDidMount() { - const { area } = this.props; - const triggerClose = (e: any) => { - if (!area.visible) return; - // 当 MouseEvent 的 target 为「插入占位符」时,不关闭当前 panel - if (e.originalEvent?.target?.classList.contains('insertion')) return; - // 假如当前操作 target 祖先节点中有属性 data-keep-visible-while-dragging="true" 代表该 target 所属 panel - // 不希望 target 在 panel 范围内拖拽时关闭 panel - const panelElem = e.originalEvent?.target.closest('div[data-keep-visible-while-dragging="true"]'); - if (panelElem) return; - area.setVisible(false); - }; - area.skeleton.editor.eventBus.on('designer.drag', triggerClose); - - this.dispose = () => { - area.skeleton.editor.removeListener('designer.drag', triggerClose); - }; - - const project: IPublicApiProject | undefined = area.skeleton.editor.get('project'); - - this.focusing = area.skeleton.focusTracker.create({ - range: (e) => { - const target = e.target as HTMLElement; - if (!target) { - return false; - } - if (this.shell?.contains(target)) { - return true; - } - // 点击了 iframe 内容,算失焦 - if ((document.querySelector('.lc-simulator-content-frame') as HTMLIFrameElement)?.contentWindow?.document.documentElement.contains(target)) { - return false; - } - if (project?.simulatorHost?.contentWindow?.document.documentElement.contains(target)) { - return false; - } - // 点击设置区 - if (document.querySelector('.lc-right-area')?.contains(target)) { - return false; - } - // 点击非编辑区域的popup/dialog,插件栏左侧等不触发失焦 - if (!document.querySelector('.lc-workbench')?.contains(target)) { - return true; - } - // 排除设置区,iframe 之后,都不算失焦 - if (document.querySelector('.lc-workbench-body')?.contains(target)) { - return true; - } - const docks = area.current?.getAssocDocks(); - if (docks && docks?.length) { - return docks.some(dock => dock.getDOMNode()?.contains(target)); - } - return false; - }, - onEsc: () => { - this.props.area.setVisible(false); - }, - onBlur: () => { - this.props.area.setVisible(false); - }, - }); - - this.onEffect(); - } - - onEffect() { - const { area } = this.props; - if (area.visible) { - this.focusing?.active(); - // 关闭当前fixed区域的面板 - // TODO: 看看有没有更合适的地方 - const fixedContainer = area?.skeleton?.leftFixedArea?.container; - const currentFixed = fixedContainer?.current; - if (currentFixed) { - fixedContainer.unactive(currentFixed); - } - } else { - this.focusing?.suspense(); - } - } - - componentDidUpdate() { - this.onEffect(); - } - - componentWillUnmount() { - this.focusing?.purge(); - this.dispose?.(); - } - - render() { - const { area } = this.props; - const width = area.current?.config.props?.width; - - const style = width ? { - width, - } : undefined; - return ( - <div - ref={(ref) => { this.shell = ref; }} - className={classNames('lc-left-float-pane', { - 'lc-area-visible': area.visible, - })} - style={style} - > - <Contents area={area} /> - </div> - ); - } -} - -@observer -class Contents extends Component<{ area: Area<any, Panel> }> { - render() { - const { area } = this.props; - return ( - <Fragment> - {area.container.items.map((panel) => panel.content)} - </Fragment> - ); - } -} diff --git a/packages/workbench/src/layouts/main-area.tsx b/packages/workbench/src/layouts/main-area.tsx deleted file mode 100644 index 400d33795..000000000 --- a/packages/workbench/src/layouts/main-area.tsx +++ /dev/null @@ -1,18 +0,0 @@ -import { Component } from 'react'; -import classNames from 'classnames'; -import { observer } from '@alilc/lowcode-editor-core'; -import { Area } from '../area'; -import { Panel } from '../widget/panel'; -import { Widget } from '../widget/widget'; - -@observer -export default class MainArea extends Component<{ area: Area<any, Panel | Widget> }> { - render() { - const { area } = this.props; - return ( - <div className={classNames('lc-main-area engine-workspacepane')}> - {area.container.items.map((item) => item.content)} - </div> - ); - } -} diff --git a/packages/workbench/src/layouts/right-area.tsx b/packages/workbench/src/layouts/right-area.tsx deleted file mode 100644 index f00ae1461..000000000 --- a/packages/workbench/src/layouts/right-area.tsx +++ /dev/null @@ -1,45 +0,0 @@ -import { Component, Fragment } from 'react'; -import classNames from 'classnames'; -import { observer } from '@alilc/lowcode-editor-core'; -import { Area } from '../area'; -import { Panel } from '../widget/panel'; - -@observer -export default class RightArea extends Component<{ area: Area<any, Panel> }> { - render() { - const { area } = this.props; - if (area.isEmpty()) { - return null; - } - return ( - <div className={classNames('lc-right-area engine-tabpane', { - 'lc-area-visible': area.visible, - })} - > - <Contents area={area} /> - </div> - ); - } -} - -@observer -class Contents extends Component<{ area: Area<any, Panel> }> { - render() { - const { area } = this.props; - - return ( - <Fragment> - { - area.container.items - .slice() - .sort((a, b) => { - const index1 = a.config?.index || 0; - const index2 = b.config?.index || 0; - return index1 === index2 ? 0 : (index1 > index2 ? 1 : -1); - }) - .map((item) => item.content) - } - </Fragment> - ); - } -} diff --git a/packages/workbench/src/layouts/sub-top-area.tsx b/packages/workbench/src/layouts/sub-top-area.tsx deleted file mode 100644 index 59d1f3011..000000000 --- a/packages/workbench/src/layouts/sub-top-area.tsx +++ /dev/null @@ -1,73 +0,0 @@ -import { Component, Fragment } from 'react'; -import classNames from 'classnames'; -import { observer } from '@alilc/lowcode-editor-core'; -import { Area } from '../area'; - -@observer -export default class SubTopArea extends Component<{ area: Area; itemClassName?: string }> { - render() { - const { area, itemClassName } = this.props; - - if (area.isEmpty()) { - return null; - } - - return ( - <div - className={classNames('lc-workspace-sub-top-area lc-sub-top-area engine-actionpane', { - 'lc-area-visible': area.visible, - })} - > - <Contents area={area} itemClassName={itemClassName} /> - </div> - ); - } -} - -@observer -class Contents extends Component<{ area: Area; itemClassName?: string }> { - render() { - const { area, itemClassName } = this.props; - const left: any[] = []; - const center: any[] = []; - const right: any[] = []; - area.container.items - .slice() - .sort((a, b) => { - const index1 = a.config?.index || 0; - const index2 = b.config?.index || 0; - return index1 === index2 ? 0 : index1 > index2 ? 1 : -1; - }) - .forEach((item) => { - const content = ( - <div className={itemClassName || ''} key={`top-area-${item.name}`}> - {item.content} - </div> - ); - if (item.align === 'center') { - center.push(content); - } else if (item.align === 'left') { - left.push(content); - } else { - right.push(content); - } - }); - const children = []; - if (left && left.length) { - children.push( - <div className="lc-workspace-sub-top-area-left lc-sub-top-area-left">{left}</div>, - ); - } - if (center && center.length) { - children.push( - <div className="lc-workspace-sub-top-area-center lc-sub-top-area-center">{center}</div>, - ); - } - if (right && right.length) { - children.push( - <div className="lc-workspace-sub-top-area-right lc-sub-top-area-right">{right}</div>, - ); - } - return <Fragment>{children}</Fragment>; - } -} diff --git a/packages/workbench/src/layouts/theme.less b/packages/workbench/src/layouts/theme.less deleted file mode 100644 index aa3af86cf..000000000 --- a/packages/workbench/src/layouts/theme.less +++ /dev/null @@ -1,75 +0,0 @@ -@import '../less-variables.less'; - -/* - * Theme Colors - * - * 乐高设计器的主要主题色变量 - */ -:root { - --color-brand: @brand-color-1; - --color-brand-light: @brand-color-2; - --color-brand-dark: @brand-color-3; - - --color-canvas-background: @normal-alpha-8; - - --color-icon-normal: @normal-alpha-4; - --color-icon-hover: @normal-alpha-3; - --color-icon-light: @normal-alpha-5; - --color-icon-active: @brand-color-1; - --color-icon-reverse: @white-alpha-1; - --color-icon-disabled: @normal-alpha-6; - --color-icon-pane: @dark-alpha-3; - - --color-line-normal: @normal-alpha-7; - --color-line-darken: darken(@normal-alpha-7, 10%); - - --color-title: @dark-alpha-2; - --color-text: @dark-alpha-3; - --color-text-dark: darken(@dark-alpha-3, 10%); - --color-text-light: lighten(@dark-alpha-3, 10%); - --color-text-reverse: @white-alpha-2; - --color-text-disabled: @gray-light; - - --color-field-label: @dark-alpha-4; - --color-field-text: @dark-alpha-3; - --color-field-placeholder: @normal-alpha-5; - --color-field-border: @normal-alpha-5; - --color-field-border-hover: @normal-alpha-4; - --color-field-border-active: @normal-alpha-3; - --color-field-background: @white-alpha-1; - - --color-success: @brand-success; - --colo-success-dark: darken(@brand-success, 10%); - --color-success-light: lighten(@brand-success, 10%); - --color-warning: @brand-warning; - --color-warning-dark: darken(@brand-warning, 10%); - --color-warning-light: lighten(@brand-warning, 10%); - --color-information: @brand-link-hover; - --color-information-dark: darken(@brand-link-hover, 10%); - --color-information-light: lighten(@brand-link-hover, 10%); - --color-error: @brand-danger; - --color-error-dark: darken(@brand-danger, 10%); - --color-error-light: lighten(@brand-danger, 10%); - --color-purple: rgb(144, 94, 190); - --color-brown: #7b605b; - - --color-pane-background: @white-alpha-1; - --color-block-background-normal: @white-alpha-1; - --color-block-background-light: @normal-alpha-9; - --color-block-background-dark: @normal-alpha-7; - --color-block-background-shallow: @normal-alpha-8; - --color-block-background-disabled: @normal-alpha-6; - --color-block-background-active: @brand-color-1; - --color-block-background-active-light: @brand-color-1-7; - --color-block-background-warning: @brand-warning-alpha-7; - --color-block-background-error: @brand-danger-alpha-7; - --color-block-background-success: @brand-success-alpha-7; - --color-block-background-deep-dark: @normal-5; - --color-layer-mask-background: @dark-alpha-7; - --color-layer-tooltip-background: rgba(44,47,51,0.8); - --color-background: #edeff3; - - --color-canvas-detecting-background: rgba(0,121,242,.04); - - --pane-title-bg-color: rgba(31,56,88,.04); -} diff --git a/packages/workbench/src/layouts/toolbar.tsx b/packages/workbench/src/layouts/toolbar.tsx deleted file mode 100644 index 9b7d1c9b6..000000000 --- a/packages/workbench/src/layouts/toolbar.tsx +++ /dev/null @@ -1,49 +0,0 @@ -import { Component, Fragment } from 'react'; -import classNames from 'classnames'; -import { observer } from '@alilc/lowcode-editor-core'; -import { Area } from '../area'; - -@observer -export default class Toolbar extends Component<{ area: Area }> { - render() { - const { area } = this.props; - if (area.isEmpty()) { - return null; - } - return ( - <div - className={classNames('lc-toolbar', { - 'lc-area-visible': area.visible, - })} - > - <Contents area={area} /> - </div> - ); - } -} - -@observer -class Contents extends Component<{ area: Area }> { - render() { - const { area } = this.props; - const left: any[] = []; - const center: any[] = []; - const right: any[] = []; - area.container.items.forEach((item) => { - if (item.align === 'center') { - center.push(item.content); - } else if (item.align === 'right') { - right.push(item.content); - } else { - left.push(item.content); - } - }); - return ( - <Fragment> - <div className="lc-toolbar-left">{left}</div> - <div className="lc-toolbar-center">{center}</div> - <div className="lc-toolbar-right">{right}</div> - </Fragment> - ); - } -} diff --git a/packages/workbench/src/layouts/top-area.tsx b/packages/workbench/src/layouts/top-area.tsx deleted file mode 100644 index 5204899b4..000000000 --- a/packages/workbench/src/layouts/top-area.tsx +++ /dev/null @@ -1,58 +0,0 @@ -import { Component, Fragment } from 'react'; -import classNames from 'classnames'; -import { observer } from '@alilc/lowcode-editor-core'; -import { Area } from '../area'; - -@observer -export default class TopArea extends Component< - { area: Area; itemClassName?: string; className?: string } -> { - render() { - const { area, itemClassName, className } = this.props; - if (area.isEmpty()) { - return null; - } - return ( - <div className={classNames(className, 'lc-top-area engine-actionpane', { - 'lc-area-visible': area.visible, - })}> - <Contents area={area} itemClassName={itemClassName} /> - </div> - ); - } -} - -@observer -class Contents extends Component<{ area: Area; itemClassName?: string }> { - render() { - const { area, itemClassName } = this.props; - const left: any[] = []; - const center: any[] = []; - const right: any[] = []; - area.container.items.slice().sort((a, b) => { - const index1 = a.config?.index || 0; - const index2 = b.config?.index || 0; - return index1 === index2 ? 0 : (index1 > index2 ? 1 : -1); - }).forEach(item => { - const content = ( - <div className={itemClassName || ''} key={`top-area-${item.name}`}> - {item.content} - </div> - ); - if (item.align === 'center') { - center.push(content); - } else if (item.align === 'left') { - left.push(content); - } else { - right.push(content); - } - }); - return ( - <Fragment> - <div className="lc-top-area-left">{left}</div> - <div className="lc-top-area-center">{center}</div> - <div className="lc-top-area-right">{right}</div> - </Fragment> - ); - } -} diff --git a/packages/workbench/src/layouts/workbench.less b/packages/workbench/src/layouts/workbench.less deleted file mode 100644 index 9c7a9815d..000000000 --- a/packages/workbench/src/layouts/workbench.less +++ /dev/null @@ -1,498 +0,0 @@ -@import './theme.less'; - -:root { - --font-family: @font-family; - --font-size-label: @fontSize-4; - --font-size-text: @fontSize-5; - --font-size-btn-large: @fontSize-3; - --font-size-btn-medium: @fontSize-4; - --font-size-btn-small: @fontSize-5; - - --global-border-radius: @global-border-radius; - --input-border-radius: @input-border-radius; - --popup-border-radius: @popup-border-radius; - - --left-area-width: 48px; - --workspace-left-area-width: 48px; - --right-area-width: 300px; - --top-area-height: 48px; - --toolbar-height: 36px; - --dock-pane-width: 300px; - --dock-fixed-pane-width: 300px; -} - -@media (min-width: 1860px) { - :root { - --right-area-width: 400px; - --dock-pane-width: 452px; - --dock-fixed-pane-width: 350px; - } -} - -html, -body { - height: 100%; - overflow: hidden; - padding: 0; - margin: 0; - position: relative; - font-family: var(--font-family); - font-size: var(--font-size-text); - color: var(--color-text); - background-color: var(--color-background); -} - -* { - box-sizing: border-box; -} - -.lc-titled-panel { - width: 100%; - height: 100%; - position: relative; - &.hidden { - display: none; - } - .lc-panel-title { - display: flex; - align-items: center; - justify-content: flex-start; - padding: 0 15px; - - .lc-help-tip { - margin-left: 4px; - color: var(--color-icon-normal, rgba(0, 0, 0, 0.4)); - cursor: pointer; - } - } - > .lc-panel-title { - height: var(--pane-title-height, 48px); - font-size: var(--pane-title-font-size, 16px); - padding: var(--pane-title-padding, 0 15px); - color: var(--color-title, #0f1726); - font-weight: bold; - } - - .lc-panel-body { - position: absolute; - top: var(--pane-title-height, 48px); - bottom: 0; - left: 0; - right: 0; - overflow: visible; - } - .lc-outline-tree-container { - border-top: 1px solid var(--color-line-normal, rgba(31, 56, 88, 0.1)); - } -} -.lc-panel { - height: 100%; - width: 100%; - position: relative; - &.hidden { - display: none; - } -} - -.workspace-engine-main { - height: 100%; - display: flex; - flex-direction: column; - background-color: var(--color-background); - position: absolute; - left: 0; - top: 0; - right: 0; - bottom: 0; - z-index: -1; - overflow: hidden; - - &.active { - z-index: 999; - } - - .lc-workbench { - - } - - .engine-editor-view { - position: absolute; - top: 0; - left: 0; - right: 0; - bottom: 0; - display: flex; - flex-direction: column; - - &.active { - z-index: 999; - background: var(--color-background); - } - } -} - -.lc-workbench, .lc-workspace-workbench { - height: 100%; - display: flex; - flex-direction: column; - background-color: var(--color-background); - - &.engine-main { - height: 100%; - display: flex; - flex-direction: column; - background-color: var(--color-background); - } - .lc-top-area, .lc-workspace-sub-top-area { - width: 100%; - display: none; - margin-bottom: 2px; - padding: 8px 12px 8px 16px; - - &.lc-top-area { - background-color: var(--color-top-area-background, var(--color-pane-background)); - height: var(--top-area-height); - } - - &.lc-workspace-top-area { - background-color: var(--color-workspace-top-area-background, var(--color-pane-background)); - } - - &.lc-workspace-sub-top-area { - background-color: var(--color-workspace-sub-top-area-background, var(--color-pane-background)); - height: var(--workspace-sub-top-area-height, var(--top-area-height)); - margin: var(--workspace-sub-top-area-margin, 0px 0px 2px 0px); - padding: var(--workspace-sub-top-area-padding, 8px 12px 8px 16px); - } - - &.lc-area-visible { - display: flex; - } - - .lc-top-area-left, .lc-workspace-sub-top-area-left { - display: flex; - align-items: center; - max-width: 100%; - } - - .lc-top-area-center, .lc-workspace-sub-top-area-center { - flex: 1; - display: flex; - justify-content: center; - margin: 0 8px; - } - .lc-top-area-right, .lc-workspace-sub-top-area-right { - display: flex; - align-items: center; - > * { - margin-left: 4px; - margin-right: 4px; - } - .ve-quick-search-trigger { - display: flex; - } - } - } - .lc-workbench-body, .lc-workspace-workbench-body { - flex: 1; - display: flex; - min-height: 0; - position: relative; - - .lc-tabs-title { - width: 100%; - height: 32px; - position: relative; - display: center; - display: flex; - justify-content: center; - align-items: center; - border-bottom: 1px solid var(--color-line-normal, #edeff3); - .lc-tab-title { - flex: 1; - height: 32px; - display: flex; - align-items: center; - justify-content: center; - border-bottom: 2px solid transparent; - cursor: pointer; - font-size: 12px; - &.actived { - color: var(--color-brand, #0079f2); - border-bottom-color: var(--color-brand, #0079f2); - } - } - } - - .lc-tabs-content { - position: absolute; - top: 32px; - bottom: 0; - left: 0; - right: 0; - } - - .lc-pane-icon-close { - position: absolute; - right: 16px; - top: calc(var(--pane-title-height, 48px) / 2 - 10px); - height: auto; - z-index: 2; - .next-icon { - line-height: 1; - color: var(--color-icon-pane); - } - } - - .lc-pane-icon-fix, - .lc-pane-icon-float { - position: absolute; - right: 38px; - top: calc(var(--pane-title-height, 48px) / 2 - 10px); - height: auto; - z-index: 2; - svg { - vertical-align: middle; - color: var(--color-icon-pane); - } - } - - .lc-left-float-pane { - position: absolute; - top: 0; - bottom: 0; - width: var(--dock-pane-width); - // min-width: var(--dock-fixed-pane-width); - left: calc(var(--left-area-width) + 1px); - background-color: var(--color-left-float-pane-background, var(--color-pane-background)); - box-shadow: 4px 6px 6px 0 var(--color-block-background-shallow, rgba(31, 50, 88, 0.08)); - z-index: 820; - display: none; - // padding-top: 36px; - &.lc-area-visible { - display: block; - } - } - .lc-left-area, .lc-workspace-left-area { - height: 100%; - width: var(--workspace-left-area-width, --left-area-width); - display: none; - flex-shrink: 0; - flex-direction: column; - justify-content: space-between; - overflow: hidden; - background-color: var(--color-left-area-background, var(--color-pane-background)); - - &.lc-workspace-left-area { - background-color: var(--color-workspace-left-area-background, var(--color-pane-background)); - } - &.lc-area-visible { - display: flex; - } - .lc-left-area-top, - .lc-left-area-bottom { - width: 100%; - display: flex; - flex-direction: column; - justify-content: flex-start; - align-items: center; - color: var(--color-text); - - .lc-title { - flex-direction: column; - width: calc(var(--left-area-width) - 2px); - height: 46px; - display: flex; - align-items: center; - justify-content: center; - cursor: pointer; - - &.has-tip { - cursor: pointer; - } - &.actived { - color: var(--color-brand, #0079f2); - } - &.disabled { - opacity: 0.4; - } - .lc-title-icon { - height: 20px; - width: 20px; - margin: 0; - .next-icon:before { - line-height: 1 !important; - } - } - } - } - .lc-left-area-top { - padding-top: 12px; - } - .lc-left-area-bottom { - padding-bottom: 12px; - } - } - .lc-left-fixed-pane { - width: var(--dock-fixed-pane-width); - background-color: var(--color-pane-background); - height: 100%; - display: none; - flex-shrink: 0; - position: relative; - z-index: 820; - &.lc-area-visible { - display: block; - } - } - .lc-left-area.lc-area-visible ~ .lc-left-fixed-pane { - margin-left: 1px; - } - .lc-left-area.lc-area-visible ~ .lc-workbench-center { - margin-left: 2px; - } - .lc-workspace-left-area.lc-area-visible ~ .lc-workspace-workbench-center { - margin-left: 2px; - } - .lc-outline-pane { - .lc-outline-tree .tree-node .tree-node-title { - border-bottom: none; - } - } - .lc-workbench-center { - flex: 1; - display: flex; - flex-direction: column; - - .lc-toolbar { - display: flex; - height: var(--toolbar-height); - background-color: var(--color-toolbar-background, var(--color-pane-background)); - padding: var(--toolbar-padding, 8px 16px); - .lc-toolbar-center { - display: flex; - justify-content: center; - align-items: center; - flex: 1; - } - } - .lc-main-area { - flex: 1; - background-color: var(--color-background); - } - .lc-bottom-area { - height: var(--bottom-area-height); - background-color: var(--color-pane-background); - display: none; - &.lc-area-visible { - display: block; - } - } - } - .lc-right-area { - height: 100%; - width: var(--right-area-width); - background-color: var(--color-right-area-background, var(--color-pane-background)); - display: none; - flex-shrink: 0; - margin-left: 2px; - position: relative; - > .lc-panel { - position: absolute; - background-color: var(--color-right-area-background, var(--color-pane-background, #fff)); - left: 0; - top: 0; - z-index: 1; - } - &.lc-area-visible { - display: block; - } - .lc-settings-tabs { - > .next-tabs-nav-extra { - top: 36px !important; - } - .lc-settings-tab-item { - .next-tabs-tab-inner { - font-size: 12px; - line-height: 12px; - } - } - .lc-title { - color: inherit; - line-height: inherit !important; - } - } - .lc-settings-tabs-content { - top: 66px; - } - } - } - .engine-actionitem { - max-width: 100%; - color: var(--color-text); - } -} - -.lc-workspace-workbench { - height: 100%; - display: flex; - flex-direction: column; - background-color: var(--color-background); - .lc-workspace-workbench-body { - flex: 1; - display: flex; - min-height: 0; - position: relative; - - > .lc-left-float-pane { - left: calc(var(--workspace-left-area-width, var(--left-area-width)) + 1px); - } - - .lc-workspace-workbench-center { - flex: 1; - display: flex; - flex-direction: column; - z-index: 10; - position: relative; - .lc-toolbar { - display: flex; - height: var(--toolbar-height); - background-color: var(--color-toolbar-background, var(--color-pane-background)); - padding: var(--toolbar-padding, 8px 16px); - .lc-toolbar-center { - display: flex; - justify-content: center; - align-items: center; - flex: 1; - } - } - .lc-main-area { - flex: 1; - } - .lc-bottom-area { - height: var(--bottom-area-height); - background-color: var(--color-pane-background); - display: none; - &.lc-area-visible { - display: block; - } - } - } - - .lc-workspace-workbench-center-content { - position: absolute; - top: 0; - right: 0; - bottom: 0; - left: 0; - flex-direction: column; - display: flex; - align-content: stretch; - } - - .lc-workspace-workbench-window { - position: relative; - height: 100%; - } - } -} diff --git a/packages/workbench/src/layouts/workbench.tsx b/packages/workbench/src/layouts/workbench.tsx deleted file mode 100644 index 3efd624c6..000000000 --- a/packages/workbench/src/layouts/workbench.tsx +++ /dev/null @@ -1,59 +0,0 @@ -import { Component } from 'react'; -import { observer } from '@alilc/lowcode-editor-core'; -import { TipContainer } from '@alilc/lowcode-designer'; -import classNames from 'classnames'; -import { Skeleton } from '../skeleton'; -import TopArea from './top-area'; -import LeftArea from './left-area'; -import LeftFixedPane from './left-fixed-pane'; -import LeftFloatPane from './left-float-pane'; -import Toolbar from './toolbar'; -import MainArea from './main-area'; -import BottomArea from './bottom-area'; -import RightArea from './right-area'; -import { SkeletonContext } from '../context'; -import { EditorConfig, PluginClassSet } from '@alilc/lowcode-types'; - -import './workbench.less'; - -@observer -export class Workbench extends Component<{ - skeleton: Skeleton; - config?: EditorConfig; - components?: PluginClassSet; - className?: string; - topAreaItemClassName?: string; -}> { - constructor(props: any) { - super(props); - const { config, components, skeleton } = this.props; - skeleton.buildFromConfig(config, components); - } - - render() { - const { - skeleton, - className = 'engine-main', - topAreaItemClassName = 'engine-actionitem', - } = this.props; - return ( - <div className={classNames('lc-workbench', className)}> - <SkeletonContext.Provider value={this.props.skeleton}> - <TopArea area={skeleton.topArea} itemClassName={topAreaItemClassName} /> - <div className="lc-workbench-body"> - <LeftArea area={skeleton.leftArea} /> - <LeftFloatPane area={skeleton.leftFloatArea} /> - <LeftFixedPane area={skeleton.leftFixedArea} /> - <div className="lc-workbench-center"> - <Toolbar area={skeleton.toolbar} /> - <MainArea area={skeleton.mainArea} /> - <BottomArea area={skeleton.bottomArea} /> - </div> - <RightArea area={skeleton.rightArea} /> - </div> - <TipContainer /> - </SkeletonContext.Provider> - </div> - ); - } -} diff --git a/packages/workbench/src/less-variables.less b/packages/workbench/src/less-variables.less deleted file mode 100644 index 017e432ce..000000000 --- a/packages/workbench/src/less-variables.less +++ /dev/null @@ -1,215 +0,0 @@ -/* - * 基础的 DPL 定义使用了 kuma base 的定义,参考: - * https://github.com/uxcore/kuma-base/tree/master/variables - */ - -/** - * =========================================================== - * ==================== Font Family ========================== - * =========================================================== - */ - -/* - * @font-family: "STHeiti", "Microsoft Yahei", "Lucida Grande", "Lucida Sans Unicode", Helvetica, Arial, Verdana, sans-serif; - */ - -@font-family: 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', Helvetica, Arial, sans-serif; -@font-family-code: Monaco, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', Helvetica, Arial, - sans-serif; - -/** - * =========================================================== - * ===================== Color DPL =========================== - * =========================================================== - */ - -@brand-color-1: rgba(0, 108, 255, 1); -@brand-color-2: rgba(25, 122, 255, 1); -@brand-color-3: rgba(0, 96, 229, 1); - -@brand-color-1-3: rgba(0, 108, 255, 0.6); -@brand-color-1-4: rgba(0, 108, 255, 0.4); -@brand-color-1-5: rgba(0, 108, 255, 0.3); -@brand-color-1-6: rgba(0, 108, 255, 0.2); -@brand-color-1-7: rgba(0, 108, 255, 0.1); - -@brand-color: @brand-color-1; - -@white-alpha-1: rgb(255, 255, 255); // W-1 -@white-alpha-2: rgba(255, 255, 255, 0.8); // W-2 A80 -@white-alpha-3: rgba(255, 255, 255, 0.6); // W-3 A60 -@white-alpha-4: rgba(255, 255, 255, 0.4); // W-4 A40 -@white-alpha-5: rgba(255, 255, 255, 0.3); // W-5 A30 -@white-alpha-6: rgba(255, 255, 255, 0.2); // W-6 A20 -@white-alpha-7: rgba(255, 255, 255, 0.1); // W-7 A10 -@white-alpha-8: rgba(255, 255, 255, 0.06); // W-8 A6 - -@dark-alpha-1: rgba(0, 0, 0, 1); // D-1 A100 -@dark-alpha-2: rgba(0, 0, 0, 0.8); // D-2 A80 -@dark-alpha-3: rgba(0, 0, 0, 0.6); // D-3 A60 -@dark-alpha-4: rgba(0, 0, 0, 0.4); // D-4 A40 -@dark-alpha-5: rgba(0, 0, 0, 0.3); // D-5 A30 -@dark-alpha-6: rgba(0, 0, 0, 0.2); // D-6 A20 -@dark-alpha-7: rgba(0, 0, 0, 0.1); // D-7 A10 -@dark-alpha-8: rgba(0, 0, 0, 0.06); // D-8 A6 -@dark-alpha-9: rgba(0, 0, 0, 0.04); // D-9 A4 - -@normal-alpha-1: rgba(31, 56, 88, 1); // N-1 A100 -@normal-alpha-2: rgba(31, 56, 88, 0.8); // N-2 A80 -@normal-alpha-3: rgba(31, 56, 88, 0.6); // N-3 A60 -@normal-alpha-4: rgba(31, 56, 88, 0.4); // N-4 A40 -@normal-alpha-5: rgba(31, 56, 88, 0.3); // N-5 A30 -@normal-alpha-6: rgba(31, 56, 88, 0.2); // N-6 A20 -@normal-alpha-7: rgba(31, 56, 88, 0.1); // N-7 A10 -@normal-alpha-8: rgba(31, 56, 88, 0.06); // N-8 A6 -@normal-alpha-9: rgba(31, 56, 88, 0.04); // N-9 A4 - -@normal-3: #77879c; -@normal-4: #a3aebd; -@normal-5: #bac3cc; -@normal-6: #d1d7de; - -@gray-dark: #333; // N2_4 -@gray: #666; // N2_3 -@gray-light: #999; // N2_2 -@gray-lighter: #ccc; // N2_1 - -@brand-secondary: #2c2f33; // B2_3 -// 补色 -@brand-complement: #00b3e8; // B3_1 -// 复合 -@brand-comosite: #00c587; // B3_2 -// 浓度 -@brand-deep: #73461d; // B3_3 - -// F1-1 -@brand-danger: rgb(240, 70, 49); -// F1-2 (10% white) -@brand-danger-hover: rgba(240, 70, 49, 0.9); -// F1-3 (5% black) -@brand-danger-focus: rgba(240, 70, 49, 0.95); - -// F2-1 -@brand-warning: rgb(250, 189, 14); -// F3-1 -@brand-success: rgb(102, 188, 92); -// F4-1 -@brand-link: rgb(102, 188, 92); -// F4-2 -@brand-link-hover: #2e76a6; - -// F1-1-7 A10 -@brand-danger-alpha-7: rgba(240, 70, 49, 0.1); -// F1-1-8 A6 -@brand-danger-alpha-8: rgba(240, 70, 49, 0.8); -// F2-1-2 A80 -@brand-warning-alpha-2: rgba(250, 189, 14, 0.8); -// F2-1-7 A10 -@brand-warning-alpha-7: rgba(250, 189, 14, 0.1); -// F3-1-2 A80 -@brand-success-alpha-2: rgba(102, 188, 92, 0.8); -// F3-1-7 A10 -@brand-success-alpha-7: rgba(102, 188, 92, 0.1); -// F4-1-7 A10 -@brand-link-alpha-7: rgba(102, 188, 92, 0.1); - -// 文本色 -@text-primary-color: @dark-alpha-3; -@text-secondary-color: @normal-alpha-3; -@text-thirdary-color: @dark-alpha-4; -@text-disabled-color: @normal-alpha-5; -@text-helper-color: @dark-alpha-4; -@text-danger-color: @brand-danger; -@text-ali-color: #ec6c00; - -/** - * =========================================================== - * =================== Shadow Box ============================ - * =========================================================== - */ - -@box-shadow-1: 0 1px 4px 0 rgba(31, 56, 88, 0.15); // 1 级阴影,物体由原来存在于底面的物体展开,物体和底面关联紧密 -@box-shadow-2: 0 2px 10px 0 rgba(31, 56, 88, 0.15); // 2 级阴影,hover状态,物体层级较高 -@box-shadow-3: 0 4px 15px 0 rgba(31, 56, 88, 0.15); // 3 级阴影,当物体层级高于所有界面元素,弹窗用 - -/** - * =========================================================== - * ================= FontSize of Level ======================= - * =========================================================== - */ - -@fontSize-1: 26px; -@fontSize-2: 20px; -@fontSize-3: 16px; -@fontSize-4: 14px; -@fontSize-5: 12px; - -@fontLineHeight-1: 38px; -@fontLineHeight-2: 30px; -@fontLineHeight-3: 26px; -@fontLineHeight-4: 24px; -@fontLineHeight-5: 20px; - -/** - * =========================================================== - * ================= FontSize of Level ======================= - * =========================================================== - */ - -@global-border-radius: 3px; -@input-border-radius: 3px; -@popup-border-radius: 6px; - -/** - * =========================================================== - * ===================== Transistion ========================= - * =========================================================== - */ - -@transition-duration: 0.3s; -@transition-ease: cubic-bezier(0.23, 1, 0.32, 1); -@transition-delay: 0s; - -/** - * =========================================================== - * ================ Global Configruations ==================== - * =========================================================== - */ - -@topPaneHeight: 48px; -@actionpane-height: 48px; -@tabPaneWidth: 260px; -@input-standard-height: 32px; -@dockpane-width: 48px; - -/** - * =========================================================== - * =================== Deprecated Items ====================== - * =========================================================== - */ - -@head-bgcolor: @white-alpha-1; -@pane-bgcolor: @white-alpha-1; -@pane-dark-bgcolor: @white-alpha-1; -@pane-bdcolor: @normal-4; -@blank-bgcolor: @normal-5; -@title-bgcolor: @white-alpha-1; -@title-bdcolor: transparent; -@section-bgcolor: transparent; -@section-bdcolor: @white-alpha-1; -@button-bgcolor: @white-alpha-1; -@button-bdcolor: transparent; -@button-blue-color: @brand-color; -@button-blue-hover-color: @brand-color; -@sub-title-bgcolor: @white-alpha-1; -@sub-title-bdcolor: transparent; -@text-color: @text-primary-color; -@icon-color: @gray; -@icon-color-active: @gray-light; -@ghost-bgcolor: @dark-alpha-3; -@input-bgcolor: transparent; -@input-bdcolor: @normal-alpha-5; -@hover-color: #5a99cc; -@active-color: #5a99cc; -@disabled-color: #666; -@setter-popup-bg: rgb(80, 86, 109); diff --git a/packages/workbench/src/locale/en-US.json b/packages/workbench/src/locale/en-US.json deleted file mode 100644 index 36abb6395..000000000 --- a/packages/workbench/src/locale/en-US.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "Binded: {expr}": "Binded: {expr}", - "Variable Binding": "Variable Binding", - "Switch Setter": "Switch Setter", - "Multiple Value, Click to Clear": "Multiple Value, Click to Clear", - "Required": "Required", - "Setted Value, Click to Clear": "Setted Value, Click to Clear", - "Multiple Value": "Multiple Value", - "Attribute: ": "Attribute: ", - "Description: ": "Description: ", - "Please select a node in canvas": "Please select a node in canvas", - "Current node is locked": "Current node is locked", - "No config found for this type of component": "No config found for this type of component", - "Please select same kind of components": "Please select same kind of components" -} diff --git a/packages/workbench/src/locale/index.ts b/packages/workbench/src/locale/index.ts deleted file mode 100644 index 4cb3b53cf..000000000 --- a/packages/workbench/src/locale/index.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { createIntl } from '@alilc/lowcode-editor-core'; -import enUS from './en-US.json'; -import zhCN from './zh-CN.json'; - -const { intl, intlNode, getLocale, setLocale } = createIntl({ - 'en-US': enUS, - 'zh-CN': zhCN, -}); - -export { intl, intlNode, getLocale, setLocale }; diff --git a/packages/workbench/src/locale/zh-CN.json b/packages/workbench/src/locale/zh-CN.json deleted file mode 100644 index c347ad20d..000000000 --- a/packages/workbench/src/locale/zh-CN.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "Binded: {expr}": "已绑定:{expr}", - "Variable Binding": "变量绑定", - "Switch Setter": "切换设置器", - "Multiple Value, Click to Clear": "多种值,点击清除", - "Required": "必填项", - "Setted Value, Click to Clear": "已设置值,点击清除", - "Multiple Value": "多种值", - "Attribute: ": "属性:", - "Description: ": "说明:", - "Please select a node in canvas": "请在左侧画布选中节点", - "Current node is locked": "该节点已被锁定,无法配置", - "No config found for this type of component": "该组件暂无配置", - "Please select same kind of components": "请选中同一类型节点编辑" -} diff --git a/packages/workbench/src/module.d.ts b/packages/workbench/src/module.d.ts deleted file mode 100644 index ebf77e1a4..000000000 --- a/packages/workbench/src/module.d.ts +++ /dev/null @@ -1 +0,0 @@ -declare module 'ric-shim'; diff --git a/packages/core/src/preference.ts b/packages/workbench/src/preference.ts similarity index 100% rename from packages/core/src/preference.ts rename to packages/workbench/src/preference.ts diff --git a/packages/workbench/src/register-defaults.ts b/packages/workbench/src/register-defaults.ts deleted file mode 100644 index 6a6e9a20d..000000000 --- a/packages/workbench/src/register-defaults.ts +++ /dev/null @@ -1,22 +0,0 @@ -import parseJSFunc from './transducers/parse-func'; -import parseProps from './transducers/parse-props'; -import addonCombine from './transducers/addon-combine'; -import { IPublicModelPluginContext } from '@alilc/lowcode-types'; - -export const registerDefaults = (ctx: IPublicModelPluginContext) => { - const { material } = ctx; - return { - init() { - // parseFunc - material.registerMetadataTransducer(parseJSFunc, 1, 'parse-func'); - - // parseProps - material.registerMetadataTransducer(parseProps, 5, 'parse-props'); - - // addon/platform custom - material.registerMetadataTransducer(addonCombine, 10, 'combine-props'); - }, - }; -}; - -registerDefaults.pluginName = '___register_defaults___'; diff --git a/packages/workbench/src/skeleton.ts b/packages/workbench/src/skeleton.ts deleted file mode 100644 index b79089dd3..000000000 --- a/packages/workbench/src/skeleton.ts +++ /dev/null @@ -1,481 +0,0 @@ -import { action, makeObservable, observable, engineConfig, IEditor, FocusTracker } from '@alilc/lowcode-editor-core'; -import { - DockConfig, - WidgetConfig, - PanelDockConfig, - DialogDockConfig, - isDockConfig, - isPanelDockConfig, - isPanelConfig, - DividerConfig, - isDividerConfig, -} from './types'; -import { isPanel, Panel } from './widget/panel'; -import { WidgetContainer } from './widget/widget-container'; -import { Area } from './area'; -import { isWidget, IWidget, Widget } from './widget/widget'; -import { PanelDock } from './widget/panel-dock'; -import { Dock } from './widget/dock'; -import { Stage, StageConfig } from './widget/stage'; -import { isValidElement } from 'react'; -import { isPlainObject, uniqueId, Logger } from '@alilc/lowcode-utils'; -import { Divider } from '@alifd/next'; -import { - EditorConfig, - PluginClassSet, - IPublicTypeWidgetBaseConfig, - IPublicTypeWidgetConfigArea, - IPublicTypeSkeletonConfig, - IPublicApiSkeleton, - IPublicTypeConfigTransducer, - IPublicTypePanelConfig, -} from '@alilc/lowcode-types'; - -const logger = new Logger({ level: 'warn', bizName: 'skeleton' }); - -export enum SkeletonEvents { - PANEL_DOCK_ACTIVE = 'skeleton.panel-dock.active', - PANEL_DOCK_UNACTIVE = 'skeleton.panel-dock.unactive', - PANEL_SHOW = 'skeleton.panel.show', - PANEL_HIDE = 'skeleton.panel.hide', - WIDGET_SHOW = 'skeleton.widget.show', - WIDGET_HIDE = 'skeleton.widget.hide', - WIDGET_DISABLE = 'skeleton.widget.disable', - WIDGET_ENABLE = 'skeleton.widget.enable', -} - -export class Skeleton implements Omit<IPublicApiSkeleton, - 'showPanel' | - 'hidePanel' | - 'showWidget' | - 'enableWidget' | - 'hideWidget' | - 'disableWidget' | - 'showArea' | - 'onShowPanel' | - 'onHidePanel' | - 'onShowWidget' | - 'onHideWidget' | - 'remove' | - 'hideArea' | - 'add' | - 'getAreaItems' | - 'onDisableWidget' | - 'onEnableWidget' -> { - private panels = new Map<string, Panel>(); - - private configTransducers: IPublicTypeConfigTransducer[] = []; - - private containers = new Map<string, WidgetContainer<any>>(); - - readonly leftArea: Area<DockConfig | PanelDockConfig | DialogDockConfig>; - - readonly topArea: Area<DockConfig | DividerConfig | PanelDockConfig | DialogDockConfig>; - - readonly subTopArea: Area<DockConfig | DividerConfig | PanelDockConfig | DialogDockConfig>; - - readonly toolbar: Area<DockConfig | DividerConfig | PanelDockConfig | DialogDockConfig>; - - readonly leftFixedArea: Area<IPublicTypePanelConfig, Panel>; - - readonly leftFloatArea: Area<IPublicTypePanelConfig, Panel>; - - readonly rightArea: Area<IPublicTypePanelConfig, Panel>; - - @observable readonly mainArea: Area<WidgetConfig | IPublicTypePanelConfig, Widget | Panel>; - - readonly bottomArea: Area<IPublicTypePanelConfig, Panel>; - - readonly stages: Area<StageConfig, Stage>; - - readonly widgets: IWidget[] = []; - - readonly focusTracker = new FocusTracker(); - - constructor(readonly editor: IEditor, readonly viewName: string = 'global') { - makeObservable(this); - this.leftArea = new Area( - this, - 'leftArea', - (config) => { - if (isWidget(config)) { - return config; - } - return this.createWidget(config); - }, - false, - ); - this.topArea = new Area( - this, - 'topArea', - (config) => { - if (isWidget(config)) { - return config; - } - return this.createWidget(config); - }, - false, - ); - this.subTopArea = new Area( - this, - 'subTopArea', - (config) => { - if (isWidget(config)) { - return config; - } - return this.createWidget(config); - }, - false, - ); - this.toolbar = new Area( - this, - 'toolbar', - (config) => { - if (isWidget(config)) { - return config; - } - return this.createWidget(config); - }, - false, - ); - this.leftFixedArea = new Area( - this, - 'leftFixedArea', - (config) => { - if (isPanel(config)) { - return config; - } - return this.createPanel(config); - }, - true, - ); - this.leftFloatArea = new Area( - this, - 'leftFloatArea', - (config) => { - if (isPanel(config)) { - return config; - } - return this.createPanel(config); - }, - true, - ); - this.rightArea = new Area( - this, - 'rightArea', - (config) => { - if (isPanel(config)) { - return config; - } - return this.createPanel(config); - }, - false, - true, - ); - this.mainArea = new Area( - this, - 'mainArea', - (config) => { - if (isWidget(config)) { - return config as Widget; - } - return this.createWidget(config) as Widget; - }, - true, - true, - ); - this.bottomArea = new Area( - this, - 'bottomArea', - (config) => { - if (isPanel(config)) { - return config; - } - return this.createPanel(config); - }, - true, - ); - this.stages = new Area(this, 'stages', (config) => { - if (isWidget(config)) { - return config; - } - return new Stage(this, config); - }); - - this.setupPlugins(); - this.setupEvents(); - this.focusTracker.mount(window); - } - - /** - * setup events - * - * @memberof Skeleton - */ - setupEvents() { - // adjust pinned status when panel shown - this.editor.eventBus.on(SkeletonEvents.PANEL_SHOW, (panelName, panel) => { - const panelNameKey = `${panelName}-pinned-status-isFloat`; - const isInFloatAreaPreferenceExists = engineConfig.getPreference()?.contains(panelNameKey, 'skeleton'); - if (isInFloatAreaPreferenceExists) { - const isInFloatAreaFromPreference = engineConfig.getPreference()?.get(panelNameKey, 'skeleton'); - const isCurrentInFloatArea = panel?.isChildOfFloatArea(); - if (isInFloatAreaFromPreference !== isCurrentInFloatArea) { - this.toggleFloatStatus(panel); - } - } - }); - } - - /** - * set isFloat status for panel - * - * @param {*} panel - * @memberof Skeleton - */ - @action - toggleFloatStatus(panel: Panel) { - const isFloat = panel?.parent?.name === 'leftFloatArea'; - if (isFloat) { - this.leftFloatArea.remove(panel); - this.leftFixedArea.add(panel); - this.leftFixedArea.container.active(panel); - } else { - this.leftFixedArea.remove(panel); - this.leftFloatArea.add(panel); - this.leftFloatArea.container.active(panel); - } - engineConfig.getPreference().set(`${panel.name}-pinned-status-isFloat`, !isFloat, 'skeleton'); - } - - buildFromConfig(config?: EditorConfig, components: PluginClassSet = {}) { - if (config) { - this.editor.init(config, components); - } - this.setupPlugins(); - } - - private setupPlugins() { - const { config, components = {} } = this.editor; - if (!config) { - return; - } - - const { plugins } = config; - if (!plugins) { - return; - } - Object.keys(plugins).forEach((area) => { - plugins[area].forEach((item) => { - const { pluginKey, type, props = {}, pluginProps } = item; - const config: IPublicTypeWidgetBaseConfig = { - area: area as IPublicTypeWidgetConfigArea, - type: 'Widget', - name: pluginKey, - contentProps: pluginProps, - }; - const { dialogProps, balloonProps, panelProps, linkProps, ...restProps } = props; - config.props = restProps; - if (dialogProps) { - config.dialogProps = dialogProps; - } - if (balloonProps) { - config.balloonProps = balloonProps; - } - if (panelProps) { - config.panelProps = panelProps; - } - if (linkProps) { - config.linkProps = linkProps; - } - if (type === 'TabPanel') { - config.type = 'Panel'; - } else if (/Icon$/.test(type)) { - config.type = type.replace('Icon', 'Dock'); - } - if (pluginKey in components) { - config.content = components[pluginKey]; - } - this.add(config); - }); - }); - } - - postEvent(event: SkeletonEvents, ...args: any[]) { - this.editor.eventBus.emit(event, ...args); - } - - createWidget(config: IPublicTypeWidgetBaseConfig | IWidget) { - if (isWidget(config)) { - return config; - } - - config = this.parseConfig(config); - let widget: IWidget; - if (isDockConfig(config)) { - if (isPanelDockConfig(config)) { - widget = new PanelDock(this, config); - } else if (false) { - // DialogDock - // others... - } else { - widget = new Dock(this, config); - } - } else if (isDividerConfig(config)) { - widget = new Widget(this, { - ...config, - type: 'Widget', - content: Divider, - }); - } else if (isPanelConfig(config)) { - widget = this.createPanel(config); - } else { - widget = new Widget(this, config as WidgetConfig); - } - this.widgets.push(widget); - return widget; - } - - getWidget(name: string): IWidget | undefined { - return this.widgets.find(widget => widget.name === name); - } - - createPanel(config: IPublicTypePanelConfig) { - const parsedConfig = this.parseConfig(config); - const panel = new Panel(this, parsedConfig as IPublicTypePanelConfig); - this.panels.set(panel.name, panel); - logger.debug(`Panel created with name: ${panel.name} \nconfig:`, config, '\n current panels: ', this.panels); - return panel; - } - - getPanel(name: string): Panel | undefined { - return this.panels.get(name); - } - - getStage(name: string) { - return this.stages.container.get(name); - } - - createStage(config: any) { - const stage = this.add({ - name: uniqueId('stage'), - area: 'stages', - ...config, - }); - return stage?.getName?.(); - } - - createContainer( - name: string, - handle: (item: any) => any, - exclusive = false, - checkVisible: () => boolean = () => true, - defaultSetCurrent = false, - ) { - const container = new WidgetContainer(name, handle, exclusive, checkVisible, defaultSetCurrent); - this.containers.set(name, container); - return container; - } - - private parseConfig(config: IPublicTypeWidgetBaseConfig) { - if (config.parsed) { - return config; - } - const { content, ...restConfig } = config; - if (content) { - if (isPlainObject<IPublicTypePanelConfig>(content) && !isValidElement(content)) { - Object.keys(content).forEach((key) => { - if (/props$/i.test(key) && restConfig[key]) { - restConfig[key] = { - ...restConfig[key], - ...content[key], - }; - } else { - restConfig[key] = content[key]; - } - }); - } else { - restConfig.content = content; - } - } - restConfig.pluginKey = restConfig.name; - restConfig.parsed = true; - return restConfig; - } - - registerConfigTransducer( - transducer: IPublicTypeConfigTransducer, - level = 100, - id?: string, - ) { - transducer.level = level; - transducer.id = id; - const i = this.configTransducers.findIndex((item) => item.level != null && item.level > level); - if (i < 0) { - this.configTransducers.push(transducer); - } else { - this.configTransducers.splice(i, 0, transducer); - } - } - - getRegisteredConfigTransducers(): IPublicTypeConfigTransducer[] { - return this.configTransducers; - } - - add( - config: IPublicTypeSkeletonConfig, - extraConfig?: Record<string, any> - ): IWidget | Widget | Panel | Stage | Dock | PanelDock | undefined { - const registeredTransducers = this.getRegisteredConfigTransducers(); - - const parsedConfig = registeredTransducers.reduce((prevConfig, current) => { - return current(prevConfig); - }, { - ...this.parseConfig(config), - ...extraConfig, - }); - - let { area } = parsedConfig; - if (!area) { - if (parsedConfig.type === 'Panel') { - area = 'leftFloatArea'; - } else if (parsedConfig.type === 'Widget') { - area = 'mainArea'; - } else { - area = 'leftArea'; - } - } - switch (area) { - case 'leftArea': - case 'left': - return this.leftArea.add(parsedConfig as PanelDockConfig); - case 'rightArea': - case 'right': - return this.rightArea.add(parsedConfig as IPublicTypePanelConfig); - case 'topArea': - case 'top': - return this.topArea.add(parsedConfig as PanelDockConfig); - case 'subTopArea': - return this.subTopArea.add(parsedConfig as PanelDockConfig); - case 'toolbar': - return this.toolbar.add(parsedConfig as PanelDockConfig); - case 'mainArea': - case 'main': - case 'center': - case 'centerArea': - return this.mainArea.add(parsedConfig as IPublicTypePanelConfig); - case 'bottomArea': - case 'bottom': - return this.bottomArea.add(parsedConfig as IPublicTypePanelConfig); - case 'leftFixedArea': - return this.leftFixedArea.add(parsedConfig as IPublicTypePanelConfig); - case 'leftFloatArea': - return this.leftFloatArea.add(parsedConfig as IPublicTypePanelConfig); - case 'stages': - return this.stages.add(parsedConfig as StageConfig); - default: - // do nothing - } - } -} diff --git a/packages/workbench/src/transducers/addon-combine.ts b/packages/workbench/src/transducers/addon-combine.ts deleted file mode 100644 index 4441833e5..000000000 --- a/packages/workbench/src/transducers/addon-combine.ts +++ /dev/null @@ -1,321 +0,0 @@ -import { - IPublicTypeTransformedComponentMetadata, - IPublicTypeFieldConfig, - IPublicModelSettingField, -} from '@alilc/lowcode-types'; -import { IconSlot } from '../icons/slot'; -import { getConvertedExtraKey } from '@alilc/lowcode-designer'; - -export default function ( - metadata: IPublicTypeTransformedComponentMetadata, -): IPublicTypeTransformedComponentMetadata { - const { componentName, configure = {} } = metadata; - - // 如果已经处理过,不再重新执行一遍 - if (configure.combined) { - return metadata; - } - if (componentName === 'Leaf') { - return { - ...metadata, - configure: { - ...configure, - combined: [ - { - name: 'children', - title: { type: 'i18n', 'zh-CN': '内容设置', 'en-US': 'Content' }, - setter: { - componentName: 'MixedSetter', - props: { - // TODO: - setters: [ - { - componentName: 'StringSetter', - props: { - // TODO: textarea mode - multiline: true, - }, - initialValue: '', - }, - { - componentName: 'ExpressionSetter', - initialValue: { - type: 'JSExpression', - value: '', - }, - }, - ], - }, - }, - }, - ], - }, - }; - } - - const { props, supports = {} } = configure as any; - const isRoot: boolean = componentName === 'Page' || componentName === 'Component'; - const eventsDefinition: any[] = []; - const supportedLifecycles = supports.lifecycles; - if (supportedLifecycles) { - eventsDefinition.push({ - type: 'lifeCycleEvent', - title: '生命周期', - list: supportedLifecycles.map((event: any) => (typeof event === 'string' ? { name: event } : event)), - }); - } - if (supports.events) { - eventsDefinition.push({ - type: 'events', - title: '事件', - list: (supports.events || []).map((event: any) => (typeof event === 'string' ? { name: event } : event)), - }); - } - // 通用设置 - let propsGroup = props ? [...props] : []; - const basicInfo: any = {}; - if (componentName === 'Slot') { - if (!configure.component) { - configure.component = { - isContainer: true, - }; - } else if (typeof configure.component === 'object') { - configure.component.isContainer = true; - } - basicInfo.icon = IconSlot; - propsGroup = [ - { - name: getConvertedExtraKey('title'), - title: { - type: 'i18n', - 'en-US': 'Slot Title', - 'zh-CN': '插槽标题', - }, - setter: 'StringSetter', - defaultValue: '插槽容器', - }, - ]; - } - - const stylesGroup: IPublicTypeFieldConfig[] = []; - const advancedGroup: IPublicTypeFieldConfig[] = []; - if (propsGroup) { - let l = propsGroup.length; - while (l-- > 0) { - const item = propsGroup[l]; - if ( - item.name === '__style__' || - item.name === 'style' || - item.name === 'containerStyle' || - item.name === 'pageStyle' - ) { - propsGroup.splice(l, 1); - stylesGroup.push(item); - if (item.extraProps?.defaultCollapsed && item.name !== 'containerStyle') { - item.extraProps.defaultCollapsed = false; - } - } - } - } - const combined: IPublicTypeFieldConfig[] = [ - { - title: { type: 'i18n', 'zh-CN': '属性', 'en-US': 'Props' }, - name: '#props', - items: propsGroup, - }, - ]; - if (supports.className) { - stylesGroup.push({ - name: 'className', - title: { type: 'i18n', 'zh-CN': '类名绑定', 'en-US': 'ClassName' }, - setter: 'ClassNameSetter', - }); - } - if (supports.style) { - stylesGroup.push({ - name: 'style', - title: { type: 'i18n', 'zh-CN': '行内样式', 'en-US': 'Style' }, - setter: 'StyleSetter', - extraProps: { - display: 'block', - }, - }); - } - if (stylesGroup.length > 0) { - combined.push({ - name: '#styles', - title: { type: 'i18n', 'zh-CN': '样式', 'en-US': 'Styles' }, - items: stylesGroup, - }); - } - - if (eventsDefinition.length > 0) { - combined.push({ - name: '#events', - title: { type: 'i18n', 'zh-CN': '事件', 'en-US': 'Events' }, - items: [ - { - name: '__events', - title: { type: 'i18n', 'zh-CN': '事件设置', 'en-US': 'Events' }, - setter: { - componentName: 'EventsSetter', - props: { - definition: eventsDefinition, - }, - }, - getValue(field: IPublicModelSettingField, val?: any[]) { - return val; - }, - - setValue(field: IPublicModelSettingField, eventData) { - const { eventDataList, eventList } = eventData; - Array.isArray(eventList) && - eventList.map((item) => { - field.parent.clearPropValue(item.name); - return item; - }); - Array.isArray(eventDataList) && - eventDataList.map((item) => { - field.parent.setPropValue(item.name, { - type: 'JSFunction', - // 需要传下入参 - value: `function(){return this.${ - item.relatedEventName - }.apply(this,Array.prototype.slice.call(arguments).concat([${ - item.paramStr ? item.paramStr : '' - }])) }`, - }); - return item; - }); - }, - }, - ], - }); - } - - if (!isRoot) { - if (supports.condition !== false) { - advancedGroup.push({ - name: getConvertedExtraKey('condition'), - title: { type: 'i18n', 'zh-CN': '是否渲染', 'en-US': 'Condition' }, - defaultValue: true, - setter: [ - { - componentName: 'BoolSetter', - }, - { - componentName: 'VariableSetter', - }, - ], - extraProps: { - display: 'block', - }, - }); - } - if (supports.loop !== false) { - advancedGroup.push({ - name: '#loop', - title: { type: 'i18n', 'zh-CN': '循环', 'en-US': 'Loop' }, - items: [ - { - name: getConvertedExtraKey('loop'), - title: { type: 'i18n', 'zh-CN': '循环数据', 'en-US': 'Loop Data' }, - setter: [ - { - componentName: 'JsonSetter', - props: { - label: { type: 'i18n', 'zh-CN': '编辑数据', 'en-US': 'Edit Data' }, - defaultValue: '[]', - }, - }, - { - componentName: 'VariableSetter', - }, - ], - }, - { - name: getConvertedExtraKey('loopArgs.0'), - title: { type: 'i18n', 'zh-CN': '迭代变量名', 'en-US': 'Loop Item' }, - setter: { - componentName: 'StringSetter', - props: { - placeholder: { type: 'i18n', 'zh-CN': '默认为: item', 'en-US': 'Defaults: item' }, - }, - }, - }, - { - name: getConvertedExtraKey('loopArgs.1'), - title: { type: 'i18n', 'zh-CN': '索引变量名', 'en-US': 'Loop Index' }, - setter: { - componentName: 'StringSetter', - props: { - placeholder: { type: 'i18n', 'zh-CN': '默认为: index', 'en-US': 'Defaults: index' }, - }, - }, - }, - { - name: 'key', - title: { type: 'i18n', 'zh-CN': '循环 Key', 'en-US': 'Loop Key' }, - setter: [ - { - componentName: 'StringSetter', - }, - { - componentName: 'VariableSetter', - }, - ], - }, - ], - extraProps: { - display: 'accordion', - }, - }); - } - - if (supports.condition !== false || supports.loop !== false) { - advancedGroup.push({ - name: 'key', - title: { - label: { - type: 'i18n', - 'zh-CN': '渲染唯一标识 (key)', - 'en-US': 'Render unique identifier (key)', - }, - tip: { - type: 'i18n', - 'zh-CN': '搭配「条件渲染」或「循环渲染」时使用,和 react 组件中的 key 原理相同,点击查看帮助', - 'en-US': 'Used with 「Conditional Rendering」or「Cycle Rendering」, the same principle as the key in the react component, click to view the help', - }, - docUrl: 'https://www.yuque.com/lce/doc/qm75w3', - }, - setter: [ - { - componentName: 'StringSetter', - }, - { - componentName: 'VariableSetter', - }, - ], - extraProps: { - display: 'block', - }, - }); - } - } - if (advancedGroup.length > 0) { - combined.push({ - name: '#advanced', - title: { type: 'i18n', 'zh-CN': '高级', 'en-US': 'Advanced' }, - items: advancedGroup, - }); - } - - return { - ...metadata, - ...basicInfo, - configure: { - ...configure, - combined, - }, - }; -} diff --git a/packages/workbench/src/transducers/parse-func.ts b/packages/workbench/src/transducers/parse-func.ts deleted file mode 100644 index 40dc319b3..000000000 --- a/packages/workbench/src/transducers/parse-func.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { IPublicTypeTransformedComponentMetadata } from '@alilc/lowcode-types'; -import { isPlainObject, isJSFunction, createLogger } from '@alilc/lowcode-utils'; - -const leadingFnRe = /^function/; -const leadingFnNameRe = /^\w+\s*\(/; -const logger = createLogger({ level: 'warn', bizName: 'skeleton:transducers' }); - -/** - * 将函数字符串转成函数,支持几种类型 - * 类型一:() => {} / val => {} - * 类型二:setValue() {} - * 类型三:function() {} / function setValue() {} - * @param str - * @returns - */ -function transformStringToFunction(str: string) { - if (typeof str !== 'string') return str; - - let fn; - if (leadingFnNameRe.test(str) && !leadingFnRe.test(str)) { - str = `function ${str}`; - } - const fnBody = ` - return function() { - const self = this; - try { - return (${str}).apply(self, arguments); - } catch(e) { - console.warn('call function which parsed by lowcode failed: ', e); - return e.message; - } - }; - `; - try { - // eslint-disable-next-line no-new-func - fn = new Function(fnBody)(); - } catch (e) { - logger.error(str); - logger.error((e as Error).message); - } - return fn; -} - -function parseJSFunc(obj: any, enableAllowedKeys = true) { - if (!obj) return; - Object.keys(obj).forEach((key) => { - const item = obj[key]; - if (isJSFunction(item)) { - obj[key] = transformStringToFunction(item.value); - } else if (Array.isArray(item)) { - item.forEach((o) => parseJSFunc(o, enableAllowedKeys)); - } else if (isPlainObject(item)) { - parseJSFunc(item, enableAllowedKeys); - } - }); -} - -export default function ( - metadata: IPublicTypeTransformedComponentMetadata, -): IPublicTypeTransformedComponentMetadata { - parseJSFunc(metadata, false); - - return metadata; -} diff --git a/packages/workbench/src/transducers/parse-props.ts b/packages/workbench/src/transducers/parse-props.ts deleted file mode 100644 index 5b0bb5bb2..000000000 --- a/packages/workbench/src/transducers/parse-props.ts +++ /dev/null @@ -1,281 +0,0 @@ -import { - IPublicTypeFieldConfig, - IPublicTypePropConfig, - IPublicTypePropType, - IPublicTypeSetterType, - IPublicTypeOneOf, - IPublicTypeObjectOf, - IPublicTypeArrayOf, - IPublicTypeTransformedComponentMetadata, - IPublicTypeOneOfType, - ConfigureSupportEvent, - IPublicModelSettingField, -} from '@alilc/lowcode-types'; - -function propConfigToFieldConfig(propConfig: IPublicTypePropConfig): IPublicTypeFieldConfig { - const { name, description } = propConfig; - const title = { - label: { - type: 'i18n', - 'en-US': name, - 'zh-CN': description?.slice(0, 10) || name, - }, - tip: description ? `${name} | ${description}` : undefined, - } as any; - return { - title, - ...propConfig, - // TODO 这边直接用propConfig,将setter丢在propconfig里,需要确认是否在PropConfig扩展还是换实现 - setter: propConfig.setter ? propConfig.setter : propTypeToSetter(propConfig.propType), - }; -} - -function propTypeToSetter(propType: IPublicTypePropType): IPublicTypeSetterType { - let typeName: string; - let isRequired: boolean | undefined = false; - if (typeof propType === 'string') { - typeName = propType; - } else if (typeof propType === 'object') { - typeName = propType.type; - isRequired = propType.isRequired; - } else { - typeName = 'string'; - } - // TODO: use mixinSetter wrapper - switch (typeName) { - case 'string': - return { - componentName: 'StringSetter', - isRequired, - initialValue: '', - }; - case 'number': - return { - componentName: 'NumberSetter', - isRequired, - initialValue: 0, - }; - case 'bool': - return { - componentName: 'BoolSetter', - isRequired, - initialValue: false, - }; - case 'oneOf': - const dataSource = ((propType as IPublicTypeOneOf).value || []).map((value, index) => { - const t = typeof value; - return { - label: - t === 'string' || t === 'number' || t === 'boolean' ? String(value) : `value ${index}`, - value, - }; - }); - - return { - componentName: dataSource.length >= 4 ? 'SelectSetter' : 'RadioGroupSetter', - props: { dataSource, options: dataSource }, - isRequired, - initialValue: dataSource[0] ? dataSource[0].value : null, - }; - - case 'element': - case 'node': // TODO: use Mixin - return { - // slotSetter - componentName: 'SlotSetter', - props: { - mode: typeName, - }, - isRequired, - initialValue: { - type: 'JSSlot', - value: [], - }, - }; - case 'shape': - case 'exact': - const items = ((propType as any).value || []).map((item: any) => - propConfigToFieldConfig(item), - ); - return { - componentName: 'ObjectSetter', - props: { - config: { - items, - extraSetter: typeName === 'shape' ? propTypeToSetter('any') : null, - }, - }, - isRequired, - initialValue: (field: IPublicModelSettingField) => { - const data: any = {}; - items.forEach((item: any) => { - let initial = item.defaultValue; - if (initial == null && item.setter && typeof item.setter === 'object') { - initial = (item.setter as any).initialValue; - } - data[item.name] = initial - ? typeof initial === 'function' - ? initial(field) - : initial - : null; - }); - return data; - }, - }; - case 'object': - case 'objectOf': - return { - componentName: 'ObjectSetter', - props: { - config: { - extraSetter: propTypeToSetter( - typeName === 'objectOf' ? (propType as IPublicTypeObjectOf).value : 'any', - ), - }, - }, - isRequired, - initialValue: {}, - }; - case 'array': - case 'arrayOf': - return { - componentName: 'ArraySetter', - props: { - itemSetter: propTypeToSetter( - typeName === 'arrayOf' ? (propType as IPublicTypeArrayOf).value : 'any', - ), - }, - isRequired, - initialValue: [], - }; - case 'func': - return { - componentName: 'FunctionSetter', - isRequired, - }; - case 'color': - return { - componentName: 'ColorSetter', - isRequired, - }; - case 'oneOfType': - return { - componentName: 'MixedSetter', - props: { - // TODO: - setters: (propType as IPublicTypeOneOfType).value.map((item) => propTypeToSetter(item)), - }, - isRequired, - }; - default: - // do nothing - } - return { - componentName: 'MixedSetter', - isRequired, - props: {}, - }; -} - -const EVENT_RE = /^on|after|before[A-Z][\w]*$/; - -export default function ( - metadata: IPublicTypeTransformedComponentMetadata, -): IPublicTypeTransformedComponentMetadata { - const { configure = {} } = metadata; - // TODO types后续补充 - let extendsProps: any = null; - if (configure.props) { - if (Array.isArray(configure.props)) { - return metadata; - } - const { isExtends, override = [] } = configure.props; - // 不开启继承时,直接返回configure配置 - if (!isExtends) { - return { - ...metadata, - configure: { - ...configure, - props: [...override], - }, - }; - } - - extendsProps = {}; - // 开启继承后,缓存重写内容的配置 - override.forEach((prop: any) => { - extendsProps[prop.name] = prop; - }); - } - - if (!metadata.props) { - return { - ...metadata, - configure: { - ...configure, - props: [], - }, - }; - } - const { component = {}, supports = {} } = configure; - const supportedEvents: ConfigureSupportEvent[] | null = supports.events ? null : []; - const props: IPublicTypeFieldConfig[] = []; - - metadata.props.forEach((prop) => { - const { name, propType, description } = prop; - if ( - name === 'children' && - (component.isContainer || propType === 'node' || propType === 'element' || propType === 'any') - ) { - if (component.isContainer !== false) { - component.isContainer = true; - props.push(propConfigToFieldConfig(prop)); - return; - } - } - - if (EVENT_RE.test(name) && (propType === 'func' || propType === 'any')) { - if (supportedEvents) { - supportedEvents.push({ - name, - description, - }); - supports.events = supportedEvents; - } - return; - } - - if (name === 'className' && (propType === 'string' || propType === 'any')) { - if (supports.className == null) { - supports.className = true; - } - return; - } - - if (name === 'style' && (propType === 'object' || propType === 'any')) { - if (supports.style == null) { - supports.style = true; - } - return; - } - - // 存在覆盖配置时 - if (extendsProps) { - if (name in extendsProps) { - prop = extendsProps[name]; - } - } - - props.push(propConfigToFieldConfig(prop)); - }); - - return { - ...metadata, - configure: { - ...configure, - props, - supports, - component, - }, - }; -} diff --git a/packages/workbench/src/types.ts b/packages/workbench/src/types.ts deleted file mode 100644 index 8c5f1484a..000000000 --- a/packages/workbench/src/types.ts +++ /dev/null @@ -1,84 +0,0 @@ -import { ReactElement, ComponentType } from 'react'; -import { - IPublicTypeTitleContent, - IPublicTypeWidgetConfigArea, - IPublicTypeWidgetBaseConfig, - IPublicTypePanelDockProps, - IPublicTypePanelConfigProps, - IPublicTypePanelConfig, -} from '@alilc/lowcode-types'; -import { IWidget } from './widget/widget'; - -export interface WidgetConfig extends IPublicTypeWidgetBaseConfig { - type: 'Widget'; - props?: { - align?: 'left' | 'right' | 'bottom' | 'center' | 'top'; - onInit?: (widget: IWidget) => void; - title?: IPublicTypeTitleContent | null; - }; - content?: string | ReactElement | ComponentType<any>; // children -} - -export function isWidgetConfig(obj: any): obj is WidgetConfig { - return obj && obj.type === 'Widget'; -} - -export interface DockProps extends IPublicTypePanelDockProps { -} - -export interface DividerConfig extends IPublicTypeWidgetBaseConfig { - type: 'Divider'; - props?: { - align?: 'left' | 'right' | 'center'; - }; -} - -export function isDividerConfig(obj: any): obj is DividerConfig { - return obj && obj.type === 'Divider'; -} - -export interface IDockBaseConfig extends IPublicTypeWidgetBaseConfig { - props?: DockProps & { - align?: 'left' | 'right' | 'bottom' | 'center' | 'top'; - onInit?: (widget: IWidget) => void; - }; -} - -export interface DockConfig extends IDockBaseConfig { - type: 'Dock'; - content?: string | ReactElement | ComponentType<any>; -} - -export function isDockConfig(obj: any): obj is DockConfig { - return obj && /Dock$/.test(obj.type); -} - -// 按钮弹窗扩展 -export interface DialogDockConfig extends IDockBaseConfig { - type: 'DialogDock'; - dialogProps?: { - [key: string]: any; - title?: IPublicTypeTitleContent; - }; -} - -export function isDialogDockConfig(obj: any): obj is DialogDockConfig { - return obj && obj.type === 'DialogDock'; -} - -export function isPanelConfig(obj: any): obj is IPublicTypePanelConfig { - return obj && obj.type === 'Panel'; -} - -export interface PanelDockConfig extends IDockBaseConfig { - type: 'PanelDock'; - panelName?: string; - panelProps?: IPublicTypePanelConfigProps & { - area?: IPublicTypeWidgetConfigArea; - }; - content?: string | ReactElement | ComponentType<any> | IPublicTypePanelConfig[]; // content for pane -} - -export function isPanelDockConfig(obj: any): obj is PanelDockConfig { - return obj && obj.type === 'PanelDock'; -} diff --git a/packages/workbench/src/widget/dock.ts b/packages/workbench/src/widget/dock.ts deleted file mode 100644 index 4277308ab..000000000 --- a/packages/workbench/src/widget/dock.ts +++ /dev/null @@ -1,122 +0,0 @@ -import { ReactNode, createElement } from 'react'; -import { makeObservable, observable } from '@alilc/lowcode-editor-core'; -import { uniqueId, createContent } from '@alilc/lowcode-utils'; -import { getEvent } from '../../../engine/src/shell/api/event'; -import { DockConfig } from '../types'; -import { Skeleton } from '../skeleton'; -import { DockView, WidgetView } from '../components/widget-views'; -import { IWidget } from './widget'; - -/** - * 带图标(主要)/标题(次要)的扩展 - */ -export class Dock implements IWidget { - readonly isWidget = true; - - readonly id = uniqueId('dock'); - - readonly name: string; - - readonly align?: string; - - @observable.ref private _visible = true; - - get visible(): boolean { - return this._visible; - } - - @observable.ref private _disabled = false; - - get content(): ReactNode { - return createElement(WidgetView, { - widget: this, - key: this.id, - }); - } - - private inited = false; - - private _body: ReactNode; - - get body() { - if (this.inited) { - return this._body; - } - - const { props, content, contentProps } = this.config; - - if (content) { - this._body = createContent(content, { - ...contentProps, - config: this.config, - editor: getEvent(this.skeleton.editor), - }); - } else { - this._body = createElement(DockView, props); - } - this.inited = true; - - return this._body; - } - - constructor( - readonly skeleton: Skeleton, - readonly config: DockConfig, - ) { - makeObservable(this); - const { props = {}, name } = config; - this.name = name; - this.align = props.align; - if (props.onInit) { - props.onInit.call(this, this); - } - } - - setVisible(flag: boolean) { - if (flag === this._visible) { - return; - } - if (flag) { - this._visible = true; - } else if (this.inited) { - this._visible = false; - } - } - - private setDisabled(flag: boolean) { - if (this._disabled === flag) return; - this._disabled = flag; - } - - disable() { - this.setDisabled(true); - } - - enable() { - this.setDisabled(false); - } - - get disabled(): boolean { - return this._disabled; - } - - getContent() { - return this.content; - } - - getName() { - return this.name; - } - - hide() { - this.setVisible(false); - } - - show() { - this.setVisible(true); - } - - toggle() { - this.setVisible(!this._visible); - } -} diff --git a/packages/workbench/src/widget/index.ts b/packages/workbench/src/widget/index.ts deleted file mode 100644 index 17d77d8c4..000000000 --- a/packages/workbench/src/widget/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -export * from './widget-container'; -export * from './panel'; -export * from './panel-dock'; -export * from './dock'; -export * from './widget'; -export * from './stage'; diff --git a/packages/workbench/src/widget/panel-dock.ts b/packages/workbench/src/widget/panel-dock.ts deleted file mode 100644 index f9263d4e0..000000000 --- a/packages/workbench/src/widget/panel-dock.ts +++ /dev/null @@ -1,168 +0,0 @@ -import { observable, computed, makeObservable } from '@alilc/lowcode-editor-core'; -import { uniqueId } from '@alilc/lowcode-utils'; -import { createElement, ReactNode, ReactInstance } from 'react'; -import { ISkeleton } from '../skeleton'; -import { PanelDockConfig } from '../types'; -import { Panel } from './panel'; -import { PanelDockView, WidgetView } from '../components/widget-views'; -import { IWidget } from './widget'; -import { composeTitle } from './utils'; -import { findDOMNode } from 'react-dom'; - -export class PanelDock implements IWidget { - readonly isWidget = true; - - readonly isPanelDock = true; - - readonly id: string; - - readonly name: string; - - readonly align?: 'left' | 'right' | 'bottom' | 'center' | 'top' | undefined; - - private inited = false; - - private _body: ReactNode; - - get body() { - if (this.inited) { - return this._body; - } - this.inited = true; - const { props } = this.config; - - this._body = createElement(PanelDockView, { - ...props, - dock: this, - }); - - return this._body; - } - - private _shell: ReactInstance | null = null; - - get content(): ReactNode { - return createElement(WidgetView, { - widget: this, - ref: (ref) => { - this._shell = ref; - }, - key: this.id, - }); - } - - @observable.ref private _visible = true; - - get visible() { - return this._visible; - } - - @computed get actived(): boolean { - return this.panel?.visible || false; - } - - readonly panelName: string; - - private _panel?: Panel; - - @observable.ref private _disabled = false; - - @computed get panel() { - return this._panel || this.skeleton.getPanel(this.panelName); - } - - constructor(readonly skeleton: ISkeleton, readonly config: PanelDockConfig) { - makeObservable(this); - const { content, contentProps, panelProps, name, props } = config; - this.name = name; - this.id = uniqueId(`dock:${name}$`); - this.panelName = config.panelName || name; - this.align = props?.align; - if (content) { - const _panelProps = { ...panelProps }; - if (_panelProps.title == null && props) { - _panelProps.title = composeTitle(props.title, undefined, props.description, true, true); - } - this._panel = this.skeleton.add({ - type: 'Panel', - name: this.panelName, - props: _panelProps, - contentProps, - content, - area: panelProps?.area, - }) as Panel; - } - if (props?.onInit) { - props.onInit.call(this, this); - } - } - - getDOMNode() { - // eslint-disable-next-line react/no-find-dom-node - return this._shell ? findDOMNode(this._shell) : null; - } - - setVisible(flag: boolean) { - if (flag === this._visible) { - return; - } - if (flag) { - this._visible = true; - } else if (this.inited) { - this._visible = false; - } - } - - hide() { - this.setVisible(false); - } - - show() { - this.setVisible(true); - } - - toggle() { - this.setVisible(!this._visible); - } - - private setDisabled(flag: boolean) { - if (this._disabled === flag) return; - this._disabled = flag; - } - - disable() { - this.setDisabled(true); - } - - enable() { - this.setDisabled(false); - } - - get disabled(): boolean { - return this._disabled; - } - - togglePanel() { - this.panel?.toggle(); - } - - getName() { - return this.name; - } - - getContent() { - return this.content; - } - - hidePanel() { - this.panel?.setActive(false); - } - - showPanel() { - this.panel?.setActive(true); - } -} - -export function isPanelDock(obj: any): obj is PanelDock { - return obj && obj.isPanelDock; -} diff --git a/packages/workbench/src/widget/panel.ts b/packages/workbench/src/widget/panel.ts deleted file mode 100644 index 9ce0756cb..000000000 --- a/packages/workbench/src/widget/panel.ts +++ /dev/null @@ -1,241 +0,0 @@ -import { createElement, ReactNode } from 'react'; -import { - observable, - computed, - makeObservable, - IEventBus, - createModuleEventBus, -} from '@alilc/lowcode-editor-core'; -import { uniqueId, createContent } from '@alilc/lowcode-utils'; -import { - IPublicTypeHelpTipConfig, - IPublicTypePanelConfig, - IPublicTypeTitleContent, -} from '@alilc/lowcode-types'; -import { WidgetContainer } from './widget-container'; -import { getEvent } from '../../../engine/src/shell/api/event'; -import { TitledPanelView, TabsPanelView, PanelView } from '../components/widget-views'; -import { ISkeleton } from '../skeleton'; -import { composeTitle } from './utils'; -import { IWidget } from './widget'; -import { isPanelDock, PanelDock } from './panel-dock'; - -export class Panel implements IWidget { - readonly isWidget = true; - - readonly name: string; - - readonly id: string; - - @observable.ref inited = false; - - @observable.ref private _actived = false; - - private emitter: IEventBus = createModuleEventBus('Panel'); - - @computed get actived(): boolean { - return this._actived; - } - - @computed get visible(): boolean { - if (!this.parent || this.parent.visible) { - const { props } = this.config; - if (props?.condition) { - return props.condition(this); - } - return this._actived; - } - return false; - } - - readonly isPanel = true; - - get body() { - if (this.container) { - return createElement(TabsPanelView, { - container: this.container, - shouldHideSingleTab: true, - }); - } - - const { content, contentProps } = this.config; - return createContent(content as any, { - ...contentProps, - editor: getEvent(this.skeleton.editor), - config: this.config, - panel: this, - pane: this, - }); - } - - get content(): ReactNode { - const area = this.config?.area || this.parent?.name; - if (this.plain) { - return createElement(PanelView, { - panel: this, - key: this.id, - area, - }); - } - return createElement(TitledPanelView, { panel: this, key: this.id, area }); - } - - readonly title: IPublicTypeTitleContent; - - readonly help?: IPublicTypeHelpTipConfig; - - private plain = false; - - private container?: WidgetContainer<Panel, IPublicTypePanelConfig>; - - @observable.ref public parent?: WidgetContainer; - - constructor( - readonly skeleton: ISkeleton, - readonly config: IPublicTypePanelConfig, - ) { - makeObservable(this); - const { name, content, props = {} } = config; - const { hideTitleBar, title, icon, description, help } = props; - this.name = name; - this.id = uniqueId(`pane:${name}$`); - this.title = composeTitle(title || name, icon, description); - this.plain = hideTitleBar || !title; - this.help = help; - if (Array.isArray(content)) { - this.container = this.skeleton.createContainer( - name, - (item) => { - if (isPanel(item)) { - return item; - } - return this.skeleton.createPanel(item); - }, - true, - () => this.visible, - true, - ); - content.forEach((item) => this.add(item)); - } - if (props.onInit) { - props.onInit.call(this, this); - } - - if (typeof content !== 'string' && content && (content as any).onInit) { - (content as any).onInit.call(this, this); - } - // todo: process shortcut - } - - setParent(parent: WidgetContainer) { - if (parent === this.parent) { - return; - } - if (this.parent) { - this.parent.remove(this); - } - this.parent = parent; - } - - add(item: Panel | IPublicTypePanelConfig) { - return this.container?.add(item); - } - - getPane(name: string): Panel | null { - return this.container?.get(name) || null; - } - - remove(item: Panel | string) { - return this.container?.remove(item); - } - - active(item?: Panel | string | null) { - if (item) { - this.container?.active(item); - } else { - this.setActive(true); - } - } - - getName() { - return this.name; - } - - getContent() { - return this.content; - } - - /** - * check is current panel is in float area or not - * - * @returns {boolean} - * @memberof Panel - */ - isChildOfFloatArea(): boolean { - return this.parent?.name === 'leftFloatArea'; - } - - /** - * check is current panel is in fixed area or not - * - * @returns {boolean} - * @memberof Panel - */ - isChildOfFixedArea(): boolean { - return this.parent?.name === 'leftFixedArea'; - } - - setActive(flag: boolean) { - if (flag === this._actived) { - // TODO: 如果移动到另外一个 container,会有问题 - return; - } - if (flag) { - // 对于 Area 的直接 Child,要专门处理 Float & Fixed 分组切换, 其他情况不需要 - if (this.isChildOfFloatArea()) { - this.skeleton.leftFixedArea.container.unactiveAll(); - } else if (this.isChildOfFixedArea()) { - this.skeleton.leftFloatArea.container.unactiveAll(); - } - this._actived = true; - this.parent?.active(this); - if (!this.inited) { - this.inited = true; - } - this.emitter.emit('activechange', true); - } else if (this.inited) { - if (this.parent?.name && this.name.startsWith(this.parent.name)) { - this.inited = false; - } - this._actived = false; - this.parent?.unactive(this); - this.emitter.emit('activechange', false); - } - } - - toggle() { - this.setActive(!this._actived); - } - - hide() { - this.setActive(false); - } - - disable() {} - - enable(): void {} - - show() { - this.setActive(true); - } - - getAssocDocks(): PanelDock[] { - return this.skeleton.widgets.filter((item) => { - return isPanelDock(item) && item.panelName === this.name; - }) as any; - } -} - -export function isPanel(obj: any): obj is Panel { - return obj && obj.isPanel; -} diff --git a/packages/workbench/src/widget/stage.ts b/packages/workbench/src/widget/stage.ts deleted file mode 100644 index 4c8a3f330..000000000 --- a/packages/workbench/src/widget/stage.ts +++ /dev/null @@ -1,53 +0,0 @@ -import { Widget } from './widget'; -import { ISkeleton } from '../skeleton'; -import { WidgetConfig } from '../types'; - -export interface StageConfig extends WidgetConfig { - isRoot?: boolean; -} - -export class Stage extends Widget { - readonly isRoot: boolean; - - private previous?: Stage; - - private refer?: { - stage?: Stage; - direction?: 'right' | 'left'; - }; - - constructor(skeleton: ISkeleton, config: StageConfig) { - super(skeleton, config); - this.isRoot = config.isRoot || false; - } - - setPrevious(stage: Stage) { - this.previous = stage; - } - - getPrevious() { - return this.previous; - } - - hasBack(): boolean { - return !!(this.previous && !this.isRoot); - } - - setRefer(stage: Stage, direction: 'right' | 'left') { - this.refer = { stage, direction }; - } - - setReferRight(stage: Stage) { - this.setRefer(stage, 'right'); - } - - setReferLeft(stage: Stage) { - this.setRefer(stage, 'left'); - } - - getRefer() { - const { refer } = this; - this.refer = undefined; - return refer; - } -} diff --git a/packages/workbench/src/widget/utils.ts b/packages/workbench/src/widget/utils.ts deleted file mode 100644 index 6a1d7f6b6..000000000 --- a/packages/workbench/src/widget/utils.ts +++ /dev/null @@ -1,59 +0,0 @@ -import { IPublicTypeIconType, IPublicTypeTitleContent, TipContent } from '@alilc/lowcode-types'; -import { isI18nData, isTitleConfig } from '@alilc/lowcode-utils'; -import { isValidElement } from 'react'; - -export function composeTitle( - title?: IPublicTypeTitleContent, - icon?: IPublicTypeIconType, - tip?: TipContent, - tipAsTitle?: boolean, - noIcon?: boolean, -) { - let _title: IPublicTypeTitleContent | undefined; - if (!title) { - _title = {}; - if (!icon || tipAsTitle) { - _title = { - label: tip as any, - }; - tip = undefined; - } - } else { - _title = title; - } - - if (icon || tip) { - if (typeof _title !== 'object' || isValidElement(_title) || isI18nData(_title)) { - if (isValidElement(_title)) { - if (_title.type === 'svg' || (_title.type as any).getIcon) { - if (!icon) { - icon = _title; - } - if (tipAsTitle) { - _title = tip; - tip = null; - } else { - _title = undefined; - } - } - } - _title = { - label: _title as any, - icon, - tip, - }; - } else { - _title = { - ..._title, - icon, - tip, - } as any; - } - } - if (isTitleConfig(_title) && noIcon) { - if (!isValidElement(_title)) { - _title.icon = undefined; - } - } - return _title; -} diff --git a/packages/workbench/src/widget/widget-container.ts b/packages/workbench/src/widget/widget-container.ts deleted file mode 100644 index 8458dfbf6..000000000 --- a/packages/workbench/src/widget/widget-container.ts +++ /dev/null @@ -1,146 +0,0 @@ -import { observable, computed, makeObservable } from '@alilc/lowcode-editor-core'; -import { hasOwnProperty } from '@alilc/lowcode-utils'; -import { isPanel } from './panel'; - -export interface WidgetItem { - name: string; -} - -export interface Activeable { - setActive(flag: boolean): void; -} - -function isActiveable(obj: any): obj is Activeable { - return obj && obj.setActive; -} - -export class WidgetContainer<T extends WidgetItem = any, G extends WidgetItem = any> { - @observable.shallow items: T[] = []; - - private maps: { [name: string]: T } = {}; - - @observable.ref private _current: T & Activeable | null = null; - - get current() { - return this._current; - } - - // eslint-disable-next-line no-useless-constructor - constructor( - readonly name: string, - private handle: (item: T | G) => T, - private exclusive: boolean = false, - private checkVisible: () => boolean = () => true, - private defaultSetCurrent: boolean = false, - ) { - makeObservable(this); - } - - @computed get visible() { - return this.checkVisible(); - } - - active(nameOrItem?: T | string | null) { - let item: any = nameOrItem; - if (nameOrItem && typeof nameOrItem === 'string') { - item = this.get(nameOrItem); - } - if (!isActiveable(item)) { - item = null; - } - - if (this.exclusive) { - if (this._current === item) { - return; - } - if (this._current) { - this._current.setActive(false); - } - this._current = item; - } - - if (item) { - item.setActive(true); - } - } - - unactive(nameOrItem?: T | string | null) { - let item: any = nameOrItem; - if (nameOrItem && typeof nameOrItem === 'string') { - item = this.get(nameOrItem); - } - if (!isActiveable(item)) { - item = null; - } - if (this._current === item) { - this._current = null; - } - if (item) { - item.setActive(false); - } - } - - unactiveAll() { - Object.keys(this.maps).forEach((name) => this.unactive(name)); - } - - add(item: T | G): T { - item = this.handle(item); - const origin = this.get(item.name); - if (origin === item) { - return origin; - } - const i = origin ? this.items.indexOf(origin) : -1; - if (i > -1) { - this.items[i] = item; - } else { - this.items.push(item); - } - this.maps[item.name] = item; - if (isPanel(item)) { - item.setParent(this); - } - if (this.defaultSetCurrent) { - const shouldHiddenWhenInit = (item as any).config?.props?.hiddenWhenInit; - if (!this._current && !shouldHiddenWhenInit) { - this.active(item); - } - } - return item; - } - - get(name: string): T | null { - return this.maps[name] || null; - } - - getAt(index: number): T | null { - return this.items[index] || null; - } - - has(name: string): boolean { - return hasOwnProperty(this.maps, name); - } - - indexOf(item: T): number { - return this.items.indexOf(item); - } - - /** - * return indexOf the deletion - */ - remove(item: string | T): number { - const thing = typeof item === 'string' ? this.get(item) : item; - if (!thing) { - return -1; - } - const i = this.items.indexOf(thing); - if (i > -1) { - this.items.splice(i, 1); - } - delete this.maps[thing.name]; - if (thing === this.current) { - this._current = null; - } - return i; - } -} diff --git a/packages/workbench/src/widget/widget.ts b/packages/workbench/src/widget/widget.ts deleted file mode 100644 index 0718b6e80..000000000 --- a/packages/workbench/src/widget/widget.ts +++ /dev/null @@ -1,143 +0,0 @@ -import { ReactNode, createElement } from 'react'; -import { makeObservable, observable } from '@alilc/lowcode-editor-core'; -import { createContent, uniqueId } from '@alilc/lowcode-utils'; -import { getEvent } from '../../../engine/src/shell/api/event'; -import { WidgetConfig } from '../types'; -import { ISkeleton } from '../skeleton'; -import { WidgetView } from '../components/widget-views'; -import { IPublicTypeTitleContent, IPublicTypeWidgetBaseConfig } from '@alilc/lowcode-types'; - -export interface IWidget { - readonly name: string; - readonly content: ReactNode; - readonly align?: string; - readonly isWidget: true; - readonly visible: boolean; - readonly disabled?: boolean; - readonly body: ReactNode; - readonly skeleton: ISkeleton; - readonly config: IPublicTypeWidgetBaseConfig; - - getName(): string; - getContent(): any; - show(): void; - hide(): void; - toggle(): void; - enable?(): void; - disable?(): void; -} - -export class Widget implements IWidget { - readonly isWidget = true; - - readonly id = uniqueId('widget'); - - readonly name: string; - - readonly align?: string; - - @observable.ref private _visible = true; - - get visible(): boolean { - return this._visible; - } - - @observable.ref inited = false; - - @observable.ref private _disabled = false; - - private _body: ReactNode; - - get body() { - if (this.inited) { - return this._body; - } - this.inited = true; - const { content, contentProps } = this.config; - this._body = createContent(content, { - ...contentProps, - config: this.config, - editor: getEvent(this.skeleton.editor), - }); - return this._body; - } - - get content(): ReactNode { - return createElement(WidgetView, { - widget: this, - key: this.id, - }); - } - - readonly title: IPublicTypeTitleContent; - - constructor( - readonly skeleton: ISkeleton, - readonly config: WidgetConfig, - ) { - makeObservable(this); - const { props = {}, name } = config; - this.name = name; - this.align = props.align; - this.title = props.title || name; - if (props.onInit) { - props.onInit.call(this, this); - } - } - - getId() { - return this.id; - } - - getName() { - return this.name; - } - - getContent() { - return this.content; - } - - hide() { - this.setVisible(false); - } - - show() { - this.setVisible(true); - } - - setVisible(flag: boolean) { - if (flag === this._visible) { - return; - } - if (flag) { - this._visible = true; - } else if (this.inited) { - this._visible = false; - } - } - - toggle() { - this.setVisible(!this._visible); - } - - private setDisabled(flag: boolean) { - if (this._disabled === flag) return; - this._disabled = flag; - } - - disable() { - this.setDisabled(true); - } - - enable() { - this.setDisabled(false); - } - - get disabled(): boolean { - return this._disabled; - } -} - -export function isWidget(obj: any): obj is IWidget { - return obj && obj.isWidget; -} diff --git a/packages/workbench/tests/widget/utils.test.ts b/packages/workbench/tests/widget/utils.test.ts deleted file mode 100644 index 2836e86db..000000000 --- a/packages/workbench/tests/widget/utils.test.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { composeTitle } from '../../src/widget/utils'; -import * as React from 'react'; - -const label = React.createElement('div'); - -describe('composeTitle 测试', () => { - it('基础能力测试', () => { - expect(composeTitle(undefined)).toEqual({ - label: undefined, - }); - - expect(composeTitle(undefined, undefined, 'tips', true, true)).toEqual({ - icon: undefined, - label: 'tips', - }); - - expect(composeTitle(undefined, undefined, label, true, true)).toEqual({ - icon: undefined, - label, - }); - - expect(composeTitle({ - icon: undefined, - label, - }, undefined, '')).toEqual({ - icon: undefined, - label, - }); - - expect(composeTitle('settingsPane')).toEqual('settingsPane'); - - expect(composeTitle(label, undefined, '物料面板', true, true)).toEqual({ - icon: undefined, - label, - tip: '物料面板', - }); - - expect(composeTitle(label, undefined, label, true, true)).toEqual({ - icon: undefined, - label, - tip: label, - }); - - expect(composeTitle({ - label: "物料面板", - icon: undefined, - tip: null, - })).toEqual({ - label: "物料面板", - icon: undefined, - tip: null, - }) - }); -}) \ No newline at end of file diff --git a/packages/workbench/tsconfig.json b/packages/workbench/tsconfig.json index e081732e9..8edf132a3 100644 --- a/packages/workbench/tsconfig.json +++ b/packages/workbench/tsconfig.json @@ -3,7 +3,5 @@ "compilerOptions": { "outDir": "lib" }, - "include": [ - "./src/" -, "../engine/src/shell/api/event.ts" ] + "include": ["./src/"] }