1
0
mirror of synced 2026-03-22 18:48:34 +08:00

feat(vue-components,react-components): 增加点击事件,使用组件状态hook

This commit is contained in:
roymondchen
2025-03-06 20:29:38 +08:00
parent 8d0040da53
commit 0736646c63
60 changed files with 594 additions and 378 deletions

View File

@@ -1,5 +1,5 @@
{
"version": "0.0.2",
"version": "0.1.0",
"name": "@tmagic/react-text",
"type": "module",
"main": "src/index.ts",
@@ -14,16 +14,13 @@
"url": "https://github.com/Tencent/tmagic-editor.git"
},
"peerDependencies": {
"@tmagic/schema": "workspace:^",
"@tmagic/core": "workspace:^",
"@tmagic/react-runtime-help": "workspace:^",
"react": ">=18.3.1",
"react-dom": ">=18.3.1",
"typescript": "*"
},
"peerDependenciesMeta": {
"@tmagic/schema": {
"optional": true
},
"typescript": {
"optional": true
}

View File

@@ -18,8 +18,9 @@
import React from 'react';
import type { Id, MComponent } from '@tmagic/core';
import { COMMON_EVENT_PREFIX } from '@tmagic/core';
import { useApp } from '@tmagic/react-runtime-help';
import type { Id, MComponent } from '@tmagic/schema';
interface TextSchema extends Omit<MComponent, 'id'> {
id?: Id;
@@ -46,18 +47,25 @@ const Text: React.FC<TextProps> = ({
iteratorIndex,
iteratorContainerId,
}) => {
const { app } = useApp({ config, iteratorIndex, iteratorContainerId });
const { app, node } = useApp({ config, iteratorIndex, iteratorContainerId });
if (!app) return null;
const clickHandler = () => {
if (node && app) {
app.emit(`${COMMON_EVENT_PREFIX}click`, node);
}
};
return (
<p
className={className}
style={style}
data-tmagic-id={id}
data-tmagic-id={`${id || config.id || ''}`}
data-tmagic-container-index={containerIndex}
data-tmagic-iterator-index={iteratorIndex}
data-tmagic-iterator-container-id={iteratorContainerId}
onClick={clickHandler}
>
{config.text}
</p>

View File

@@ -1,4 +1,6 @@
import { COMMON_EVENT_PREFIX } from '@tmagic/core';
export default {
methods: [],
events: [],
events: [{ label: '点击', value: `${COMMON_EVENT_PREFIX}click` }],
};