@meshagent/meshagent-tailwind 0.5.7 → 0.5.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/CHANGELOG.md +3 -0
  2. package/dist/cjs/Chat.js +28 -5
  3. package/dist/cjs/ChatInput.d.ts +4 -1
  4. package/dist/cjs/ChatInput.js +15 -3
  5. package/dist/cjs/ChatThread.js +1 -0
  6. package/dist/cjs/ChatTypingIndicator.js +2 -2
  7. package/dist/cjs/components/pane-example.d.ts +1 -0
  8. package/dist/cjs/components/pane-example.js +43 -0
  9. package/dist/cjs/components/ui/dialog.d.ts +15 -0
  10. package/dist/cjs/components/ui/dialog.js +166 -0
  11. package/dist/cjs/components/ui/form.d.ts +24 -0
  12. package/dist/cjs/components/ui/form.js +146 -0
  13. package/dist/cjs/components/ui/input.d.ts +3 -0
  14. package/dist/cjs/components/ui/input.js +41 -0
  15. package/dist/cjs/components/ui/label.d.ts +4 -0
  16. package/dist/cjs/components/ui/label.js +53 -0
  17. package/dist/cjs/components/ui/radio-group.d.ts +5 -0
  18. package/dist/cjs/components/ui/radio-group.js +76 -0
  19. package/dist/cjs/components/ui/select.d.ts +15 -0
  20. package/dist/cjs/components/ui/select.js +199 -0
  21. package/dist/cjs/components/ui/sheet.d.ts +13 -0
  22. package/dist/cjs/components/ui/sheet.js +110 -0
  23. package/dist/cjs/components/ui/sonner.d.ts +3 -0
  24. package/dist/cjs/components/ui/sonner.js +42 -0
  25. package/dist/cjs/lib/pane-service.d.ts +16 -0
  26. package/dist/cjs/lib/pane-service.js +35 -0
  27. package/dist/cjs/lib/utils.d.ts +4 -0
  28. package/dist/cjs/tools/ask-user-for-file.d.ts +10 -0
  29. package/dist/cjs/tools/ask-user-for-file.js +68 -0
  30. package/dist/cjs/tools/ask-user.d.ts +10 -0
  31. package/dist/cjs/tools/ask-user.js +161 -0
  32. package/dist/cjs/tools/build-schema.d.ts +3 -0
  33. package/dist/cjs/tools/build-schema.js +55 -0
  34. package/dist/cjs/tools/display-document.d.ts +10 -0
  35. package/dist/cjs/tools/display-document.js +49 -0
  36. package/dist/cjs/tools/file-dialog.d.ts +11 -0
  37. package/dist/cjs/tools/file-dialog.js +113 -0
  38. package/dist/cjs/tools/form-dialog.d.ts +12 -0
  39. package/dist/cjs/tools/form-dialog.js +92 -0
  40. package/dist/cjs/tools/form-schema.d.ts +41 -0
  41. package/dist/cjs/tools/form-schema.js +51 -0
  42. package/dist/cjs/tools/form.d.ts +16 -0
  43. package/dist/cjs/tools/form.js +81 -0
  44. package/dist/cjs/tools/toast.d.ts +10 -0
  45. package/dist/cjs/tools/toast.js +52 -0
  46. package/dist/cjs/tools/ui-toolkit.d.ts +6 -0
  47. package/dist/cjs/tools/ui-toolkit.js +44 -0
  48. package/dist/esm/Chat.js +29 -6
  49. package/dist/esm/ChatInput.d.ts +4 -1
  50. package/dist/esm/ChatInput.js +15 -3
  51. package/dist/esm/ChatThread.js +1 -0
  52. package/dist/esm/ChatTypingIndicator.js +2 -2
  53. package/dist/esm/components/pane-example.d.ts +1 -0
  54. package/dist/esm/components/pane-example.js +30 -0
  55. package/dist/esm/components/ui/dialog.d.ts +15 -0
  56. package/dist/esm/components/ui/dialog.js +136 -0
  57. package/dist/esm/components/ui/form.d.ts +24 -0
  58. package/dist/esm/components/ui/form.js +121 -0
  59. package/dist/esm/components/ui/input.d.ts +3 -0
  60. package/dist/esm/components/ui/input.js +21 -0
  61. package/dist/esm/components/ui/label.d.ts +4 -0
  62. package/dist/esm/components/ui/label.js +23 -0
  63. package/dist/esm/components/ui/radio-group.d.ts +5 -0
  64. package/dist/esm/components/ui/radio-group.js +46 -0
  65. package/dist/esm/components/ui/select.d.ts +15 -0
  66. package/dist/esm/components/ui/select.js +169 -0
  67. package/dist/esm/components/ui/sheet.d.ts +13 -0
  68. package/dist/esm/components/ui/sheet.js +80 -0
  69. package/dist/esm/components/ui/sonner.d.ts +3 -0
  70. package/dist/esm/components/ui/sonner.js +22 -0
  71. package/dist/esm/lib/pane-service.d.ts +16 -0
  72. package/dist/esm/lib/pane-service.js +15 -0
  73. package/dist/esm/lib/utils.d.ts +4 -0
  74. package/dist/esm/tools/ask-user-for-file.d.ts +10 -0
  75. package/dist/esm/tools/ask-user-for-file.js +48 -0
  76. package/dist/esm/tools/ask-user.d.ts +10 -0
  77. package/dist/esm/tools/ask-user.js +141 -0
  78. package/dist/esm/tools/build-schema.d.ts +3 -0
  79. package/dist/esm/tools/build-schema.js +25 -0
  80. package/dist/esm/tools/display-document.d.ts +10 -0
  81. package/dist/esm/tools/display-document.js +29 -0
  82. package/dist/esm/tools/file-dialog.d.ts +11 -0
  83. package/dist/esm/tools/file-dialog.js +101 -0
  84. package/dist/esm/tools/form-dialog.d.ts +12 -0
  85. package/dist/esm/tools/form-dialog.js +79 -0
  86. package/dist/esm/tools/form-schema.d.ts +41 -0
  87. package/dist/esm/tools/form-schema.js +31 -0
  88. package/dist/esm/tools/form.d.ts +16 -0
  89. package/dist/esm/tools/form.js +64 -0
  90. package/dist/esm/tools/toast.d.ts +10 -0
  91. package/dist/esm/tools/toast.js +32 -0
  92. package/dist/esm/tools/ui-toolkit.d.ts +6 -0
  93. package/dist/esm/tools/ui-toolkit.js +24 -0
  94. package/dist/index.css +1 -1
  95. package/package.json +7 -4
