feat(vue-components,react-components): 增加点击事件,使用组件状态hook
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { COMMON_EVENT_PREFIX } from '@tmagic/core';
|
||||
|
||||
export default {
|
||||
methods: [],
|
||||
events: [],
|
||||
events: [{ label: '点击', value: `${COMMON_EVENT_PREFIX}click` }],
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user