diff --git a/.eslintrc.js b/.eslintrc.js
index f1b6c7b..b22d43b 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -31,6 +31,16 @@ module.exports = {
'@typescript-eslint/indent': 0,
'import/no-cycle': 0,
'@typescript-eslint/no-shadow': 0,
- 'max-len': ["error", {"code": 180}]
- }
+ 'max-len': ['error', { code: 180 }],
+ 'comma-dangle': [
+ 'warn',
+ {
+ objects: 'always',
+ arrays: 'always',
+ imports: 'never',
+ functions: 'never',
+ },
+ ],
+ semi: ['error', 'always'],
+ },
};
diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
new file mode 100644
index 0000000..281c877
--- /dev/null
+++ b/.github/CODEOWNERS
@@ -0,0 +1,20 @@
+# ref: https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners
+
+# These owners will be the default owners for everything in
+# the repo. Unless a later match takes precedence
+* @liujuping @JackLian @alvarto
+
+/packages/plugin-manual/ @alvarto
+/packages/base-monaco-editor/ @alvarto @wangshihao111 @SuSunSam
+/packages/plugin-code-editor/ @alvarto @SuSunSam
+/packages/plugin-schema/ @alvarto
+/packages/plugin-components-pane/ @mark-ck @love999262
+/packages/plugin-datasource-pane/ @YSMJ1994
+/packages/plugin-zh-en/ @JackLian @liujuping
+/packages/plugin-undo-redo/ @JackLian @liujuping
+/packages/plugin-resource-tabs/ @JackLian @liujuping
+/packages/plugin-set-ref-prop/ @JackLian @liujuping
+/packages/plugin-view-manager-pane/ @JackLian @liujuping
+/packages/base-monaco-editor/ @hzd822
+/packages/plugin-multiple-editor/ @hzd822
+/packages/action-block @liujuping
\ No newline at end of file
diff --git a/.github/workflows/deprecate npm.yml b/.github/workflows/deprecate npm.yml
new file mode 100644
index 0000000..ea096ec
--- /dev/null
+++ b/.github/workflows/deprecate npm.yml
@@ -0,0 +1,32 @@
+name: deprecate Package Version
+
+on:
+ workflow_dispatch:
+ inputs:
+ version:
+ description: 'Version to be deleted package@version'
+ required: true
+
+jobs:
+ delete-package-version:
+ 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: Set up Node.js
+ uses: actions/setup-node@v2
+ with:
+ node-version: '14'
+
+ - name: deprecate Package Version
+ run: |
+ git config --local user.email "action@github.com"
+ git config --local user.name "GitHub Action"
+
+ echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc
+ npm deprecate ${{ github.event.inputs.version }} "This version is deprecated. Please consider upgrading to a newer version."
diff --git a/.github/workflows/publish beta npm.yml b/.github/workflows/publish beta npm.yml
new file mode 100644
index 0000000..01ab685
--- /dev/null
+++ b/.github/workflows/publish beta npm.yml
@@ -0,0 +1,38 @@
+name: Publish Beta NPM Packages
+on:
+ 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: Change to Package Directory
+ run: |
+ git config --local user.email "action@github.com"
+ git config --local user.name "GitHub Action"
+ npm install --legacy-peer-deps
+ echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc
+ cd packages/${{ github.event.inputs.packagePath }}
+ npm install --legacy-peer-deps
+ npm run build
+ npm version ${{ github.event.inputs.betaVersion }}
+ echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc
+ npm publish --tag beta
\ No newline at end of file
diff --git a/.github/workflows/publish npm.yml b/.github/workflows/publish npm.yml
new file mode 100644
index 0000000..5ada959
--- /dev/null
+++ b/.github/workflows/publish npm.yml
@@ -0,0 +1,51 @@
+name: Publish NPM Packages
+on:
+ 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: Publish Package
+ run: |
+ git config --local user.email "action@github.com"
+ git config --local user.name "GitHub Action"
+
+ echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc
+ npm install --legacy-peer-deps
+ cd packages/${{ github.event.inputs.packagePath }}
+ npm install --legacy-peer-deps
+ npm version ${{ github.event.inputs.versionType }}
+ npm run build
+
+ echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc
+ npm publish
+
+ echo "PACKAGE_NAME=$(node -p "require('./package.json').name")" >> $GITHUB_ENV
+ echo "PACKAGE_VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_ENV
+
+ git add package.json
+ git commit -m "Bump version to ${PACKAGE_VERSION}"
+
+ git tag -a "${PACKAGE_NAME}@${PACKAGE_VERSION}" -m "Release ${PACKAGE_NAME} version ${PACKAGE_VERSION}"
+ git push origin "${PACKAGE_NAME}@${PACKAGE_VERSION}"
\ No newline at end of file
diff --git a/README.md b/README.md
index d23206e..c71cea3 100644
--- a/README.md
+++ b/README.md
@@ -25,3 +25,5 @@
- plugin-schema
- plugin-undo-redo
- plugin-zh-cn
+- plugin-block
+- action-block
diff --git a/demo/build.json b/demo/build.json
deleted file mode 100644
index 11f88e5..0000000
--- a/demo/build.json
+++ /dev/null
@@ -1,38 +0,0 @@
-{
- "entry": {
- "index": "src/index"
- },
- "vendor": false,
- "devServer": {
- "hot": false
- },
- "publicPath": "public",
- "externals": {
- "react": "var window.React",
- "react-dom": "var window.ReactDOM",
- "prop-types": "var window.PropTypes",
- "@alifd/next": "var window.Next",
- "@alilc/lowcode-engine": "var window.AliLowCodeEngine",
- "@alilc/lowcode-editor-core": "var window.AliLowCodeEngine.common.editorCabin",
- "@alilc/lowcode-editor-skeleton": "var window.AliLowCodeEngine.common.skeletonCabin",
- "@alilc/lowcode-designer": "var window.AliLowCodeEngine.common.designerCabin",
- "@alilc/lowcode-engine-ext": "var window.AliLowCodeEngineExt",
- "@ali/lowcode-engine": "var window.AliLowCodeEngine",
- "moment": "var window.moment",
- "lodash": "var window._"
- },
- "plugins": [
- [
- "build-plugin-react-app"
- ],
- [
- "build-plugin-moment-locales",
- {
- "locales": [
- "zh-cn"
- ]
- }
- ],
- "./build.plugin.js"
- ]
-}
diff --git a/demo/build.plugin.js b/demo/build.plugin.js
deleted file mode 100644
index 12882de..0000000
--- a/demo/build.plugin.js
+++ /dev/null
@@ -1,58 +0,0 @@
-const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
-
-const HtmlWebpackPlugin = require('html-webpack-plugin');
-
-module.exports = ({ onGetWebpackConfig }) => {
- onGetWebpackConfig((config) => {
- config.resolve.plugin('tsconfigpaths').use(TsconfigPathsPlugin, [
- {
- configFile: './tsconfig.json',
- },
- ]);
-
- config.merge({
- node: {
- fs: 'empty',
- },
- });
- config.merge({
- entry: {
- index: require.resolve('./src/index.ts'),
- preview: require.resolve('./src/preview.tsx'),
- },
- });
- config
- .plugin('index')
- .use(HtmlWebpackPlugin, [
- {
- inject: false,
- templateParameters: {
- },
- template: require.resolve('./public/index.html'),
- filename: 'index.html',
- },
- ]);
- config
- .plugin('preview')
- .use(HtmlWebpackPlugin, [
- {
- inject: false,
- templateParameters: {
- },
- template: require.resolve('./public/preview.html'),
- filename: 'preview.html',
- },
- ]);
-
- config.plugins.delete('hot');
- config.devServer.hot(false);
-
- config.module // fixes https://github.com/graphql/graphql-js/issues/1272
- .rule('mjs$')
- .test(/\.mjs$/)
- .include
- .add(/node_modules/)
- .end()
- .type('javascript/auto');
- });
-};
diff --git a/demo/package.json b/demo/package.json
deleted file mode 100644
index 6d61e11..0000000
--- a/demo/package.json
+++ /dev/null
@@ -1,45 +0,0 @@
-{
- "name": "@alilc/lowcode-plugins-demo",
- "version": "1.0.0",
- "description": "Low-Code Engine 低代码搭建引擎 Demo 项目",
- "repository": "git@github.com:alibaba/lowcode-demo.git",
- "license": "MIT",
- "main": "index.js",
- "scripts": {
- "start": "build-scripts start --disable-reload",
- "build": "build-scripts build",
- "pub": "node ./scripts/watchdog.js && npm pub"
- },
- "files": [
- "build"
- ],
- "config": {},
- "dependencies": {
- "@alilc/lowcode-plugin-code-editor": "^1.0.1",
- "@alilc/lowcode-plugin-code-generator": "^1.0.1",
- "@alilc/lowcode-plugin-components-pane": "^1.0.2",
- "@alilc/lowcode-plugin-datasource-pane": "1.0.0",
- "@alilc/lowcode-plugin-inject": "^1.0.0",
- "@alilc/lowcode-plugin-manual": "^1.0.0",
- "@alilc/lowcode-plugin-schema": "^1.0.0",
- "@alilc/lowcode-plugin-simulator-select": "^1.0.0",
- "@alilc/lowcode-plugin-undo-redo": "^1.0.0",
- "@alilc/lowcode-plugin-zh-en": "^1.0.0",
- "@alilc/lowcode-react-renderer": "^1.0.0",
- "@alilc/lowcode-setter-behavior": "^1.0.0",
- "@alilc/lowcode-setter-title": "^1.0.2"
- },
- "devDependencies": {
- "@alilc/lowcode-engine": "^1.0.0",
- "@alilc/lowcode-types": "^1.0.0",
- "@alib/build-scripts": "^0.1.18",
- "@types/events": "^3.0.0",
- "@types/react": "^16.8.3",
- "@types/react-dom": "^16.8.2",
- "@types/streamsaver": "^2.0.0",
- "build-plugin-fusion": "^0.1.0",
- "build-plugin-moment-locales": "^0.1.0",
- "build-plugin-react-app": "^1.1.2",
- "tsconfig-paths-webpack-plugin": "^3.2.0"
- }
-}
diff --git a/demo/public/favicon.png b/demo/public/favicon.png
deleted file mode 100644
index 307ffbd..0000000
Binary files a/demo/public/favicon.png and /dev/null differ
diff --git a/demo/public/index.html b/demo/public/index.html
deleted file mode 100644
index 8ef9ceb..0000000
--- a/demo/public/index.html
+++ /dev/null
@@ -1,41 +0,0 @@
-
-
-
-
-
-
- 阿里低代码引擎 Demo
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/demo/public/mock-pages.json b/demo/public/mock-pages.json
deleted file mode 100644
index 8e20f2f..0000000
--- a/demo/public/mock-pages.json
+++ /dev/null
@@ -1 +0,0 @@
-{"success":true,"content":[{"gmtModified":"2021-03-06 00:40:54","formUuid":"FORM-6X866SC1KM4O4BLF3U7879QB0EMT2Z3TGIWLKW","parentNavUuid":"NAV-SYSTEM-PARENT-UUID","hidden":"n","navUuid":"FORM-6X866SC1KM4O4BLF3U7879QB0EMT2Z3TGIWLKW","navType":"PAGE","isIndex":"n","isNew":"n","gmtCreate":"2021-03-06 00:27:26","title":{"en_US":"页面1","zh_CN":"页面1","type":"i18n"},"relateUuid":"FORM-6X866SC1KM4O4BLF3U7879QB0EMT2Z3TGIWLKW","parentId":0,"listOrder":0,"id":556103}]}
\ No newline at end of file
diff --git a/demo/public/mock/info.json b/demo/public/mock/info.json
deleted file mode 100644
index 006209b..0000000
--- a/demo/public/mock/info.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "info": "Hello AliLowCode!!"
-}
\ No newline at end of file
diff --git a/demo/public/preview.html b/demo/public/preview.html
deleted file mode 100644
index 798b156..0000000
--- a/demo/public/preview.html
+++ /dev/null
@@ -1,25 +0,0 @@
-
-
-
-
-
- 预览低代码
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/demo/src/index.ts b/demo/src/index.ts
deleted file mode 100644
index d0d58c3..0000000
--- a/demo/src/index.ts
+++ /dev/null
@@ -1,36 +0,0 @@
-import { init } from '@alilc/lowcode-engine';
-import registerPlugins from './universal/plugin';
-import './universal/global.scss';
-
-
-const preference = new Map();
-preference.set('DataSourcePane', {
- importPlugins: [],
- dataSourceTypes: [
- {
- type: 'fetch',
- },
- {
- type: 'jsonp',
- }
- ]
-});
-
-(async function main() {
- await registerPlugins();
-
- init(document.getElementById('lce-container')!, {
- // designMode: 'live',
- // locale: 'zh-CN',
- enableCondition: true,
- enableCanvasLock: true,
- // 默认绑定变量
- supportVariableGlobally: true,
- // simulatorUrl 在当 engine-core.js 同一个路径下时是不需要配置的!!!
- // 这里因为用的是 unpkg,在不同 npm 包,engine-core.js 和 react-simulator-renderer.js 是不同路径
- simulatorUrl: [
- 'https://alifd.alicdn.com/npm/@alilc/lowcode-react-simulator-renderer@beta/dist/css/react-simulator-renderer.css',
- 'https://alifd.alicdn.com/npm/@alilc/lowcode-react-simulator-renderer@beta/dist/js/react-simulator-renderer.js'
- ]
- }, preference);
-})();
diff --git a/demo/src/preview.tsx b/demo/src/preview.tsx
deleted file mode 100644
index 27627ff..0000000
--- a/demo/src/preview.tsx
+++ /dev/null
@@ -1,63 +0,0 @@
-import ReactDOM from 'react-dom';
-import React, { useState } from 'react';
-import { Loading } from '@alifd/next';
-import { buildComponents, assetBundle, AssetLevel, AssetLoader } from '@alilc/lowcode-utils';
-import ReactRenderer from '@alilc/lowcode-react-renderer';
-import { injectComponents } from '@alilc/lowcode-plugin-inject';
-
-const SamplePreview = () => {
- const [data, setData] = useState({});
-
- async function init() {
- const packages = JSON.parse(window.localStorage.getItem('packages') || '');
- const projectSchema = JSON.parse(window.localStorage.getItem('projectSchema') || '');
- const { componentsMap: componentsMapArray, componentsTree } = projectSchema;
- const componentsMap: any = {};
- componentsMapArray.forEach((component: any) => {
- componentsMap[component.componentName] = component;
- });
- const schema = componentsTree[0];
-
- const libraryMap = {};
- const libraryAsset = [];
- packages.forEach(({ package: _package, library, urls, renderUrls }) => {
- libraryMap[_package] = library;
- if (renderUrls) {
- libraryAsset.push(renderUrls);
- } else if (urls) {
- libraryAsset.push(urls);
- }
- });
-
- const vendors = [assetBundle(libraryAsset, AssetLevel.Library)];
-
- // TODO asset may cause pollution
- const assetLoader = new AssetLoader();
- await assetLoader.load(libraryAsset);
- const components = await injectComponents(buildComponents(libraryMap, componentsMap));
-
- setData({
- schema,
- components,
- });
- }
-
- const { schema, components } = data;
-
- if (!schema || !components) {
- init();
- return ;
- }
-
- return (
-
-
-
- );
-};
-
-ReactDOM.render(, document.getElementById('ice-container'));
diff --git a/demo/src/universal/global.scss b/demo/src/universal/global.scss
deleted file mode 100644
index 02906a3..0000000
--- a/demo/src/universal/global.scss
+++ /dev/null
@@ -1,55 +0,0 @@
-body {
- font-family: PingFangSC-Regular, Roboto, Helvetica Neue, Helvetica, Tahoma, Arial, PingFang SC-Light, Microsoft YaHei;
- font-size: 12px;
- * {
- box-sizing: border-box;
- }
-}
-
-body, #lce-container {
- position: fixed;
- left: 0;
- right: 0;
- bottom: 0;
- top: 0;
- box-sizing: border-box;
- padding: 0;
- margin: 0;
- overflow: hidden;
- text-rendering: optimizeLegibility;
- -webkit-user-select: none;
- -webkit-user-drag: none;
- -webkit-text-size-adjust: none;
- -webkit-touch-callout: none;
- -webkit-font-smoothing: antialiased;
- #engine {
- width: 100%;
- height: 100%;
- }
-}
-
-html {
- min-width: 1024px;
-}
-
-.save-sample {
- width: 80px;
- height: 30px;
- background-color: #5584FF;
- border: none;
- outline: none;
- border-radius: 4px;
- color: white;
- cursor: pointer;
-}
-
-.load-assets {
- width: 100px;
- height: 30px;
- background-color: #5584FF;
- border: none;
- outline: none;
- border-radius: 4px;
- color: white;
- cursor: pointer;
-}
diff --git a/demo/tsconfig.json b/demo/tsconfig.json
deleted file mode 100644
index 23314ab..0000000
--- a/demo/tsconfig.json
+++ /dev/null
@@ -1,44 +0,0 @@
-{
- "compilerOptions": {
- "baseUrl": ".",
- "declaration": true,
- "lib": ["es2015", "dom"],
- // Target latest version of ECMAScript.
- "target": "esnext",
- // Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'.
- "module": "esnext",
- // Search under node_modules for non-relative imports.
- "moduleResolution": "node",
- // Process & infer types from .js files.
- "allowJs": true,
- // Report errors in .js files.
- "checkJs": false,
- // Don't emit; allow Babel to transform files.
- // "noEmit": true,
- // Enable strictest settings like strictNullChecks & noImplicitAny.
- "strict": true,
- // Allow default imports from modules with no default export. This does not affect code emit, just typechecking.
- "allowSyntheticDefaultImports": true,
- // Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'.
- "esModuleInterop": true,
- // Specify JSX code generation: 'preserve', 'react-native', or 'react'.
- "jsx": "preserve",
- // Import emit helpers (e.g. __extends, __rest, etc..) from tslib
- "importHelpers": true,
- // Enables experimental support for ES7 decorators.
- "experimentalDecorators": true,
- // Generates corresponding .map file.
- "sourceMap": true,
- // Disallow inconsistently-cased references to the same file.
- "forceConsistentCasingInFileNames": true,
- // Allow json import
- "resolveJsonModule": true,
- // skip type checking of declaration files
- "skipLibCheck": true,
- "outDir": "lib"
- },
- "include": [
- "./src/"
- ],
- "exclude": ["**/test", "**/lib", "**/es", "node_modules"]
-}
diff --git a/package.json b/package.json
index c4dfabc..761e9e0 100644
--- a/package.json
+++ b/package.json
@@ -10,6 +10,7 @@
]
},
"scripts": {
+ "bootstrap": "lerna bootstrap",
"dev": "npm run bootstrap && npm run build && cooking watch -c build/cooking.demo.js -p",
"build": "./scripts/build.sh",
"clean": "rm -rf ./packages/*/lib ./packages/*/es ./packages/*/dist ./packages/*/build",
@@ -39,9 +40,9 @@
}
},
"devDependencies": {
- "lerna": "^4.x",
"f2elint": "^2.0.1",
"husky": "^7.0.4",
+ "lerna": "^4.x",
"typescript": "^3.2.2"
},
"engines": {
@@ -53,5 +54,6 @@
},
"resolutions": {
"@builder/babel-preset-ice": "1.0.1"
- }
-}
+ },
+ "repository": "https://github.com/alibaba/lowcode-plugins.git"
+}
\ No newline at end of file
diff --git a/packages/action-block/README.md b/packages/action-block/README.md
new file mode 100644
index 0000000..9bda2b0
--- /dev/null
+++ b/packages/action-block/README.md
@@ -0,0 +1,46 @@
+# 区块管理 - 保存为区块
+
+## 区块实体
+
+```
+
+interface Block {
+ name: string;
+ title: string;
+ schema: string;
+ screenshot: string;
+ created_at?: string;
+ updated_at?: string;
+}
+
+```
+
+## 注意
+
+使用区块管理需要提前将对应的 API 注册到 engine config 里:
+
+```
+
+interface BlockAPI {
+ listBlocks: () => Block[];
+ createBlock: (Block) => any;
+}
+
+function setupConfig() {
+ config.set('apiList', {
+ block: {
+ listBlocks,
+ createBlock
+ },
+ })
+}
+```
+
+# 使用方式
+
+```
+import { material } from '@alilc/lowcode-engine';
+import { default as saveAsBlock } from '@alilc/action-block';
+
+material.addBuiltinComponentAction(saveAsBlock);
+```
\ No newline at end of file
diff --git a/packages/plugin-datasource-pane/build.json b/packages/action-block/build.json
similarity index 53%
rename from packages/plugin-datasource-pane/build.json
rename to packages/action-block/build.json
index b2fe2de..d2836c1 100644
--- a/packages/plugin-datasource-pane/build.json
+++ b/packages/action-block/build.json
@@ -1,4 +1,9 @@
{
+ "externals": {
+ "react": "var window.React",
+ "@alifd/next": "var window.Next",
+ "@alilc/lowcode-engine": "var window.AliLowCodeEngine"
+ },
"plugins": [
"build-plugin-component",
"build-plugin-fusion",
diff --git a/packages/action-block/package.json b/packages/action-block/package.json
new file mode 100644
index 0000000..e9c0c00
--- /dev/null
+++ b/packages/action-block/package.json
@@ -0,0 +1,31 @@
+{
+ "name": "@alilc/action-block",
+ "version": "1.0.1",
+ "description": "",
+ "main": "lib/index.js",
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/alibaba/lowcode-plugins.git",
+ "directory": "packages/action-block"
+ },
+ "scripts": {
+ "start": "build-scripts start",
+ "build": "build-scripts build",
+ "prepublishOnly": "npm run build"
+ },
+ "author": "mark.ck",
+ "license": "MIT",
+ "dependencies": {
+ "@alifd/next": "^1.25.31",
+ "@alilc/lowcode-engine": "^1.0.5",
+ "html2canvas": "^1.4.1",
+ "react": "^16.8.1"
+ },
+ "devDependencies": {
+ "@alib/build-scripts": "^0.1.32",
+ "build-plugin-component": "^1.10.0",
+ "build-plugin-fusion": "^0.1.22",
+ "build-plugin-moment-locales": "^0.1.3"
+ },
+ "homepage": "https://unpkg.com/@alilc/action-block@1.0.1/build/index.html"
+}
diff --git a/packages/action-block/src/index.scss b/packages/action-block/src/index.scss
new file mode 100644
index 0000000..1f019fb
--- /dev/null
+++ b/packages/action-block/src/index.scss
@@ -0,0 +1,11 @@
+.block-screenshot {
+ background: gainsboro;
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ padding: 10px 0;
+
+ img {
+ max-width: 80%;
+ }
+}
\ No newline at end of file
diff --git a/packages/action-block/src/index.tsx b/packages/action-block/src/index.tsx
new file mode 100644
index 0000000..22eaa46
--- /dev/null
+++ b/packages/action-block/src/index.tsx
@@ -0,0 +1,119 @@
+import * as React from 'react';
+import { default as html2canvas } from 'html2canvas';
+import { Node, config, event } from '@alilc/lowcode-engine';
+import { Dialog, Form, Input } from '@alifd/next';
+import './index.scss';
+
+const FormItem = Form.Item;
+
+interface SaveAsBlockProps {
+ node: Node;
+}
+
+function checkBlockAPI () {
+ const apiList = config.get('apiList') || {};
+ const { block: blockAPI } = apiList;
+
+ if (!blockAPI?.createBlock) {
+ throw new Error('[BlockPane] block api required in engine config.');
+ }
+
+ return blockAPI;
+}
+
+let dialog: any;
+
+const SaveAsBlock = (props: SaveAsBlockProps) => {
+ const { createBlock } = checkBlockAPI();
+ const { node } = props;
+ const [ src, setSrc ] = React.useState();
+ React.useEffect(() => {
+ const generateImage = async () => {
+ let dom2 = node.getDOMNode();
+ // console.log('html2canvas: ', html2canvas);
+ const canvas = await html2canvas?.(dom2, { scale: 0.5 });
+ const dataUrl = canvas.toDataURL();
+ setSrc(dataUrl);
+ };
+
+ generateImage();
+ }, []);
+
+ const save = async (values) => {
+ const { name, title } = values;
+ const { schema } = node;
+
+ await createBlock({
+ name,
+ title,
+ schema: JSON.stringify(schema),
+ screenshot: src,
+ });
+ dialog?.hide();
+ event.emit('BlockChanged');
+ }
+
+ return
+}
+
+
+export default {
+ name: 'add',
+ content: {
+ icon: {
+ type: 'add',
+ size: 'xs'
+ },
+ title: '新增',
+ action(node: Node) {
+ // console.log('node: ', node);
+ dialog = Dialog.show({
+ v2: true,
+ title: "保存为区块",
+ content: ,
+ footer: false
+ });
+ },
+ },
+ important: true,
+};
diff --git a/packages/base-monaco-editor/CHANGELOG.md b/packages/base-monaco-editor/CHANGELOG.md
index 58196de..1ca5153 100644
--- a/packages/base-monaco-editor/CHANGELOG.md
+++ b/packages/base-monaco-editor/CHANGELOG.md
@@ -1,3 +1,27 @@
+## 1.1.1
+
+- 避免 UIPaaS 中的样式冲突,将 `.ve-code-control` 替换为 `.lc-code-control`
+
+## 1.1.0
+
+- Publish following changes
+
+## 1.1.0-beta.3
+
+- 去除 `overflow: visible` 样式,避免动作面板遮住按钮
+
+## 1.1.0-beta.1
+
+- 添加 controller 实例,可用作中间交换介质,解决与代码编辑相关的插件间的协作问题 [@wangshihao111](https://github.com/wangshihao111)
+- 优化 Monaco 单例,元信息保存在 controller 实例内部 [@wangshihao111](https://github.com/wangshihao111)
+
+## 1.1.0-beta.0
+
+- 重构 type / path / value 联动,彻底修复 monaco 在多文件模式下覆盖多个 path 值的 bug
+- 修复 ts 类型问题 [@wangshihao111](https://github.com/wangshihao111)
+- 添加 configure 方法,支持配置是否开启 monaco 单例模式 [@wangshihao111](https://github.com/wangshihao111)
+- 新增插件参数:`enhancers`,用于强化编辑器功能 [@wangshihao111](https://github.com/wangshihao111)
+
## 1.0.0
- Publish following changes
diff --git a/packages/base-monaco-editor/README.md b/packages/base-monaco-editor/README.md
index 0740b37..49473bb 100644
--- a/packages/base-monaco-editor/README.md
+++ b/packages/base-monaco-editor/README.md
@@ -125,6 +125,24 @@ function App() {
ReactDOM.render(, mountNode);
```
+### Using controller
+
+```ts
+import { controller } from '@alilc/lowcode-plugin-base-monaco-editor';
+
+// configure Monaco to be singleton
+controller.updateMeta({ singleton: true });
+
+// Get all metadata
+controller.getMeta();
+
+// register a custom method
+controller.registerMethod('methodName', (a, b, c) => { });
+
+// call custom methods
+const ret = controller.call('methodName', a, b, c);
+```
+
## Citation
This is forked from [monaco-react](https://github.com/suren-atoyan/monaco-react). Thanks for [suren-atoyan](https://github.com/suren-atoyan)'s effort for making monaco editor appoachable.
diff --git a/packages/base-monaco-editor/package.json b/packages/base-monaco-editor/package.json
index 520741f..6dfa41a 100644
--- a/packages/base-monaco-editor/package.json
+++ b/packages/base-monaco-editor/package.json
@@ -1,8 +1,9 @@
{
"name": "@alilc/lowcode-plugin-base-monaco-editor",
- "version": "1.0.0",
+ "version": "1.1.2",
"description": "代码编辑组件,monaco-editor 的低代码适配封装",
"publishConfig": {
+ "registry": "https://registry.npmjs.org/",
"access": "public"
},
"files": [
@@ -31,7 +32,7 @@
"component"
],
"dependencies": {
- "@monaco-editor/loader": "^1.2.0",
+ "@monaco-editor/loader": "1.3.0",
"classnames": "^2.3.1"
},
"devDependencies": {
@@ -62,5 +63,10 @@
"commit-msg": "f2elint commit-msg-scan"
}
},
- "homepage": "https://unpkg.com/@alilc/lowcode-plugin-base-monaco-editor@1.0.0/build/index.html"
+ "homepage": "https://unpkg.com/@alilc/lowcode-plugin-base-monaco-editor@1.1.2/build/index.html",
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/alibaba/lowcode-plugins.git",
+ "directory": "packages/base-monaco-editor"
+ }
}
diff --git a/packages/base-monaco-editor/src/controller.ts b/packages/base-monaco-editor/src/controller.ts
new file mode 100644
index 0000000..2ebe419
--- /dev/null
+++ b/packages/base-monaco-editor/src/controller.ts
@@ -0,0 +1,39 @@
+export interface EditorMeta {
+ singleton: boolean;
+ [key: string]: any;
+}
+
+export class Controller {
+ private methodMap: Record;
+ private meta: EditorMeta;
+
+ constructor() {
+ this.methodMap = {};
+ this.meta = { singleton: false };
+ }
+
+ registerMethod(name: string, fn: Function) {
+ this.methodMap[name] = fn;
+ }
+
+ call(name: string, ...args: any[]) {
+ return this.methodMap[name]?.(...args);
+ }
+
+ updateMeta(obj: Partial) {
+ Object.assign(this.meta, obj);
+ }
+
+ getMeta() {
+ return Object.freeze({ ...this.meta });
+ }
+}
+
+const CONFIGURE_KEY = '__base_monaco_editor_controller__';
+const fakeWindow: any = window;
+
+if (!fakeWindow[CONFIGURE_KEY]) {
+ fakeWindow[CONFIGURE_KEY] = new Controller();
+}
+
+export const controller: Controller = fakeWindow[CONFIGURE_KEY];
diff --git a/packages/base-monaco-editor/src/helper.ts b/packages/base-monaco-editor/src/helper.ts
index 475f80a..5180c52 100644
--- a/packages/base-monaco-editor/src/helper.ts
+++ b/packages/base-monaco-editor/src/helper.ts
@@ -1,70 +1,25 @@
/* eslint-disable no-empty */
-import { useEffect, useState, useRef, CSSProperties } from 'react';
-import loader from '@monaco-editor/loader';
-
-loader.config({
- paths: {
- vs: 'https://g.alicdn.com/code/lib/monaco-editor/0.31.1/min/vs',
- },
-});
-
-type IAmbigousFn = (...args: any[]) => any;
+import React, { useEffect, useState, useRef, CSSProperties } from 'react';
+import { Monaco } from '@monaco-editor/loader';
+import type { editor as oEditor } from 'monaco-editor';
+import { getMonaco } from './monaco';
// @todo fill type def for monaco editor without refering monaco editor
/**
* @see https://microsoft.github.io/monaco-editor/api/index.html
*/
-export interface IEditorInstance {
- getModel: IAmbigousFn;
- dispose: IAmbigousFn;
- getValue: () => string;
- onDidChangeModelContent: (input: any) => void;
- setTheme: (input: string) => void;
- setModelLanguage: (model: any, language: string) => void;
- layout: () => void;
- setValue: (value: string) => void;
- executeEdits: IAmbigousFn;
- pushUndoStop: IAmbigousFn;
- EditorOption?: Record;
- getOption?: (input: string) => any;
- onDidFocusEditorText: (...args: any[]) => void;
- onDidBlurEditorText: (...args: any[]) => void;
- getModifiedEditor?: () => IEditorInstance;
- setModel: IAmbigousFn;
- revealLineInCenter: IAmbigousFn;
- focus: IAmbigousFn;
- Range: new(...args: any[]) => any;
- getPosition: IAmbigousFn;
- setPosition: IAmbigousFn;
- deltaDecorations: IAmbigousFn;
- addAction: IAmbigousFn;
- saveViewState: () => ICodeEditorViewState;
- createModel: IAmbigousFn;
- [key: string]: any;
-}
-export interface IMonacoInstance {
- editor?: {
- create: IAmbigousFn;
- [key: string]: any;
- };
- KeyCode?: Record;
- KeyMod?: Record;
- [otherKeys: string]: any;
-}
+export type IEditorInstance = oEditor.IStandaloneCodeEditor | oEditor.IStandaloneDiffEditor;
-type ICodeEditorViewState = {
- contributionsState: any;
- cursorState: any;
- viewState: any;
-}
+export type EditorEnhancer =
+ (monaco: Monaco, editorIns: IEditorInstance) => any;
export interface IGeneralManacoEditorProps {
/** [Monaco editor options](https://microsoft.github.io/monaco-editor/) */
options?: Record;
/** callback after monaco's loaded and after editor's loaded */
- editorDidMount?: (monaco: IMonacoInstance, editor: IEditorInstance) => void;
+ editorDidMount?: (monaco: Monaco, editor: IEditorInstance) => void;
/** callback after monaco's loaded and before editor's loaded */
- editorWillMount?: (monaco: IMonacoInstance) => void;
+ editorWillMount?: (monaco: Monaco) => void;
/** path of the current model, useful when creating a multi-model editor */
path?: string;
/** whether to save the models' view states between model changes or not */
@@ -89,6 +44,8 @@ export interface IGeneralManacoEditorProps {
enableOutline?: boolean;
/** style of wrapper */
style?: CSSProperties;
+ overrideServices?: oEditor.IEditorOverrideServices;
+ enhancers?: EditorEnhancer[];
}
export interface ISingleMonacoEditorProps extends IGeneralManacoEditorProps {
@@ -103,16 +60,15 @@ export interface IDiffMonacoEditorProps extends IGeneralManacoEditorProps {
const CURRENT_LANGUAGE = ((window as any).locale || window.localStorage.getItem('vdev-locale') || '').replace(/_/, '-') || 'zh-CN';
export const WORD_EDITOR_INITIALIZING = CURRENT_LANGUAGE === 'en-US' ? 'Initializing Editor' : '编辑器初始化中';
-export const INITIAL_OPTIONS = {
+export const INITIAL_OPTIONS: oEditor.IStandaloneEditorConstructionOptions = {
fontSize: 12,
tabSize: 2,
fontFamily: 'Menlo, Monaco, Courier New, monospace',
- renderIndentGuides: true,
folding: true,
minimap: {
enabled: false,
},
- autoIndent: true,
+ autoIndent: 'advanced',
contextmenu: true,
useTabStops: true,
wordBasedSuggestions: true,
@@ -131,9 +87,34 @@ export const INITIAL_OPTIONS = {
},
};
-export const useEditor = (type: 'single' | 'diff', props: IGeneralManacoEditorProps) => {
+const DIFF_EDITOR_INITIAL_OPTIONS: oEditor.IStandaloneDiffEditorConstructionOptions = {
+ fontSize: 12,
+ fontFamily: 'Menlo, Monaco, Courier New, monospace',
+ folding: true,
+ minimap: {
+ enabled: false,
+ },
+ autoIndent: 'advanced',
+ contextmenu: true,
+ useTabStops: true,
+ formatOnPaste: true,
+ automaticLayout: true,
+ lineNumbers: 'on',
+ wordWrap: 'off',
+ scrollBeyondLastLine: false,
+ fixedOverflowWidgets: false,
+ snippetSuggestions: 'top',
+ scrollbar: {
+ vertical: 'auto',
+ horizontal: 'auto',
+ verticalScrollbarSize: 10,
+ horizontalScrollbarSize: 10,
+ },
+};
+
+export const useEditor = (type: 'single' | 'diff', props: IGeneralManacoEditorProps) => {
const {
- editorDidMount, editorWillMount, theme, value, path, language, saveViewState, defaultValue,
+ editorDidMount, editorWillMount, theme, value, path, language, saveViewState, defaultValue, enhancers, overrideServices
} = props;
const [isEditorReady, setIsEditorReady] = useState(false);
@@ -146,7 +127,7 @@ export const useEditor = (type: 'single' | 'diff', props: IGeneralManacoEditorPr
const previousPath = usePrevious(path);
const requireConfigRef = useRef(props.requireConfig);
const optionRef = useRef(props.options);
- const monacoRef = useRef();
+ const monacoRef = useRef();
const editorRef = useRef();
const containerRef = useRef();
const typeRef = useRef(type);
@@ -154,7 +135,13 @@ export const useEditor = (type: 'single' | 'diff', props: IGeneralManacoEditorPr
const editorWillMountRef = useRef();
const decomposeRef = useRef(false);
- const viewStatusRef = useRef