From 05fcc76ceb2d52aeb6e72abd98e70a45acf0c4db Mon Sep 17 00:00:00 2001 From: BoBoooooo Date: Thu, 11 Apr 2024 13:40:04 +0800 Subject: [PATCH 1/6] Create sync.yml --- .github/workflows/sync.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .github/workflows/sync.yml diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml new file mode 100644 index 00000000..69a5b8c1 --- /dev/null +++ b/.github/workflows/sync.yml @@ -0,0 +1,26 @@ +name: Sync with upstream + +on: + schedule: + - cron: '0 */24 * * *' + workflow_dispatch: + +jobs: + sync: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + ref: main + - name: Fetch upstream + run: git remote add upstream https://github.com/NetEase/tango.git + - name: Sync with upstream + env: + GITHUB_TOKEN: ${{ secrets.PERSONAL_TOKEN }} + run: | + git fetch upstream + git checkout main + git merge upstream/main + git push + From 3d3f638b1e9d731c4a48da491868dbea8e56deec Mon Sep 17 00:00:00 2001 From: BoBoooooo Date: Thu, 11 Apr 2024 13:45:47 +0800 Subject: [PATCH 2/6] Update sync.yml --- .github/workflows/sync.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml index 69a5b8c1..3b7b45f0 100644 --- a/.github/workflows/sync.yml +++ b/.github/workflows/sync.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: ref: main - name: Fetch upstream From 236966d8ead1da404f9708bc706879abbc304c77 Mon Sep 17 00:00:00 2001 From: BoBoooooo <17746714@qq.com> Date: Fri, 12 Apr 2024 14:57:11 +0800 Subject: [PATCH 3/6] feat: support nativeDom --- apps/playground/src/helpers/mock-files.ts | 89 ++++++++++++++++------- apps/playground/src/helpers/prototypes.ts | 74 +++++++++++++++++++ packages/core/src/helpers/string.ts | 7 +- 3 files changed, 140 insertions(+), 30 deletions(-) diff --git a/apps/playground/src/helpers/mock-files.ts b/apps/playground/src/helpers/mock-files.ts index 5ed38c05..24d5d445 100644 --- a/apps/playground/src/helpers/mock-files.ts +++ b/apps/playground/src/helpers/mock-files.ts @@ -173,6 +173,60 @@ class App extends React.Component { +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+
); } @@ -227,38 +281,21 @@ const storeApp = ` import { defineStore } from '@music163/tango-boot'; export default defineStore({ - title: 'Page Title', array: [1, 2, 3], test: function() { console.log('test'); - console.log('test'); - console.log('test'); - console.log('test'); - console.log('test'); - console.log('test'); - console.log('test'); - console.log('test'); - console.log('test'); - console.log('test'); - console.log('test'); - console.log('test'); - console.log('test'); - console.log('test'); - console.log('test'); - console.log('test'); - console.log('test'); - console.log('test'); - console.log('test'); - console.log('test'); - console.log('test'); - console.log('test'); - console.log('test'); - console.log('test'); - console.log('test'); - console.log('test'); + }, + + submitForm: function(event) { + event.preventDefault(); + const formData = new FormData(event.target); + const username = formData.get("username"); + const password = formData.get("password"); + const role = formData.get("role"); + console.log("Submitted Data:", { username, password, role }); } }, 'app'); `; diff --git a/apps/playground/src/helpers/prototypes.ts b/apps/playground/src/helpers/prototypes.ts index da8e93f6..63e39515 100644 --- a/apps/playground/src/helpers/prototypes.ts +++ b/apps/playground/src/helpers/prototypes.ts @@ -85,8 +85,82 @@ basePrototypes['Section'].siblingNames = [ 'Section', ]; +export const nativeDomPrototypes = () => { + const doms = [ + 'div', + 'span', + 'h1', + 'h2', + 'p', + 'a', + 'img', + 'ul', + 'ol', + 'li', + 'input', + 'button', + 'form', + 'table', + 'tr', + 'td', + 'header', + 'footer', + 'nav', + 'section', + 'article', + 'aside', + 'main', + 'video', + 'audio', + 'label', + 'select', + 'option', + 'textarea', + 'iframe', + ]; + const componentPrototypes: Dict = doms.reduce( + (acc: Dict, tag) => { + acc[tag] = { + name: tag, + title: tag, + hasChildren: true, + package: '', + type: 'element', + props: [ + { + name: 'style', + title: '样式', + group: 'style', + setter: 'expressionSetter', + }, + { + name: 'className', + title: '类名', + setter: 'textSetter', + }, + { + name: 'id', + title: 'ID', + setter: 'textSetter', + }, + { + name: 'onClick', + title: '点击事件', + setter: 'actionSetter', + group: 'event', + }, + ], + }; + return acc; + }, + {}, + ); + return componentPrototypes; +}; + // iconfont: https://www.iconfont.cn/manage/index?manage_type=myprojects&projectId=2891794 const prototypes: Dict = { + ...nativeDomPrototypes(), ...(basePrototypes as any), SnippetSuccessResult, Snippet2ColumnLayout, diff --git a/packages/core/src/helpers/string.ts b/packages/core/src/helpers/string.ts index eedaa198..16e8300c 100644 --- a/packages/core/src/helpers/string.ts +++ b/packages/core/src/helpers/string.ts @@ -75,7 +75,8 @@ export function inferFileType(filename: string): FileType { /** * 判断组件名是否合法 * @example Button -> valid - * @example div -> invalid + * @example div -> valid + * @example undefined | null -> invalid * @param name * @returns */ @@ -83,9 +84,7 @@ export function isValidComponentName(name: string) { if (!name) { return false; } - - const firstChar = name.charAt(0); - return firstChar === firstChar.toUpperCase(); + return true; } /** From 014e6e5e5025eb6bfab28555d9c1afbbf49643eb Mon Sep 17 00:00:00 2001 From: BoBoooooo <17746714@qq.com> Date: Fri, 12 Apr 2024 14:59:14 +0800 Subject: [PATCH 4/6] ci: remove sync.yml --- .github/workflows/sync.yml | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 .github/workflows/sync.yml diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml deleted file mode 100644 index 3b7b45f0..00000000 --- a/.github/workflows/sync.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: Sync with upstream - -on: - schedule: - - cron: '0 */24 * * *' - workflow_dispatch: - -jobs: - sync: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - ref: main - - name: Fetch upstream - run: git remote add upstream https://github.com/NetEase/tango.git - - name: Sync with upstream - env: - GITHUB_TOKEN: ${{ secrets.PERSONAL_TOKEN }} - run: | - git fetch upstream - git checkout main - git merge upstream/main - git push - From a0113d29524efacd3b06f83ed7e80a66da5014a6 Mon Sep 17 00:00:00 2001 From: BoBoooooo <17746714@qq.com> Date: Fri, 12 Apr 2024 15:18:04 +0800 Subject: [PATCH 5/6] fix: update test case --- packages/core/tests/helpers.test.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/core/tests/helpers.test.ts b/packages/core/tests/helpers.test.ts index f9c90fdf..9956188c 100644 --- a/packages/core/tests/helpers.test.ts +++ b/packages/core/tests/helpers.test.ts @@ -161,6 +161,10 @@ describe('string helpers', () => { it('isValidComponentName', () => { expect(isValidComponentName('Button')).toBeTruthy(); expect(isValidComponentName('Button.Group')).toBeTruthy(); + expect(isValidComponentName('div')).toBeTruthy(); + expect(isValidComponentName('')).toBeFalsy(); + expect(isValidComponentName(null)).toBeFalsy(); + expect(isValidComponentName(undefined)).toBeFalsy(); }); it('inferFileType', () => { From c13578aa94bacfcdbfeca15349ccf9d9667485a7 Mon Sep 17 00:00:00 2001 From: BoBoooooo <17746714@qq.com> Date: Mon, 15 Apr 2024 14:14:03 +0800 Subject: [PATCH 6/6] fix: update isValidComponentName logic --- packages/core/src/helpers/string.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/core/src/helpers/string.ts b/packages/core/src/helpers/string.ts index 16e8300c..392e3d0e 100644 --- a/packages/core/src/helpers/string.ts +++ b/packages/core/src/helpers/string.ts @@ -75,16 +75,22 @@ export function inferFileType(filename: string): FileType { /** * 判断组件名是否合法 * @example Button -> valid - * @example div -> valid - * @example undefined | null -> invalid + * @example isStrict ? div -> invalid : div -> valid * @param name + * @param isStrict 是否严格模式(严格模式不匹配原生标签) * @returns */ -export function isValidComponentName(name: string) { +export function isValidComponentName(name: string, isStrict = false) { if (!name) { return false; } - return true; + + if (!isStrict) { + return true; + } + + const firstChar = name.charAt(0); + return firstChar === firstChar.toUpperCase(); } /**