diff --git a/.github/workflows/publish beta npm.yml b/.github/workflows/publish beta npm.yml new file mode 100644 index 0000000..b051410 --- /dev/null +++ b/.github/workflows/publish beta npm.yml @@ -0,0 +1,41 @@ +name: Publish Beta NPM Packages +on: push + workflow_dispatch: + inputs: + packagePath: + description: 'Path to the package (e.g., action-block)' + required: true + betaVersion: + description: 'Beta version number (e.g., 1.0.1-beta.0)' + required: true + +jobs: + publish-package: + runs-on: ubuntu-latest + if: >- + github.actor == 'JackLian' || github.actor == 'liujuping' + + steps: + - name: Checkout Repository + uses: actions/checkout@v2 + + - name: Setup Node.js + uses: actions/setup-node@v2 + with: + node-version: '16' # 或者您希望的任何版本 + + - name: Install Dependencies and Publish + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + cd packages + cd ${{ github.event.inputs.packagePath }} + npm install + # 假设您使用 npm 来修改版本和发布 + npm run build + npm version ${{ github.event.inputs.betaVersion }} + echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc + + npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} # 确保在您的 GitHub 仓库的 Secrets 中设置了 NPM_TOKEN diff --git a/.github/workflows/publish npm.yml b/.github/workflows/publish npm.yml new file mode 100644 index 0000000..a1b8b8d --- /dev/null +++ b/.github/workflows/publish npm.yml @@ -0,0 +1,50 @@ +name: Publish NPM Packages +on: push + workflow_dispatch: + inputs: + packagePath: + description: 'Path to the package (e.g., action-block)' + required: true + versionType: + description: 'Version update type (major, minor, patch)' + required: true + default: 'patch' + +jobs: + publish-package: + runs-on: ubuntu-latest + if: >- + github.ref == 'refs/heads/main' && + (github.actor == 'JackLian' || github.actor == 'liujuping') + + steps: + - name: Checkout Repository + uses: actions/checkout@v2 + + - name: Setup Node.js + uses: actions/setup-node@v2 + with: + node-version: '16' # 或者您希望的任何版本 + + - name: Install Dependencies and Publish + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + cd packages + cd ${{ github.event.inputs.packagePath }} + npm install + # 假设您使用 npm 来修改版本和发布 + npm run build + npm version patch + + echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc + npm publish + + echo "::set-output name=PACKAGE_NAME::$(node -p "require('./package.json').name")" + echo "::set-output name=PACKAGE_VERSION::$(node -p "require('./package.json').version")" + + git tag -a "${{ steps.package_info.outputs.PACKAGE_NAME }}@${{ steps.package_info.outputs.PACKAGE_VERSION }}" -m "Release ${{ steps.package_info.outputs.PACKAGE_NAME }} version ${{ steps.package_info.outputs.PACKAGE_VERSION }}" + git push origin "${{ steps.package_info.outputs.PACKAGE_NAME }}@${{ steps.package_info.outputs.PACKAGE_VERSION }}" + + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} # 确保在您的 GitHub 仓库的 Secrets 中设置了 NPM_TOKEN diff --git a/packages/plugin-test/build.json b/packages/plugin-test/build.json new file mode 100644 index 0000000..840cacf --- /dev/null +++ b/packages/plugin-test/build.json @@ -0,0 +1,19 @@ +{ + "plugins": [ + [ + "@alilc/build-plugin-alt", + { + "type": "plugin" + } + ], + [ + "build-plugin-fusion", + { + "themePackage": "@alifd/theme-lowcode-light" + } + ], + ["build-plugin-moment-locales", { + "locales": ["zh-cn"] + }] + ] +} diff --git a/packages/plugin-test/package.json b/packages/plugin-test/package.json new file mode 100644 index 0000000..6054c2f --- /dev/null +++ b/packages/plugin-test/package.json @@ -0,0 +1,44 @@ +{ + "name": "@alilc/lowcode-plugin-test", + "version": "1.0.0", + "description": "alibaba lowcode editor test plugin", + "files": [ + "es", + "lib" + ], + "main": "lib/index.js", + "module": "es/index.js", + "scripts": { + "start": "build-scripts start", + "build": "build-scripts build", + "prepublishOnly": "npm run build" + }, + "keywords": [ + "lowcode", + "editor" + ], + "dependencies": { + "@alilc/lowcode-utils": "^1.0.0", + "@alilc/lowcode-types": "^1.1.9", + "react": "^16.8.1", + "react-dom": "^16.8.1" + }, + "devDependencies": { + "@alib/build-scripts": "^0.1.3", + "@alilc/build-plugin-alt": "^1.0.1", + "@alilc/lowcode-engine": "^1.0.0", + "@types/react": "^16.9.13", + "@types/react-dom": "^16.9.4", + "build-plugin-fusion": "^0.1.22", + "build-plugin-moment-locales": "^0.1.0" + }, + "publishConfig": { + "registry": "https://registry.npmjs.org/", + "access": "public" + }, + "repository": { + "type": "git", + "url": "https://github.com/alibaba/lowcode-plugins.git", + "directory": "packages/plugin-undo-redo" + } +} diff --git a/packages/plugin-test/src/index.tsx b/packages/plugin-test/src/index.tsx new file mode 100644 index 0000000..d489336 --- /dev/null +++ b/packages/plugin-test/src/index.tsx @@ -0,0 +1,115 @@ +import React, { PureComponent } from 'react'; +import { project } from '@alilc/lowcode-engine'; +import { Button, Icon } from '@alifd/next'; +import { PluginProps, IPublicTypeDisposable } from '@alilc/lowcode-types'; + +export interface IProps extends PluginProps { + logo?: string; +} + +export interface IState { + undoEnable: boolean; + redoEnable: boolean; +} + +class Test extends PureComponent { + static displayName = 'Test'; + + private history: any; + private changeDocumentDispose?: IPublicTypeDisposable; + private changeStateDispose?: IPublicTypeDisposable; + constructor(props: any) { + super(props); + this.state = { + undoEnable: false, + redoEnable: false, + }; + this.init(); + } + + init = (): void => { + this.changeDocumentDispose = project.onChangeDocument(doc => { + this.history = doc.history; + this.updateState(this.history?.getState() || 0); + this.changeStateDispose?.(); + this.changeStateDispose = this.history.onChangeState(() => { + this.updateState(this.history?.getState() || 0); + }); + }); + }; + + updateState = (state: number): void => { + this.setState({ + undoEnable: !!(state & 1), + redoEnable: !!(state & 2), + }); + }; + + handleUndoClick = (): void => { + this.history.back(); + }; + + handleRedoClick = (): void => { + this.history.forward(); + }; + + componentWillUnmount() { + this.changeDocumentDispose?.(); + this.changeStateDispose?.(); + } + + render(): React.ReactNode { + const { undoEnable, redoEnable } = this.state; + return ( +
+ + +
+ ); + } +} + +const plugin = (ctx: any) => { + return { + // 插件名,注册环境下唯一 + name: 'PluginTest', + // 依赖的插件(插件名数组) + dep: [], + // 插件的初始化函数,在引擎初始化之后会立刻调用 + init() { + // 往引擎增加面板 + ctx.skeleton.add({ + area: 'topArea', + type: 'Widget', + name: 'undoRedo', + content: Test, + props: { + align: 'right', + width: 88, + }, + }) + }, + }; +}; + +plugin.pluginName = 'PluginTest' + +export default plugin diff --git a/packages/plugin-test/tsconfig.json b/packages/plugin-test/tsconfig.json new file mode 100644 index 0000000..c37b76e --- /dev/null +++ b/packages/plugin-test/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "lib" + }, + "include": [ + "./src/" + ] +}