Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: text-to-diagram #7325

Merged
merged 19 commits into from
Nov 25, 2023
Merged

feat: text-to-diagram #7325

merged 19 commits into from
Nov 25, 2023

Conversation

barnabasmolnar
Copy link
Contributor

@barnabasmolnar barnabasmolnar commented Nov 22, 2023

This PR extends what was previously merely the Mermaid dialog with a Text to Diagram tab.

As discussed "offline", we're keeping the API surface really simple & small for now and we only expose very minimal control for host applications.

Given the following code in a host app:

<Excalidraw>
  <TTDDialogTrigger icon={TTDIcon}>
    Text to Diagram
  </TTDDialogTrigger>

  <TTDDialog
    onTextSubmit={async (input) => {
      // some custom host app code resolving to mermaid syntax
      const mermaid = await giveMeMermaid(input);
      return mermaid;
    }}
  />
</Excalidraw>

The more tools toolbar will now feature a Text to Diagram button. Upon clicking said button, a dialog will open. The dialog has a tabbed interface where the user can choose between Text to Diagram and Mermaid. As already mentioned, we're keeping things closed & minimal for now, so tab names, layout, behaviour, etc cannot be customised from host apps. The general idea is that the host app can use the onTextSubmit callback on TTDDialog to get the input from the TTD text area, run some magic on it and spit back something that resolves to mermaid syntax/definition. At this point, clicking on Generate under the left tab will try and convert said mermaid syntax to an excalidraw diagram. Loading states & error handling are included.

And that's about the gist of it.

Some testing notes:
Unfortunately the example app cannot load the mermaid package due to some bug so. I added a debug commit, instead, so that the whole flow can be tested in the editor proper. It's meant to be reverted before merging.

To show off functionality, I have some "fake" example code that will randomly succeed or fail, so just keep clicking Generate if it fails. 😄 Don't use linebreaks in your input, that will fail all the time.

Finally, note that if Generate succeeds, going over to the Mermaid tab, you'll now see the mermaid code that was generated in the previous step.

Copy link

vercel bot commented Nov 22, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
excalidraw ✅ Ready (Inspect) Visit Preview Nov 25, 2023 9:09pm
excalidraw-package-example ✅ Ready (Inspect) Visit Preview Nov 25, 2023 9:09pm
1 Ignored Deployment
Name Status Preview Updated (UTC)
docs ⬜️ Ignored (Inspect) Visit Preview Nov 25, 2023 9:09pm

Copy link

github-actions bot commented Nov 23, 2023

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
dist/excalidraw.production.min.js 324.55 KB (0%) 6.5 s (0%) 60 ms (-12.06% 🔽) 6.6 s
dist/excalidraw-assets/locales 280.73 KB (0%) 5.7 s (0%) 20 ms (+81.49% 🔺) 5.7 s
dist/excalidraw-assets/vendor*.js 826.02 KB (0%) 16.6 s (0%) 123 ms (+1.86% 🔺) 16.7 s

Copy link

github-actions bot commented Nov 24, 2023

Coverage Report