@@ -0,0 +1,161 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var ask_user_exports = {};
20
+ __export(ask_user_exports, {
21
+ AskUser: () => AskUser
22
+ });
23
+ module.exports = __toCommonJS(ask_user_exports);
24
+ var import_meshagent = require("@meshagent/meshagent");
25
+ var import_form_dialog = require("./form-dialog");
26
+ const askUserSchema = {
27
+ "type": "object",
28
+ "additionalProperties": false,
29
+ "required": ["subject", "form", "help"],
30
+ "properties": {
31
+ "subject": {
32
+ "type": "string",
33
+ "description": "a very short description suitable for a dialog title"
34
+ },
35
+ "help": {
36
+ "type": "string",
37
+ "description": "helpful information that explains why this information is being collected and how it will be used"
38
+ },
39
+ "form": {
40
+ "type": "array",
41
+ "items": {
42
+ "anyOf": [
43
+ {
44
+ "type": "object",
45
+ "additionalProperties": false,
46
+ "required": ["input"],
47
+ "properties": {
48
+ "input": {
49
+ "type": "object",
50
+ "additionalProperties": false,
51
+ "required": ["multiline", "name", "description", "default_value"],
52
+ "properties": {
53
+ "name": { "type": "string" },
54
+ "description": { "type": "string" },
55
+ "multiline": { "type": "boolean" },
56
+ "default_value": { "type": "string" }
57
+ }
58
+ }
59
+ }
60
+ },
61
+ {
62
+ "type": "object",
63
+ "additionalProperties": false,
64
+ "required": ["checkbox"],
65
+ "properties": {
66
+ "checkbox": {
67
+ "type": "object",
68
+ "additionalProperties": false,
69
+ "required": ["name", "description", "default_value"],
70
+ "properties": {
71
+ "name": { "type": "string" },
72
+ "description": { "type": "string" },
73
+ "default_value": { "type": "boolean" }
74
+ }
75
+ }
76
+ }
77
+ },
78
+ {
79
+ "type": "object",
80
+ "additionalProperties": false,
81
+ "required": ["radio_group"],
82
+ "description": "allows the user to select a single option from a list of options. best for multiple choice questions or surveys",
83
+ "properties": {
84
+ "radio_group": {
85
+ "type": "object",
86
+ "additionalProperties": false,
87
+ "required": ["name", "default_value", "description", "options"],
88
+ "properties": {
89
+ "name": { "type": "string" },
90
+ "description": { "type": "string" },
91
+ "default_value": { "type": "string" },
92
+ "options": {
93
+ "type": "array",
94
+ "items": {
95
+ "type": "object",
96
+ "additionalProperties": false,
97
+ "required": ["name", "value"],
98
+ "properties": {
99
+ "name": { "type": "string" },
100
+ "value": { "type": "string" }
101
+ }
102
+ }
103
+ }
104
+ }
105
+ }
106
+ }
107
+ },
108
+ {
109
+ "type": "object",
110
+ "additionalProperties": false,
111
+ "required": ["select"],
112
+ "properties": {
113
+ "select": {
114
+ "type": "object",
115
+ "additionalProperties": false,
116
+ "required": ["name", "options", "description", "default_value"],
117
+ "properties": {
118
+ "name": { "type": "string" },
119
+ "description": { "type": "string" },
120
+ "default_value": { "type": "string" },
121
+ "options": {
122
+ "type": "array",
123
+ "items": {
124
+ "type": "object",
125
+ "additionalProperties": false,
126
+ "required": ["name", "value"],
127
+ "properties": {
128
+ "name": { "type": "string" },
129
+ "value": { "type": "string" }
130
+ }
131
+ }
132
+ }
133
+ }
134
+ }
135
+ }
136
+ }
137
+ ]
138
+ }
139
+ }
140
+ }
141
+ };
142
+ class AskUser extends import_meshagent.Tool {
143
+ constructor({ name, description, title } = {}) {
144
+ super({
145
+ name: name ?? "ask_user",
146
+ description: description ?? "ask the user a question",
147
+ title: title ?? "Ask User",
148
+ inputSchema: askUserSchema
149
+ });
150
+ }
151
+ async execute(arguments_) {
152
+ const result = await (0, import_form_dialog.showUserFormDialog)({
153
+ formSchema: arguments_.form,
154
+ title: arguments_.subject
155
+ });
156
+ if (result === null) {
157
+ throw new Error("User cancelled the form dialog");
158
+ }
159
+ return new import_meshagent.JsonResponse({ json: result });
160
+ }
161
+ }
@@ -0,0 +1,3 @@
1
+ import * as z from "zod";
2
+ import type { FormSchema } from "./form-schema";
3
+ export declare function buildZodSchemaFromAskUser(formSchema: FormSchema): z.ZodObject<any>;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var build_schema_exports = {};
30
+ __export(build_schema_exports, {
31
+ buildZodSchemaFromAskUser: () => buildZodSchemaFromAskUser
32
+ });
33
+ module.exports = __toCommonJS(build_schema_exports);
34
+ var z = __toESM(require("zod"));
35
+ function buildZodSchemaFromAskUser(formSchema) {
36
+ const shape = {};
37
+ for (const item of formSchema) {
38
+ if (item.hasOwnProperty("input")) {
39
+ const f = item.input;
40
+ shape[f.name] = z.string().min(1, `${f.description} is required`);
41
+ } else if (item.hasOwnProperty("checkbox")) {
42
+ const f = item.checkbox;
43
+ shape[f.name] = z.boolean();
44
+ } else if (item.hasOwnProperty("radio_group")) {
45
+ const f = item.radio_group;
46
+ const options = f.options.map((opt) => opt.value);
47
+ shape[f.name] = z.enum(options, "Select an option").default(f.default_value || options[0]);
48
+ } else if (item.hasOwnProperty("select")) {
49
+ const f = item.select;
50
+ const options = f.options.map((opt) => opt.value);
51
+ shape[f.name] = z.enum(options, "Select an option").default(f.default_value || options[0]);
52
+ }
53
+ }
54
+ return z.object(shape);
55
+ }
@@ -0,0 +1,10 @@
1
+ import { Tool } from '@meshagent/meshagent';
2
+ import type { Response } from '@meshagent/meshagent';
3
+ export declare class DisplayDocument extends Tool {
4
+ constructor({ name, description, title }?: {
5
+ name?: string;
6
+ description?: string;
7
+ title?: string;
8
+ });
9
+ execute(arguments_: Record<string, any>): Promise<Response>;
10
+ }
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var display_document_exports = {};
20
+ __export(display_document_exports, {
21
+ DisplayDocument: () => DisplayDocument
22
+ });
23
+ module.exports = __toCommonJS(display_document_exports);
24
+ var import_meshagent = require("@meshagent/meshagent");
25
+ const displayDocumentSchema = {
26
+ type: "object",
27
+ additionalProperties: false,
28
+ required: ["path"],
29
+ properties: {
30
+ path: {
31
+ type: "string"
32
+ }
33
+ }
34
+ };
35
+ class DisplayDocument extends import_meshagent.Tool {
36
+ constructor({ name, description, title } = {}) {
37
+ super({
38
+ name: name ?? "display_document",
39
+ description: description ?? "display document to the user",
40
+ title: title ?? "display document",
41
+ inputSchema: displayDocumentSchema
42
+ });
43
+ }
44
+ async execute(arguments_) {
45
+ const { path } = arguments_;
46
+ console.log("Navigate to document:", path);
47
+ return new import_meshagent.EmptyResponse();
48
+ }
49
+ }
@@ -0,0 +1,11 @@
1
+ export declare function showFileDialog({ title, description }: {
2
+ title?: string;
3
+ description?: string;
4
+ }): Promise<Record<string, any> | null>;
5
+ export declare function FileDialog({ title, description, onSubmit, onDismiss, onCleanup }: {
6
+ title?: string;
7
+ description?: string;
8
+ onSubmit: (file: File | null) => void;
9
+ onDismiss: () => void;
10
+ onCleanup: () => void;
11
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var file_dialog_exports = {};
20
+ __export(file_dialog_exports, {
21
+ FileDialog: () => FileDialog,
22
+ showFileDialog: () => showFileDialog
23
+ });
24
+ module.exports = __toCommonJS(file_dialog_exports);
25
+ var import_jsx_runtime = require("react/jsx-runtime");
26
+ var import_react = require("react");
27
+ var import_client = require("react-dom/client");
28
+ var import_dialog = require("../components/ui/dialog");
29
+ var import_button = require("../components/ui/button");
30
+ function showFileDialog({ title, description }) {
31
+ return new Promise((resolve) => {
32
+ const container = document.createElement("div");
33
+ document.body.appendChild(container);
34
+ const root = (0, import_client.createRoot)(container);
35
+ const onCleanup = () => {
36
+ root.unmount();
37
+ container.remove();
38
+ };
39
+ const onDismiss = () => resolve(null);
40
+ root.render(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
41
+ FileDialog,
42
+ {
43
+ title,
44
+ description,
45
+ onSubmit: resolve,
46
+ onDismiss,
47
+ onCleanup
48
+ }
49
+ ));
50
+ });
51
+ }
52
+ function FileDialog({ title, description, onSubmit, onDismiss, onCleanup }) {
53
+ const inputRef = (0, import_react.useRef)(null);
54
+ const [open, setOpen] = (0, import_react.useState)(true);
55
+ const [selectedFile, setSelectedFile] = (0, import_react.useState)(null);
56
+ const handleSubmit = (0, import_react.useCallback)((e) => {
57
+ e.preventDefault();
58
+ onSubmit(selectedFile);
59
+ setOpen(false);
60
+ }, [selectedFile, onSubmit]);
61
+ const handleFileChange = (e) => {
62
+ if (e.target.files && e.target.files[0]) {
63
+ setSelectedFile(e.target.files[0]);
64
+ }
65
+ };
66
+ const onOpenChange = (0, import_react.useCallback)((isOpen) => {
67
+ onDismiss();
68
+ setOpen(isOpen);
69
+ }, [onDismiss]);
70
+ const onAnimationEnd = (0, import_react.useCallback)(() => {
71
+ if (!open) {
72
+ onCleanup();
73
+ }
74
+ }, [open, onCleanup]);
75
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.Dialog, { open, onOpenChange, modal: true, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
76
+ import_dialog.DialogContent,
77
+ {
78
+ showCloseButton: true,
79
+ onAnimationEnd,
80
+ className: "\n sm:max-w-[425px]\n fixed top-1/2 left-1/2 w-[90vw] max-w-md max-h-[90vh]\n transform -translate-x-1/2 -translate-y-1/2\n bg-white rounded shadow-lg p-6 overflow-y-auto",
81
+ children: [
82
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_dialog.DialogHeader, { children: [
83
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.DialogTitle, { children: title }),
84
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.DialogDescription, { children: description })
85
+ ] }),
86
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
87
+ "input",
88
+ {
89
+ id: "file-input",
90
+ type: "file",
91
+ onChange: handleFileChange,
92
+ className: "\n block w-full text-sm text-gray-500 file:mr-4 file:py-2\n file:px-4 file:rounded-full file:border-0 file:text-sm \n file:font-semibold file:bg-gray-100 hover:file:bg-gray-200"
93
+ }
94
+ ),
95
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
96
+ "input",
97
+ {
98
+ ref: inputRef,
99
+ type: "file",
100
+ multiple: true,
101
+ accept: "",
102
+ className: "hidden",
103
+ onChange: handleFileChange
104
+ }
105
+ ),
106
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_dialog.DialogFooter, { className: "pt-4", children: [
107
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.DialogClose, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_button.Button, { variant: "outline", children: "Cancel" }) }),
108
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_button.Button, { onClick: handleSubmit, children: "Submit" })
109
+ ] })
110
+ ]
111
+ }
112
+ ) });
113
+ }
@@ -0,0 +1,12 @@
1
+ import type { FormSchema } from "./form-schema";
2
+ export declare function showUserFormDialog({ formSchema, title }: {
3
+ formSchema: FormSchema;
4
+ title?: string;
5
+ }): Promise<Record<string, any> | null>;
6
+ export declare function FormDialog({ title, formSchema, onSubmit, onDismiss, onCleanup }: {
7
+ title?: string;
8
+ formSchema: FormSchema;
9
+ onSubmit: (data: Record<string, any>) => void;
10
+ onDismiss: () => void;
11
+ onCleanup: () => void;
12
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var form_dialog_exports = {};
20
+ __export(form_dialog_exports, {
21
+ FormDialog: () => FormDialog,
22
+ showUserFormDialog: () => showUserFormDialog
23
+ });
24
+ module.exports = __toCommonJS(form_dialog_exports);
25
+ var import_jsx_runtime = require("react/jsx-runtime");
26
+ var import_react = require("react");
27
+ var import_client = require("react-dom/client");
28
+ var import_react_hook_form = require("react-hook-form");
29
+ var import_dialog = require("@/components/ui/dialog");
30
+ var import_button = require("@/components/ui/button");
31
+ var import_form = require("./form");
32
+ function showUserFormDialog({ formSchema, title }) {
33
+ return new Promise((resolve) => {
34
+ const container = document.createElement("div");
35
+ document.body.appendChild(container);
36
+ const root = (0, import_client.createRoot)(container);
37
+ const onCleanup = () => {
38
+ root.unmount();
39
+ container.remove();
40
+ };
41
+ const onDismiss = () => resolve(null);
42
+ root.render(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
43
+ FormDialog,
44
+ {
45
+ title,
46
+ formSchema,
47
+ onSubmit: resolve,
48
+ onDismiss,
49
+ onCleanup
50
+ }
51
+ ));
52
+ });
53
+ }
54
+ function FormDialog({ title, formSchema, onSubmit, onDismiss, onCleanup }) {
55
+ const [open, setOpen] = (0, import_react.useState)(true);
56
+ const form = (0, import_react_hook_form.useForm)({
57
+ resolver: async (values) => ({ values, errors: {} }),
58
+ mode: "onChange",
59
+ defaultValues: {}
60
+ });
61
+ const handleSubmit = (0, import_react.useCallback)((e) => {
62
+ e.preventDefault();
63
+ onSubmit(form.getValues());
64
+ }, [onSubmit]);
65
+ const onOpenChange = (0, import_react.useCallback)((isOpen) => {
66
+ onDismiss();
67
+ setOpen(isOpen);
68
+ }, [onDismiss]);
69
+ const onAnimationEnd = (0, import_react.useCallback)(() => {
70
+ if (!open) {
71
+ onCleanup();
72
+ }
73
+ }, [open, onCleanup]);
74
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.Dialog, { open, onOpenChange, modal: true, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
75
+ import_dialog.DialogContent,
76
+ {
77
+ className: "sm:max-w-[425px]\n fixed top-1/2 left-1/2 w-[90vw] max-w-md max-h-[90vh]\n transform -translate-x-1/2 -translate-y-1/2\n bg-white rounded shadow-lg p-6 overflow-y-auto",
78
+ showCloseButton: true,
79
+ onAnimationEnd,
80
+ children: [
81
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.DialogHeader, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.DialogTitle, { children: title }) }),
82
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("form", { onSubmit: handleSubmit, className: "grid gap-4 py-4", children: [
83
+ formSchema.map((fieldItem, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_form.FormField, { fieldItem, control: form.control }, index)),
84
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_dialog.DialogFooter, { className: "pt-4", children: [
85
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dialog.DialogClose, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_button.Button, { variant: "outline", children: "Cancel" }) }),
86
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_button.Button, { type: "submit", children: "Submit" })
87
+ ] })
88
+ ] })
89
+ ]
90
+ }
91
+ ) });
92
+ }
@@ -0,0 +1,41 @@
1
+ export interface BaseField<T> {
2
+ name: string;
3
+ description: string;
4
+ default_value: T;
5
+ }
6
+ export interface InputField extends BaseField<string> {
7
+ multiline: boolean;
8
+ }
9
+ export interface SelectOption {
10
+ name: string;
11
+ value: string;
12
+ }
13
+ export interface SelectField extends BaseField<string> {
14
+ options: SelectOption[];
15
+ }
16
+ export interface RadioOption {
17
+ name: string;
18
+ value: string;
19
+ }
20
+ export interface RadioGroupField extends BaseField<string> {
21
+ options: RadioOption[];
22
+ }
23
+ export interface CheckboxField extends BaseField<boolean> {
24
+ }
25
+ export type FormField = InputField | SelectField | RadioGroupField | CheckboxField;
26
+ export interface InputFieldItem {
27
+ input: InputField;
28
+ }
29
+ export interface SelectFieldItem {
30
+ select: SelectField;
31
+ }
32
+ export interface RadioGroupFieldItem {
33
+ radio_group: RadioGroupField;
34
+ }
35
+ export interface CheckboxFieldItem {
36
+ checkbox: CheckboxField;
37
+ }
38
+ export type FormFieldItem = InputFieldItem | SelectFieldItem | RadioGroupFieldItem | CheckboxFieldItem;
39
+ export type FormSchema = FormFieldItem[];
40
+ export declare function getFormFieldType(fieldItem: FormFieldItem): String;
41
+ export declare function getFormField(fieldItem: FormFieldItem): FormField;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var form_schema_exports = {};
20
+ __export(form_schema_exports, {
21
+ getFormField: () => getFormField,
22
+ getFormFieldType: () => getFormFieldType
23
+ });
24
+ module.exports = __toCommonJS(form_schema_exports);
25
+ function getFormFieldType(fieldItem) {
26
+ if ("input" in fieldItem) {
27
+ return "input";
28
+ } else if ("select" in fieldItem) {
29
+ return "select";
30
+ } else if ("radio_group" in fieldItem) {
31
+ return "radio_group";
32
+ } else if ("checkbox" in fieldItem) {
33
+ return "checkbox";
34
+ }
35
+ throw new Error("Unknown form field type");
36
+ }
37
+ function getFormField(fieldItem) {
38
+ if ("input" in fieldItem) {
39
+ return fieldItem.input;
40
+ }
41
+ if ("select" in fieldItem) {
42
+ return fieldItem.select;
43
+ }
44
+ if ("radio_group" in fieldItem) {
45
+ return fieldItem.radio_group;
46
+ }
47
+ if ("checkbox" in fieldItem) {
48
+ return fieldItem.checkbox;
49
+ }
50
+ throw new Error("Unknown form field type");
51
+ }
@@ -0,0 +1,16 @@
1
+ import React from "react";
2
+ import type { Control } from "react-hook-form";
3
+ import type { FormFieldItem } from "./form-schema";
4
+ export type FieldErrorProperty = {
5
+ errors: string[];
6
+ } | undefined;
7
+ export type FieldErrors = {
8
+ errors: string[];
9
+ properties?: {
10
+ [x: string]: FieldErrorProperty;
11
+ } | undefined;
12
+ };
13
+ export declare function FormField({ fieldItem, control }: {
14
+ fieldItem: FormFieldItem;
15
+ control: Control<any>;
16
+ }): React.ReactElement;