mirror of
https://github.com/smartxworks/sunmao-ui.git
synced 2024-11-21 03:15:49 +08:00
remove wrong files
This commit is contained in:
parent
381346aa8a
commit
46960fd4e5
@ -1,80 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>meta-ui runtime example: delete button</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module">
|
||||
import renderApp from "../../src/main.tsx";
|
||||
renderApp({
|
||||
version: "example/v1",
|
||||
metadata: {
|
||||
name: "fetch-button",
|
||||
description: "fetch button example",
|
||||
},
|
||||
spec: {
|
||||
components: [
|
||||
{
|
||||
id: "fetch_btn",
|
||||
type: "chakra_ui/v1/button",
|
||||
properties: {
|
||||
text: {
|
||||
raw: `{{ fetch_btn.count > 0 ? 'CLICK TO CONFIRM' : '**DELETE** Button' }}`,
|
||||
format: "md",
|
||||
},
|
||||
isLoading: false,
|
||||
colorScheme: "twitter",
|
||||
},
|
||||
traits: [
|
||||
{
|
||||
type: "core/v1/state",
|
||||
properties: {
|
||||
key: "count",
|
||||
initialValue: 0,
|
||||
},
|
||||
},
|
||||
{
|
||||
type: "core/v1/fetch",
|
||||
properties: {
|
||||
url: "http://localhost:3000",
|
||||
method: "get",
|
||||
},
|
||||
},
|
||||
{
|
||||
type: "core/v1/event",
|
||||
properties: {
|
||||
events: [
|
||||
{
|
||||
event: "click",
|
||||
componentId: "fetch_btn",
|
||||
method: {
|
||||
name: "trigger",
|
||||
},
|
||||
wait: {},
|
||||
disabled: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "debug_text",
|
||||
type: "core/v1/text",
|
||||
properties: {
|
||||
value: {
|
||||
raw: `{{ fetch_btn.value }}`,
|
||||
format: "md",
|
||||
},
|
||||
},
|
||||
traits: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -1,75 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>meta-ui runtime example: delete button</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module">
|
||||
import renderApp from "../../src/main.tsx";
|
||||
renderApp({
|
||||
version: "example/v1",
|
||||
metadata: {
|
||||
name: "fetch-button",
|
||||
description: "fetch button example",
|
||||
},
|
||||
spec: {
|
||||
components: [
|
||||
{
|
||||
id: "fetch_btn",
|
||||
type: "chakra_ui/v1/button",
|
||||
properties: {
|
||||
text: {
|
||||
raw: `{{ fetch_btn.count > 0 ? 'CLICK TO CONFIRM' : '**DELETE** Button' }}`,
|
||||
format: "md",
|
||||
},
|
||||
isLoading: false,
|
||||
colorScheme: "twitter",
|
||||
},
|
||||
traits: [
|
||||
{
|
||||
type: "core/v1/state",
|
||||
properties: {
|
||||
key: "count",
|
||||
initialValue: undefined,
|
||||
},
|
||||
},
|
||||
{
|
||||
type: "core/v1/event",
|
||||
properties: {
|
||||
events: [
|
||||
{
|
||||
event: "click",
|
||||
componentId: "fetch_btn",
|
||||
method: {
|
||||
name: "setValue",
|
||||
parameters:
|
||||
"{{ fetch_btn.count > 0 ? 0 : fetch_btn.count + 1 }}",
|
||||
},
|
||||
wait: {},
|
||||
disabled: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "debug_text",
|
||||
type: "core/v1/text",
|
||||
properties: {
|
||||
value: {
|
||||
raw: `{{ fetch_btn.value + '---' + fetch_btn.count }}`,
|
||||
format: "md",
|
||||
},
|
||||
},
|
||||
traits: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -1,134 +0,0 @@
|
||||
import { useEffect, useMemo } from "react";
|
||||
import { Static, Type } from "@sinclair/typebox";
|
||||
import { createTrait } from "@meta-ui/core";
|
||||
import { TraitImplementation } from "../../registry";
|
||||
import { emitter, useExpression } from "../../store";
|
||||
import { nanoid } from "nanoid";
|
||||
const useFetchTrait: TraitImplementation<FetchTraitSchemaProperty> = ({
|
||||
url,
|
||||
name,
|
||||
method,
|
||||
lazy,
|
||||
headers,
|
||||
body,
|
||||
subscribeMethods,
|
||||
mergeState,
|
||||
}) => {
|
||||
const rawUrl = useExpression(url);
|
||||
|
||||
const [sucessEvent, failureEvent, hookId] = useMemo(() => {
|
||||
const nid = nanoid();
|
||||
return [`${nid}.success`, `${nid}.error`, nid];
|
||||
}, []);
|
||||
|
||||
if (lazy === undefined) {
|
||||
lazy = method.toLowerCase() !== "get";
|
||||
}
|
||||
|
||||
const header = new Headers();
|
||||
if (headers) {
|
||||
for (const key in headers) {
|
||||
header.set(key, headers[key]);
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const responseHandler = (res: Response) => {
|
||||
mergeState({
|
||||
[name]: res,
|
||||
});
|
||||
};
|
||||
const failureHandler = (res: Response | Error) => {};
|
||||
|
||||
emitter.on(sucessEvent, responseHandler);
|
||||
emitter.on(failureEvent, failureHandler);
|
||||
if (!lazy) {
|
||||
fetch(rawUrl, {
|
||||
method,
|
||||
headers: header,
|
||||
body,
|
||||
}).then(
|
||||
(res) => {
|
||||
emitter.emit(hookId, res);
|
||||
},
|
||||
(err) => {
|
||||
emitter.emit(hookId, err);
|
||||
}
|
||||
);
|
||||
}
|
||||
}, []);
|
||||
|
||||
subscribeMethods({
|
||||
trigger: () => {
|
||||
fetch(rawUrl, {
|
||||
method,
|
||||
headers: header,
|
||||
body,
|
||||
}).then(
|
||||
(res) => {
|
||||
emitter.emit(hookId, res);
|
||||
},
|
||||
(err) => {
|
||||
emitter.emit(hookId, err);
|
||||
}
|
||||
);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const NamePropertySchema = Type.String();
|
||||
const UrlPropertySchema = Type.String();
|
||||
const MethodPropertySchema = Type.String();
|
||||
const LazyPropertySchema = Type.Boolean();
|
||||
const BodyPropertySchema = Type.Any(); // BodyInit
|
||||
const HeaderPropertySchema = Type.Record(Type.String(), Type.String());
|
||||
|
||||
type FetchTraitSchemaProperty = {
|
||||
name: Static<typeof NamePropertySchema>;
|
||||
url: Static<typeof UrlPropertySchema>;
|
||||
method: Static<typeof MethodPropertySchema>;
|
||||
lazy?: Static<typeof LazyPropertySchema>;
|
||||
body?: Static<typeof BodyPropertySchema>;
|
||||
headers?: Static<typeof HeaderPropertySchema>;
|
||||
};
|
||||
|
||||
export default {
|
||||
...createTrait({
|
||||
version: "core/v1",
|
||||
metadata: {
|
||||
name: "fetch",
|
||||
description: "add fetch ability for component",
|
||||
},
|
||||
spec: {
|
||||
properties: [
|
||||
{
|
||||
name: "url",
|
||||
...UrlPropertySchema,
|
||||
},
|
||||
{
|
||||
name: "method",
|
||||
...MethodPropertySchema,
|
||||
},
|
||||
{
|
||||
name: "lazy",
|
||||
...LazyPropertySchema,
|
||||
},
|
||||
{
|
||||
name: "body",
|
||||
...BodyPropertySchema,
|
||||
},
|
||||
{
|
||||
name: "header",
|
||||
...HeaderPropertySchema,
|
||||
},
|
||||
],
|
||||
state: {},
|
||||
methods: [
|
||||
{
|
||||
name: "trigger",
|
||||
},
|
||||
],
|
||||
},
|
||||
}),
|
||||
impl: useFetchTrait,
|
||||
};
|
Loading…
Reference in New Issue
Block a user