Status Category Percentage Covered / Total
🟢 Lines 72.53% / 70% 45714 / 63026
🟢 Statements 72.53% / 70% 45714 / 63026
🟢 Functions 68.8% / 68% 1447 / 2103
🟢 Branches 81% / 70% 5716 / 7056
File Coverage
File Stmts % Branch % Funcs % Lines Uncovered Lines
Changed Files
excalidraw-app/index.tsx 49.94% 63.15% 34.78% 49.94% 115-124, 169-204, 206-228, 231-262, 265-270, 273-274, 301, 329-330, 332-346, 350-353, 357-368, 371-383, 397-419, 427-481, 485-486, 489-498, 521-531, 574-597, 607-643, 646-656, 663-664, 673-686, 707-726, 766-771, 780-833, 837-839, 842-846, 852-854
src/types.ts 100% 100% 100% 100%
src/utils.ts 77.65% 81.25% 71.83% 77.65% 76-78, 90-91, 119-125, 127-129, 143-153, 160-165, 169-171, 173-175, 180-182, 265-266, 300, 312-314, 320-323, 328-341, 344-351, 354-358, 387, 395, 398, 408-411, 459, 483-488, 496-497, 514-515, 581-597, 600-604, 608-621, 635-637, 639-640, 643-644, 647-655, 658-661, 695-701, 741-742, 754-755, 769, 792-798, 827-840, 891-892, 899-906, 915-925, 930-931
src/components/Actions.tsx 93.22% 92.3% 33.33% 93.22% 173-177, 249-250, 272-275, 281-284, 364-369, 434-442
src/components/App.tsx 69.36% 75.99% 67.97% 69.36% 441-442, 612-613, 629-630, 650-710, 713-719, 722-725, 728-804, 807-826, 834-845, 847-848, 853-854, 858-860, 879-1124, 1184-1185, 1196-1197, 1224-1229, 1239-1283, 1309, 1319, 1326-1329, 1364-1365, 1445-1451, 1456-1470, 1474-1520, 1612-1617, 1620-1650, 1658-1683, 1686-1695, 1698-1807, 1810-1818, 1827-1840, 1843-1869, 1872-1939, 1942-1982, 2028-2029, 2047-2048, 2085-2086, 2090-2091, 2107-2114, 2119-2132, 2138-2139, 2144-2152, 2154-2162, 2174, 2214-2215, 2237-2238, 2245, 2306-2308, 2311-2316, 2321-2322, 2357-2365, 2427-2436, 2459-2461, 2523-2524, 2537-2540, 2543, 2545-2546, 2553-2554, 2560-2561, 2569-2570, 2573-2574, 2577-2580, 2583-2586, 2597-2605, 2610-2611, 2667-2668, 2682-2688, 2694-2702, 2706-2714, 2718-2719, 2722-2759, 2762-2774, 2785-2786, 2797-2798, 2816-2820, 2824-2827, 2834-2836, 2854-2861, 2864, 2866-2871, 2875-2877, 2893-2894, 2896-2905, 2931, 2937, 2976-2977, 2994-2996, 3018-3019, 3025-3028, 3034-3109, 3181-3182, 3187-3190, 3253, 3263-3281, 3284-3290, 3293-3294, 3300-3313, 3399-3400, 3402-3403, 3408-3410, 3435-3449, 3454-3473, 3496-3497, 3530-3532, 3557, 3576-3580, 3591-3592, 3595-3599, 3601-3602, 3604-3607, 3632-3633, 3642-3644, 3646, 3721-3724, 3746-3748, 3758-3759, 3761-3781, 3784-3790, 3807-3810, 3816-3819, 3829-3836, 3840-3841, 3846, 3874-3878, 3882, 3887-3888, 3893-3897, 3929-3930, 3933-3934, 3942-3946, 3950-3960, 3965-3992, 3997-4008, 4067, 4093-4094, 4185, 4362-4363, 4366-4367, 4375, 4387, 4389-4390, 4431-4435, 4486-4492, 4498-4561, 4603, 4652, 4710, 4758-4761, 4764-4770, 4772-4775, 4790-4799, 4802-4803, 4884-4885, 4888, 4890-4891, 4897-4899, 4901, 4910, 4932-4937, 4939-4942, 4946-4947, 4957-5044, 5047-5048, 5062-5063, 5114-5115, 5142-5143, 5173-5199, 5206-5207, 5230-5231, 5251, 5253-5254, 5270-5271, 5277-5278, 5282-5285, 5288-5289, 5304-5331, 5339-5340, 5344-5347, 5349-5353, 5412-5417, 5419-5421, 5437, 5439-5450, 5475-5478, 5537-5538, 5540-5563, 5578-5579, 5691-5720, 5785-5789, 5812-5813, 5833-5834, 5928, 5934-5935, 5958-5977, 5992, 6125, 6147-6188, 6192-6243, 6258, 6267, 6301-6307, 6322-6324, 6466-6470, 6494-6528, 6564, 6566-6573, 6580-6583, 6596, 6619-6620, 6623-6624, 6629-6631, 6634-6635, 6660-6661, 6689-6690, 6772-6773, 6822-6835, 6895-6898, 6924-6925, 6970, 6988-6994, 7001-7004, 7027-7032, 7103-7106, 7112, 7127-7134, 7137-7144, 7200, 7274-7275, 7295-7297, 7300, 7314-7338, 7444-7463, 7473-7512, 7525-7526, 7535-7542, 7556-7568, 7581-7586, 7638-7666, 7668-7669, 7743-7747, 7754, 7756-7792, 7821, 7871, 7890-7892, 7917-7922, 7924-7925, 7930-7961, 7964-7988, 8002-8003, 8009-8018, 8023, 8027-8031, 8040-8041, 8044-8049, 8053-8060, 8090, 8092-8096, 8098-8108, 8124-8126, 8137-8145, 8149-8185, 8188-8259, 8267, 8285-8292, 8294-8310, 8325-8347, 8366-8368, 8413-8414, 8444-8445, 8461, 8538-8541, 8543-8559, 8561-8565, 8577-8578, 8588-8604, 8638-8639, 8643-8655, 8665, 8667-8670, 8672-8673, 8713, 8734-8735, 8761, 8764, 8804, 8818-8825, 8842-8843, 8875-8878, 8967-8974, 9000-9001, 9042-9096, 9140-9141, 9150-9153, 9158-9159, 9180-9182, 9184-9188, 9226
src/components/Button.tsx 100% 100% 100% 100%
src/components/LayerUI.tsx 84.2% 87.03% 46.42% 84.2% 321, 360-365, 410-455, 458-462, 465-481, 488-496, 539-547, 553-556
src/components/icons.tsx 97.38% 86.66% 100% 97.38% 1155-1167, 1286-1296, 1301-1311, 1316-1326
src/components/TTDDialog/MermaidToExcalidraw.tsx 92.48% 93.33% 83.33% 92.48% 31-33, 112-118
src/components/TTDDialog/TTDDialog.tsx 46.15% 81.81% 33.33% 46.15% 91-94, 100-174, 216-222, 231-319
src/components/TTDDialog/TTDDialogInput.tsx 75% 66.66% 50% 75% 27-39
src/components/TTDDialog/TTDDialogOutput.tsx 100% 100% 100% 100%
src/components/TTDDialog/TTDDialogPanel.tsx 100% 66.66% 50% 100%
src/components/TTDDialog/TTDDialogPanels.tsx 100% 100% 100% 100%
src/components/TTDDialog/TTDDialogTab.tsx 100% 100% 100% 100%
src/components/TTDDialog/TTDDialogTabTrigger.tsx 19.04% 100% 0% 19.04% 4-20
src/components/TTDDialog/TTDDialogTabTriggers.tsx 30.76% 100% 0% 30.76% 4-12
src/components/TTDDialog/TTDDialogTabs.tsx 89.47% 66.66% 100% 89.47% 24-27
src/components/TTDDialog/TTDDialogTrigger.tsx 91.17% 100% 50% 91.17% 23-25
src/components/TTDDialog/common.ts 63.39% 81.81% 50% 63.39% 13-31, 69-71, 117-119, 123-153
src/components/dropdownMenu/DropdownMenuItem.tsx 69.11% 100% 50% 69.11% 43-63
src/context/tunnels.ts 100% 100% 100% 100%
src/packages/excalidraw/index.tsx 78.84% 88.88% 75% 78.84% 81-85, 140-189
Generated in workflow #1147

@dwelle
Copy link
Member

dwelle commented Nov 25, 2023

🔥

@dwelle dwelle enabled auto-merge (squash) November 25, 2023 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants