@dust-tt/sparkle 0.4.10 → 0.4.12-rc-1
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.
- package/dist/cjs/index.js +1 -1
- package/dist/esm/components/ButtonGroup.d.ts +19 -2
- package/dist/esm/components/ButtonGroup.d.ts.map +1 -1
- package/dist/esm/components/ButtonGroup.js +26 -20
- package/dist/esm/components/ButtonGroup.js.map +1 -1
- package/dist/esm/components/index.d.ts +1 -1
- package/dist/esm/components/index.d.ts.map +1 -1
- package/dist/esm/components/markdown/Markdown.d.ts.map +1 -1
- package/dist/esm/components/markdown/Markdown.js +6 -3
- package/dist/esm/components/markdown/Markdown.js.map +1 -1
- package/dist/esm/components/markdown/utils.d.ts +10 -0
- package/dist/esm/components/markdown/utils.d.ts.map +1 -1
- package/dist/esm/components/markdown/utils.js +34 -0
- package/dist/esm/components/markdown/utils.js.map +1 -1
- package/dist/esm/stories/ButtonGroup.stories.d.ts +4 -3
- package/dist/esm/stories/ButtonGroup.stories.d.ts.map +1 -1
- package/dist/esm/stories/ButtonGroup.stories.js +130 -41
- package/dist/esm/stories/ButtonGroup.stories.js.map +1 -1
- package/dist/esm/stories/Markdown.stories.d.ts.map +1 -1
- package/dist/esm/stories/Markdown.stories.js +1 -1
- package/dist/esm/stories/Markdown.stories.js.map +1 -1
- package/package.json +1 -1
- package/src/components/ButtonGroup.tsx +90 -31
- package/src/components/index.ts +1 -1
- package/src/components/markdown/Markdown.tsx +9 -3
- package/src/components/markdown/utils.ts +40 -0
- package/src/stories/ButtonGroup.stories.tsx +162 -63
- package/src/stories/Markdown.stories.tsx +21 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ButtonGroup.stories.js","sourceRoot":"","sources":["../../../src/stories/ButtonGroup.stories.tsx"],"names":[],"mappings":";AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EACL,YAAY,EACZ,eAAe,GAEhB,MAAM,4BAA4B,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IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE;yBACpD;wBACD;4BACE,IAAI,EAAE,QAAQ;4BACd,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE;yBACvD;wBACD;4BACE,IAAI,EAAE,UAAU;4BAChB,YAAY,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,eAAe,EAAE;4BACnD,aAAa,EAAE;gCACb,KAAK,EAAE;oCACL,EAAE,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,QAAQ,EAAE;oCACzC,EAAE,KAAK,EAAE,UAAU,EAAE;iCACtB;6BACF;yBACF;qBACF,GACD,CACE,CACF,CACF,CACP,EApGa,CAoGb;CACF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Markdown.stories.d.ts","sourceRoot":"","sources":["../../../src/stories/Markdown.stories.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAQ,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,QAAA,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;CAeuB,CAAC;AAElC,eAAe,IAAI,CAAC;AACpB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"Markdown.stories.d.ts","sourceRoot":"","sources":["../../../src/stories/Markdown.stories.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAQ,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,QAAA,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;CAeuB,CAAC;AAElC,eAAe,IAAI,CAAC;AACpB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC;AAkWnC,eAAO,MAAM,qBAAqB,EAAE,KAInC,CAAC;AA2EF,eAAO,MAAM,iBAAiB,EAAE,KAI/B,CAAC"}
|
|
@@ -17,7 +17,7 @@ var meta = {
|
|
|
17
17
|
},
|
|
18
18
|
};
|
|
19
19
|
export default meta;
|
|
20
|
-
var example = "\n# Level 1 Title\n\n## Level 2 Title\n\n### Level 3 Title\n\n#### Level 4 Title\n\n##### Level 5 Title\n\n###### Level 6 Title\n\nGot it. I won\u2019t escape your Markdown.\n\nIf you intended to render a footnote reference like [^4], you can write it directly without backslashes:\n\n- Footnote reference in text: [^4]\n- Footnote definition at the end:\n [^4]: Your footnote content here\n\nThis is a paragraph with **bold** text and *italic* text. This is `code` block:\n```\nBlock\n```\n\nLorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n\n# Another Level 1 Title\n\nDemo of a list, showcasing our pets of the month:\n- Soupinou\n- Chawarma\n- Chalom\n- Anakine\n- Goose\n\nOrdered list:\n1. Soupinou\n2. Chawarma\n3. Chalom\n\n---\n\n### Demo of a quote below:\n\n> You take the blue pill - the story ends, you wake up in your bed and believe whatever you want to believe. You take the red pill - you stay in Wonderland and I show you how deep the rabbit hole goes.\n\n> You take the blue pill - the story ends, you wake up in your bed and believe whatever you want to believe. You take the red pill - you stay in Wonderland and I show you how deep the rabbit hole goes.\n\nAnother one, a short one:\n> Soupinou fait des miaou miaou.\n\n### Other stuff\n\n~~stuff~~\nlink www.x.com\nfootnote [^1]\n\n* [ ] to do\n* [x] done\n\n### Short Table\n\n| Date | High Temperature (\u00B0C) | Low Temperature (\u00B0C) |\n|-------------|-----------------------|----------------------|\n| October 25 | 19 | 14 |\n| October 26 | 17 | 12 |\n| October 27 | 16 | 10 |\n| October 28 | 16 | 9 |\n| October 29 | 17 | 8 |\n| October 30 | 19 | 8 |\n| October 31 | 19 | 10 |\n\n\n### Table\n\n| Date | High Temperature (\u00B0C) | Low Temperature (\u00B0C) | Weather Condition | Date | High Temperature (\u00B0C) | Low Temperature (\u00B0C) | Weather Condition | Date | High Temperature (\u00B0C) | Low Temperature (\u00B0C) | Weather Condition |\n|-------------|-----------------------|----------------------|-------------------------------|-------------|-----------------------|----------------------|-------------------------------|-------------|-----------------------|----------------------|-------------------------------|\n| October 25 | 19 | 14 | Passing showers, cloudy | October 25 | 19 | 14 | Passing showers, cloudy | October 25 | 19 | 14 | Passing showers, cloudy |\n| October 26 | 17 | 12 | Light showers, overcast | October 25 | 19 | 14 | Passing showers, cloudy | October 25 | 19 | 14 | Passing showers, cloudy |\n| October 27 | 16 | 10 | Overcast | October 25 | 19 | 14 | Passing showers, cloudy | October 25 | 19 | 14 | Passing showers, cloudy |\n| October 28 | 16 | 9 | Increasing cloudiness | October 25 | 19 | 14 | Passing showers, cloudy | October 25 | 19 | 14 | Passing showers, cloudy |\n| October 29 | 17 | 8 | Scattered clouds | October 25 | 19 | 14 | Passing showers, cloudy | October 25 | 19 | 14 | Passing showers, cloudy |\n| October 30 | 19 | 8 | Sunny | October 25 | 19 | 14 | Passing showers, cloudy | October 25 | 19 | 14 | Passing showers, cloudy |\n| October 31 | 19 | 10 | Sunny | October 25 | 19 | 14 | Passing showers, cloudy | October 25 | 19 | 14 | Passing showers, cloudy |\n\n\n\n### Some lateX\n\n$$ \\sigma(z_i) = \\frac{e^{z_{i}}}{\\sum_{j=1}^K e^{z_{j}}} \\ \\ \\ for\\ i=1,2,\\dots,K $$\n\n### This is a CSV:\n\n```csv\nDate,High (\u00B0C),Low (\u00B0C)\nOctober 24,19,12\nOctober 25,20,12\nOctober 26,17,11\nOctober 27,16,10\nOctober 28,17,11\nOctober 29,18,12\nOctober 30,19,11\n```\n\n### Some js code:\n\n```javascript\nimport React from \"react\";\nimport {\n LineChart,\n Line,\n XAxis,\n YAxis,\n CartesianGrid,\n Tooltip,\n Legend,\n ResponsiveContainer,\n} from \"recharts\";\n\nconst data = [\n { date: \"Oct 24\", high: 19, low: 12 },\n { date: \"Oct 25\", high: 20, low: 12 },\n { date: \"Oct 26\", high: 17, low: 11 },\n { date: \"Oct 27\", high: 16, low: 10 },\n { date: \"Oct 28\", high: 17, low: 11 },\n { date: \"Oct 29\", high: 18, low: 12 },\n { date: \"Oct 30\", high: 19, low: 11 },\n];\n\nfunction renderHeader(latitude, longitude) {\n const container = document.getElementById(\"dashboard-container\");\n if (!container) {\n console.error(\"Dashboard container is missing in the DOM.\");\n return;\n }\n let header = document.getElementById(\"dashboard-header\");\n if (!header) {\n console.log(\"Creating new dashboard header.\");\n header = document.createElement(\"div\");\n header.id = \"dashboard-header\";\n container.prepend(header);\n }\n console.log(\"Updating header content.\");\n const currentTime = new Date().toLocaleString(\"en-US\", {\n timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone,\n weekday: \"long\",\n hour: \"2-digit\",\n minute: \"2-digit\",\n second: \"2-digit\",\n });\n header.innerHTML = `\n <div>\n <h2>Local Time</h2>\n <p>${currentTime}</p>\n </div>\n <div>\n <h2>Location</h2>\n <p>Lat: ${latitude.toFixed(2)}, Lon: ${longitude.toFixed(2)}</p>\n </div>\n `;\n}\n```\n\n\n### Some CLI code:\n\n```bash\n# Define variables\nAPI_URL=\"https://api.example.com\"\nLATEST_TAG=\"v1.2.3\"\nUSERNAME=\"user123\"\nENVIRONMENT=\"production\"\n\n# Basic GET with variables\ncurl \"${API_URL}/version/${LATEST_TAG}\"\n\n# POST with JSON payload using variables\ncurl -X POST -H \"Content-Type: application/json\" -d \"{\n \"tag\": \"${LATEST_TAG}\",\n \"environment\": \"${ENVIRONMENT}\",\n \"deployedBy\": \"${USERNAME}\"\n }\" \"${API_URL}/deployments\"\n```\n\n### Some python code:\n\n```python\nimport datetime\nimport pytz\nfrom typing import List, Dict, Union\nimport tkinter as tk\nfrom tkinter import ttk\nimport matplotlib.pyplot as plt\nfrom matplotlib.figure import Figure\nfrom matplotlib.backends.backend_tkagg import FigureCanvasTkAgg\n\n# Data structure similar to the JavaScript example\ndata = [\n {\"date\": \"Oct 24\", \"high\": 19, \"low\": 12},\n {\"date\": \"Oct 25\", \"high\": 20, \"low\": 12},\n {\"date\": \"Oct 26\", \"high\": 17, \"low\": 11},\n {\"date\": \"Oct 27\", \"high\": 16, \"low\": 10},\n {\"date\": \"Oct 28\", \"high\": 17, \"low\": 11},\n {\"date\": \"Oct 29\", \"high\": 18, \"low\": 12},\n {\"date\": \"Oct 30\", \"high\": 19, \"low\": 11},\n]\n\nclass WeatherDashboard:\n def __init__(self, root: tk.Tk):\n self.root = root\n self.root.title(\"Weather Dashboard\")\n\n # Create header frame\n self.header_frame = ttk.Frame(root, padding=\"10\")\n self.header_frame.grid(row=0, column=0, sticky=(tk.W, tk.E))\n\n # Create chart frame\n self.chart_frame = ttk.Frame(root, padding=\"10\")\n self.chart_frame.grid(row=1, column=0, sticky=(tk.W, tk.E, tk.N, tk.S))\n\n def render_header(self, latitude: float, longitude: float) -> None:\n \"\"\"\n Render the dashboard header with time and location information\n \"\"\"\n # Clear existing widgets\n for widget in self.header_frame.winfo_children():\n widget.destroy()\n\n # Get current time in local timezone\n current_time = datetime.datetime.now()\n local_tz = datetime.datetime.now(pytz.timezone('UTC')).astimezone().tzinfo\n formatted_time = current_time.strftime('%A, %I:%M:%S %p')\n\n # Create time section\n time_frame = ttk.LabelFrame(self.header_frame, text=\"Local Time\")\n time_frame.grid(row=0, column=0, padx=5, pady=5, sticky=(tk.W))\n ttk.Label(time_frame, text=formatted_time).grid(row=0, column=0, padx=5, pady=2)\n\n # Create location section\n location_frame = ttk.LabelFrame(self.header_frame, text=\"Location\")\n location_frame.grid(row=0, column=1, padx=5, pady=5, sticky=(tk.W))\n ttk.Label(\n location_frame,\n text=f\"Lat: {latitude:.2f}, Lon: {longitude:.2f}\"\n ).grid(row=0, column=0, padx=5, pady=2)\n\n def create_chart(self) -> None:\n \"\"\"\n Create a line chart using matplotlib\n \"\"\"\n # Create figure and axis\n fig = Figure(figsize=(8, 4))\n ax = fig.add_subplot(111)\n\n # Extract data for plotting\n dates = [d['date'] for d in data]\n highs = [d['high'] for d in data]\n lows = [d['low'] for d in data]\n\n # Plot lines\n ax.plot(dates, highs, marker='o', label='High', color='red')\n ax.plot(dates, lows, marker='o', label='Low', color='blue')\n\n # Customize chart\n ax.grid(True)\n ax.set_xlabel('Date')\n ax.set_ylabel('Temperature')\n ax.legend()\n\n # Rotate x-axis labels for better readability\n plt.setp(ax.get_xticklabels(), rotation=45)\n\n # Create canvas and add to frame\n canvas = FigureCanvasTkAgg(fig, master=self.chart_frame)\n canvas.draw()\n canvas.get_tk_widget().grid(row=0, column=0, sticky=(tk.W, tk.E, tk.N, tk.S))\n\ndef main():\n root = tk.Tk()\n dashboard = WeatherDashboard(root)\n\n # Example coordinates (Paris)\n dashboard.render_header(48.8566, 2.3522)\n dashboard.create_chart()\n\n # Configure grid weights\n root.columnconfigure(0, weight=1)\n root.rowconfigure(1, weight=1)\n\n # Start the application\n root.mainloop()\n\nif __name__ == \"__main__\":\n main()\n\n```\n\n### And some mermaids:\n\n```mermaid\ngraph TD\n A[Christmas] -->|Get money| B(Go shopping)\n B --> C{Let me think}\n B --> G[/Another/]\n C ==>|One| D[Laptop]\n C -->|Two| E[iPhone]\n C -->|Three| F[fa:fa-car Car]\n subgraph section\n C\n D\n E\n F\n G\n end\n```\n\n```mermaid pie chart\npie title Distribution\n \"Category A\" : 30\n \"Category B\" : 20\n \"Category C\" : 15\n \"Category D\" : 10\n \"Category E\" : 25\n```\n\n";
|
|
20
|
+
var example = "\n# Level 1 Title\n\n## Level 2 Title\n\n### Level 3 Title\n\n#### Level 4 Title\n\n##### Level 5 Title\n\n###### Level 6 Title\n\nGot it. I won\u2019t escape your Markdown.\n\nIf you intended to render a footnote reference like [^4], you can write it directly without backslashes:\n\n- Footnote reference in text: [^4]\n- Footnote definition at the end:\n [^4]: Your footnote content here\n\nThis is a paragraph with **bold** text and *italic* text. This is `code` block:\n```\nBlock\n```\n\nLorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n\n# Another Level 1 Title\n\nDemo of a list, showcasing our pets of the month:\n- Soupinou\n- Chawarma\n- Chalom\n- Anakine\n- Goose\n\nOrdered list:\n1. Soupinou\n2. Chawarma\n3. Chalom\n\n---\n\n### Demo of a quote below:\n\n> You take the blue pill - the story ends, you wake up in your bed and believe whatever you want to believe. You take the red pill - you stay in Wonderland and I show you how deep the rabbit hole goes.\n\n> You take the blue pill - the story ends, you wake up in your bed and believe whatever you want to believe. You take the red pill - you stay in Wonderland and I show you how deep the rabbit hole goes.\n\nAnother one, a short one:\n> Soupinou fait des miaou miaou.\n\n### Other stuff\n\n~~stuff~~\nlink www.x.com\nfootnote [^1]\n\n* [ ] to do\n* [x] done\n\n### Short Table\n\n| Date | High Temperature (\u00B0C) | Low Temperature (\u00B0C) |\n|-------------|-----------------------|----------------------|\n| October 25 | 19 | 14 |\n| October 26 | 17 | 12 |\n| October 27 | 16 | 10 |\n| October 28 | 16 | 9 |\n| October 29 | 17 | 8 |\n| October 30 | 19 | 8 |\n| October 31 | 19 | 10 |\n\n\n### Table\n\n| Date | High Temperature (\u00B0C) | Low Temperature (\u00B0C) | Weather Condition | Date | High Temperature (\u00B0C) | Low Temperature (\u00B0C) | Weather Condition | Date | High Temperature (\u00B0C) | Low Temperature (\u00B0C) | Weather Condition |\n|-------------|-----------------------|----------------------|-------------------------------|-------------|-----------------------|----------------------|-------------------------------|-------------|-----------------------|----------------------|-------------------------------|\n| October 25 | 19 | 14 | Passing showers, cloudy | October 25 | 19 | 14 | Passing showers, cloudy | October 25 | 19 | 14 | Passing showers, cloudy |\n| October 26 | 17 | 12 | Light showers, overcast | October 25 | 19 | 14 | Passing showers, cloudy | October 25 | 19 | 14 | Passing showers, cloudy |\n| October 27 | 16 | 10 | Overcast | October 25 | 19 | 14 | Passing showers, cloudy | October 25 | 19 | 14 | Passing showers, cloudy |\n| October 28 | 16 | 9 | Increasing cloudiness | October 25 | 19 | 14 | Passing showers, cloudy | October 25 | 19 | 14 | Passing showers, cloudy |\n| October 29 | 17 | 8 | Scattered clouds | October 25 | 19 | 14 | Passing showers, cloudy | October 25 | 19 | 14 | Passing showers, cloudy |\n| October 30 | 19 | 8 | Sunny | October 25 | 19 | 14 | Passing showers, cloudy | October 25 | 19 | 14 | Passing showers, cloudy |\n| October 31 | 19 | 10 | Sunny | October 25 | 19 | 14 | Passing showers, cloudy | October 25 | 19 | 14 | Passing showers, cloudy |\n\n\n\n### Some LaTeX\n\n$$ \\sigma(z_i) = \\frac{e^{z_{i}}}{\\sum_{j=1}^K e^{z_{j}}} \\ \\ \\ for\\ i=1,2,\\dots,K $$\n\n### Some inline LaTeX\n\n**Example**: Linear attention is a 2-level optimization:\n- Inner level: Memory matrix $\\mathcal{M}_t = \\mathcal{M}_{t-1} + \\mathbf{v}_t \\mathbf{k}_t^\\top$ (updates every token)\n- Outer level: Projection matrices $W_k, W_v, W_q$ (updates during pre-training)\n\nEven **optimizers** are associative memories. Momentum with gradient descent is 2-level:\n- Momentum $\\mathbf{m}_t$ compresses past gradients\n- Weights $W_t$ are updated by momentum\n\nThe result is $a=2+t$\n\n### Some text with dollars signs:\n\nOne want to import $USER_WORKSPACE but it will cost them $3.5 or $100 $1000\n\n-> The EF for this code is 0.49059 kgCO2e per $ (2018 USD).\n-> This code is 0.54895 kgCO2e per $ (2018 USD) more.\n-> This thing is $5-$10 range.\n\n### This is a CSV:\n\n```csv\nDate,High (\u00B0C),Low (\u00B0C)\nOctober 24,19,12\nOctober 25,20,12\nOctober 26,17,11\nOctober 27,16,10\nOctober 28,17,11\nOctober 29,18,12\nOctober 30,19,11\n```\n\n### Some js code:\n\n```javascript\nimport React from \"react\";\nimport {\n LineChart,\n Line,\n XAxis,\n YAxis,\n CartesianGrid,\n Tooltip,\n Legend,\n ResponsiveContainer,\n} from \"recharts\";\n\nconst data = [\n { date: \"Oct 24\", high: 19, low: 12 },\n { date: \"Oct 25\", high: 20, low: 12 },\n { date: \"Oct 26\", high: 17, low: 11 },\n { date: \"Oct 27\", high: 16, low: 10 },\n { date: \"Oct 28\", high: 17, low: 11 },\n { date: \"Oct 29\", high: 18, low: 12 },\n { date: \"Oct 30\", high: 19, low: 11 },\n];\n\nfunction renderHeader(latitude, longitude) {\n const container = document.getElementById(\"dashboard-container\");\n if (!container) {\n console.error(\"Dashboard container is missing in the DOM.\");\n return;\n }\n let header = document.getElementById(\"dashboard-header\");\n if (!header) {\n console.log(\"Creating new dashboard header.\");\n header = document.createElement(\"div\");\n header.id = \"dashboard-header\";\n container.prepend(header);\n }\n console.log(\"Updating header content.\");\n const currentTime = new Date().toLocaleString(\"en-US\", {\n timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone,\n weekday: \"long\",\n hour: \"2-digit\",\n minute: \"2-digit\",\n second: \"2-digit\",\n });\n header.innerHTML = `\n <div>\n <h2>Local Time</h2>\n <p>${currentTime}</p>\n </div>\n <div>\n <h2>Location</h2>\n <p>Lat: ${latitude.toFixed(2)}, Lon: ${longitude.toFixed(2)}</p>\n </div>\n `;\n}\n```\n\n\n### Some CLI code:\n\n```bash\n# Define variables\nAPI_URL=\"https://api.example.com\"\nLATEST_TAG=\"v1.2.3\"\nUSERNAME=\"user123\"\nENVIRONMENT=\"production\"\n\n# Basic GET with variables\ncurl \"${API_URL}/version/${LATEST_TAG}\"\n\n# POST with JSON payload using variables\ncurl -X POST -H \"Content-Type: application/json\" -d \"{\n \"tag\": \"${LATEST_TAG}\",\n \"environment\": \"${ENVIRONMENT}\",\n \"deployedBy\": \"${USERNAME}\"\n }\" \"${API_URL}/deployments\"\n```\n\n### Some python code:\n\n```python\nimport datetime\nimport pytz\nfrom typing import List, Dict, Union\nimport tkinter as tk\nfrom tkinter import ttk\nimport matplotlib.pyplot as plt\nfrom matplotlib.figure import Figure\nfrom matplotlib.backends.backend_tkagg import FigureCanvasTkAgg\n\n# Data structure similar to the JavaScript example\ndata = [\n {\"date\": \"Oct 24\", \"high\": 19, \"low\": 12},\n {\"date\": \"Oct 25\", \"high\": 20, \"low\": 12},\n {\"date\": \"Oct 26\", \"high\": 17, \"low\": 11},\n {\"date\": \"Oct 27\", \"high\": 16, \"low\": 10},\n {\"date\": \"Oct 28\", \"high\": 17, \"low\": 11},\n {\"date\": \"Oct 29\", \"high\": 18, \"low\": 12},\n {\"date\": \"Oct 30\", \"high\": 19, \"low\": 11},\n]\n\nclass WeatherDashboard:\n def __init__(self, root: tk.Tk):\n self.root = root\n self.root.title(\"Weather Dashboard\")\n\n # Create header frame\n self.header_frame = ttk.Frame(root, padding=\"10\")\n self.header_frame.grid(row=0, column=0, sticky=(tk.W, tk.E))\n\n # Create chart frame\n self.chart_frame = ttk.Frame(root, padding=\"10\")\n self.chart_frame.grid(row=1, column=0, sticky=(tk.W, tk.E, tk.N, tk.S))\n\n def render_header(self, latitude: float, longitude: float) -> None:\n \"\"\"\n Render the dashboard header with time and location information\n \"\"\"\n # Clear existing widgets\n for widget in self.header_frame.winfo_children():\n widget.destroy()\n\n # Get current time in local timezone\n current_time = datetime.datetime.now()\n local_tz = datetime.datetime.now(pytz.timezone('UTC')).astimezone().tzinfo\n formatted_time = current_time.strftime('%A, %I:%M:%S %p')\n\n # Create time section\n time_frame = ttk.LabelFrame(self.header_frame, text=\"Local Time\")\n time_frame.grid(row=0, column=0, padx=5, pady=5, sticky=(tk.W))\n ttk.Label(time_frame, text=formatted_time).grid(row=0, column=0, padx=5, pady=2)\n\n # Create location section\n location_frame = ttk.LabelFrame(self.header_frame, text=\"Location\")\n location_frame.grid(row=0, column=1, padx=5, pady=5, sticky=(tk.W))\n ttk.Label(\n location_frame,\n text=f\"Lat: {latitude:.2f}, Lon: {longitude:.2f}\"\n ).grid(row=0, column=0, padx=5, pady=2)\n\n def create_chart(self) -> None:\n \"\"\"\n Create a line chart using matplotlib\n \"\"\"\n # Create figure and axis\n fig = Figure(figsize=(8, 4))\n ax = fig.add_subplot(111)\n\n # Extract data for plotting\n dates = [d['date'] for d in data]\n highs = [d['high'] for d in data]\n lows = [d['low'] for d in data]\n\n # Plot lines\n ax.plot(dates, highs, marker='o', label='High', color='red')\n ax.plot(dates, lows, marker='o', label='Low', color='blue')\n\n # Customize chart\n ax.grid(True)\n ax.set_xlabel('Date')\n ax.set_ylabel('Temperature')\n ax.legend()\n\n # Rotate x-axis labels for better readability\n plt.setp(ax.get_xticklabels(), rotation=45)\n\n # Create canvas and add to frame\n canvas = FigureCanvasTkAgg(fig, master=self.chart_frame)\n canvas.draw()\n canvas.get_tk_widget().grid(row=0, column=0, sticky=(tk.W, tk.E, tk.N, tk.S))\n\ndef main():\n root = tk.Tk()\n dashboard = WeatherDashboard(root)\n\n # Example coordinates (Paris)\n dashboard.render_header(48.8566, 2.3522)\n dashboard.create_chart()\n\n # Configure grid weights\n root.columnconfigure(0, weight=1)\n root.rowconfigure(1, weight=1)\n\n # Start the application\n root.mainloop()\n\nif __name__ == \"__main__\":\n main()\n\n```\n\n### And some mermaids:\n\n```mermaid\ngraph TD\n A[Christmas] -->|Get money| B(Go shopping)\n B --> C{Let me think}\n B --> G[/Another/]\n C ==>|One| D[Laptop]\n C -->|Two| E[iPhone]\n C -->|Three| F[fa:fa-car Car]\n subgraph section\n C\n D\n E\n F\n G\n end\n```\n\n```mermaid pie chart\npie title Distribution\n \"Category A\" : 30\n \"Category B\" : 20\n \"Category C\" : 15\n \"Category D\" : 10\n \"Category E\" : 25\n```\n\n";
|
|
21
21
|
export var ExtendedMarkdownStory = {
|
|
22
22
|
args: {
|
|
23
23
|
content: example,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Markdown.stories.js","sourceRoot":"","sources":["../../../src/stories/Markdown.stories.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,IAAM,IAAI,GAAG;IACX,KAAK,EAAE,qBAAqB;IAC5B,SAAS,EAAE,QAAQ;IACnB,IAAI,EAAE,CAAC,UAAU,CAAC;IAClB,UAAU,EAAE,CAAC,UAAC,KAAK,IAAK,OAAA,oBAAC,KAAK,OAAG,EAAT,CAAS,CAAC;IAClC,QAAQ,EAAE;QACR,SAAS,EAAE;YACT,OAAO,EAAE;gBACP,mBAAmB;gBACnB,yBAAyB;gBACzB,kBAAkB;aACnB;YACD,OAAO,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;SAC3B;KACF;CAC8B,CAAC;AAElC,eAAe,IAAI,CAAC;AAGpB,IAAM,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"Markdown.stories.js","sourceRoot":"","sources":["../../../src/stories/Markdown.stories.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,IAAM,IAAI,GAAG;IACX,KAAK,EAAE,qBAAqB;IAC5B,SAAS,EAAE,QAAQ;IACnB,IAAI,EAAE,CAAC,UAAU,CAAC;IAClB,UAAU,EAAE,CAAC,UAAC,KAAK,IAAK,OAAA,oBAAC,KAAK,OAAG,EAAT,CAAS,CAAC;IAClC,QAAQ,EAAE;QACR,SAAS,EAAE;YACT,OAAO,EAAE;gBACP,mBAAmB;gBACnB,yBAAyB;gBACzB,kBAAkB;aACnB;YACD,OAAO,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;SAC3B;KACF;CAC8B,CAAC;AAElC,eAAe,IAAI,CAAC;AAGpB,IAAM,OAAO,GAAG,gqYA8Vf,CAAC;AAEF,MAAM,CAAC,IAAM,qBAAqB,GAAU;IAC1C,IAAI,EAAE;QACJ,OAAO,EAAE,OAAO;KACjB;CACF,CAAC;AAEF,IAAM,cAAc,GAAG,+9CAuEtB,CAAC;AAEF,MAAM,CAAC,IAAM,iBAAiB,GAAU;IACtC,IAAI,EAAE;QACJ,OAAO,EAAE,cAAc;KACxB;CACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -4,6 +4,30 @@ import * as React from "react";
|
|
|
4
4
|
import { cn } from "@sparkle/lib/utils";
|
|
5
5
|
|
|
6
6
|
import type { ButtonProps, ButtonSizeType, ButtonVariantType } from "./Button";
|
|
7
|
+
import { Button } from "./Button";
|
|
8
|
+
import type { DropdownMenuItemProps } from "./Dropdown";
|
|
9
|
+
import {
|
|
10
|
+
DropdownMenu,
|
|
11
|
+
DropdownMenuContent,
|
|
12
|
+
DropdownMenuItem,
|
|
13
|
+
DropdownMenuTrigger,
|
|
14
|
+
} from "./Dropdown";
|
|
15
|
+
|
|
16
|
+
type ButtonGroupButtonItem = {
|
|
17
|
+
type: "button";
|
|
18
|
+
props: ButtonProps;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
type ButtonGroupDropdownItem = {
|
|
22
|
+
type: "dropdown";
|
|
23
|
+
triggerProps: Omit<ButtonProps, "onClick">;
|
|
24
|
+
dropdownProps: {
|
|
25
|
+
items: DropdownMenuItemProps[];
|
|
26
|
+
align?: "start" | "center" | "end";
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export type ButtonGroupItem = ButtonGroupButtonItem | ButtonGroupDropdownItem;
|
|
7
31
|
|
|
8
32
|
type DisallowedButtonGroupVariant =
|
|
9
33
|
| "ghost"
|
|
@@ -58,13 +82,16 @@ const buttonGroupVariants = cva("s-inline-flex", {
|
|
|
58
82
|
export interface ButtonGroupProps
|
|
59
83
|
extends Omit<React.HTMLAttributes<HTMLDivElement>, "children">,
|
|
60
84
|
VariantProps<typeof buttonGroupVariants> {
|
|
61
|
-
|
|
85
|
+
/**
|
|
86
|
+
* Array of button or dropdown items to render in the group.
|
|
87
|
+
*/
|
|
88
|
+
items: ButtonGroupItem[];
|
|
62
89
|
/**
|
|
63
90
|
* Variant to apply to all buttons in the group.
|
|
64
91
|
*/
|
|
65
92
|
variant?: ButtonGroupVariantType;
|
|
66
93
|
/**
|
|
67
|
-
* Size to apply to all buttons in the group. Mini buttons must opt-in per
|
|
94
|
+
* Size to apply to all buttons in the group. Mini buttons must opt-in per item.
|
|
68
95
|
*/
|
|
69
96
|
size?: Exclude<ButtonSizeType, "mini">;
|
|
70
97
|
/**
|
|
@@ -86,26 +113,19 @@ const ButtonGroup = React.forwardRef<HTMLDivElement, ButtonGroupProps>(
|
|
|
86
113
|
size,
|
|
87
114
|
disabled,
|
|
88
115
|
removeGaps = true,
|
|
89
|
-
|
|
116
|
+
items,
|
|
90
117
|
...props
|
|
91
118
|
},
|
|
92
119
|
ref
|
|
93
120
|
) => {
|
|
94
|
-
const
|
|
95
|
-
children
|
|
96
|
-
) as React.ReactElement<ButtonProps>[];
|
|
121
|
+
const totalItems = items.length;
|
|
97
122
|
|
|
98
|
-
const
|
|
99
|
-
if (!React.isValidElement<ButtonProps>(child)) {
|
|
100
|
-
return child;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const totalChildren = childrenArray.length;
|
|
123
|
+
const renderedItems = items.map((item, index) => {
|
|
104
124
|
const isFirst = index === 0;
|
|
105
|
-
const isLast = index ===
|
|
125
|
+
const isLast = index === totalItems - 1;
|
|
106
126
|
|
|
107
127
|
const borderRadiusClasses = (() => {
|
|
108
|
-
if (!removeGaps ||
|
|
128
|
+
if (!removeGaps || totalItems === 1) {
|
|
109
129
|
return "";
|
|
110
130
|
}
|
|
111
131
|
|
|
@@ -140,22 +160,61 @@ const ButtonGroup = React.forwardRef<HTMLDivElement, ButtonGroupProps>(
|
|
|
140
160
|
return isLast ? "" : "s-border-b-0";
|
|
141
161
|
})();
|
|
142
162
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
163
|
+
if (item.type === "button") {
|
|
164
|
+
const nextVariant = sanitizeVariant(variant ?? item.props.variant);
|
|
165
|
+
const rawSize = size ?? item.props.size;
|
|
166
|
+
const nextSize: Exclude<ButtonSizeType, "mini"> | undefined =
|
|
167
|
+
rawSize === "mini"
|
|
168
|
+
? undefined
|
|
169
|
+
: (rawSize as Exclude<ButtonSizeType, "mini"> | undefined);
|
|
170
|
+
|
|
171
|
+
return (
|
|
172
|
+
<Button
|
|
173
|
+
key={index}
|
|
174
|
+
{...item.props}
|
|
175
|
+
variant={nextVariant}
|
|
176
|
+
size={nextSize}
|
|
177
|
+
disabled={disabled ?? item.props.disabled}
|
|
178
|
+
isRounded={false}
|
|
179
|
+
className={cn(
|
|
180
|
+
item.props.className,
|
|
181
|
+
borderRadiusClasses,
|
|
182
|
+
borderClasses
|
|
183
|
+
)}
|
|
184
|
+
/>
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const nextVariant = sanitizeVariant(variant ?? item.triggerProps.variant);
|
|
189
|
+
const rawSize = size ?? item.triggerProps.size;
|
|
190
|
+
const nextSize: Exclude<ButtonSizeType, "mini"> | undefined =
|
|
191
|
+
rawSize === "mini"
|
|
192
|
+
? undefined
|
|
193
|
+
: (rawSize as Exclude<ButtonSizeType, "mini"> | undefined);
|
|
194
|
+
|
|
195
|
+
return (
|
|
196
|
+
<DropdownMenu key={index}>
|
|
197
|
+
<DropdownMenuTrigger asChild>
|
|
198
|
+
<Button
|
|
199
|
+
{...item.triggerProps}
|
|
200
|
+
variant={nextVariant}
|
|
201
|
+
size={nextSize}
|
|
202
|
+
disabled={disabled ?? item.triggerProps.disabled}
|
|
203
|
+
isRounded={false}
|
|
204
|
+
className={cn(
|
|
205
|
+
item.triggerProps.className,
|
|
206
|
+
borderRadiusClasses,
|
|
207
|
+
borderClasses
|
|
208
|
+
)}
|
|
209
|
+
/>
|
|
210
|
+
</DropdownMenuTrigger>
|
|
211
|
+
<DropdownMenuContent align={item.dropdownProps.align ?? "center"}>
|
|
212
|
+
{item.dropdownProps.items.map((dropdownItem, dropdownIndex) => (
|
|
213
|
+
<DropdownMenuItem key={dropdownIndex} {...dropdownItem} />
|
|
214
|
+
))}
|
|
215
|
+
</DropdownMenuContent>
|
|
216
|
+
</DropdownMenu>
|
|
217
|
+
);
|
|
159
218
|
});
|
|
160
219
|
|
|
161
220
|
return (
|
|
@@ -169,7 +228,7 @@ const ButtonGroup = React.forwardRef<HTMLDivElement, ButtonGroupProps>(
|
|
|
169
228
|
role="group"
|
|
170
229
|
{...props}
|
|
171
230
|
>
|
|
172
|
-
{
|
|
231
|
+
{renderedItems}
|
|
173
232
|
</div>
|
|
174
233
|
);
|
|
175
234
|
}
|
package/src/components/index.ts
CHANGED
|
@@ -17,7 +17,7 @@ export type {
|
|
|
17
17
|
RegularButtonProps,
|
|
18
18
|
} from "./Button";
|
|
19
19
|
export { Button } from "./Button";
|
|
20
|
-
export type { ButtonGroupProps } from "./ButtonGroup";
|
|
20
|
+
export type { ButtonGroupItem, ButtonGroupProps } from "./ButtonGroup";
|
|
21
21
|
export { ButtonGroup } from "./ButtonGroup";
|
|
22
22
|
export { ButtonsSwitch, ButtonsSwitchList } from "./ButtonsSwitch";
|
|
23
23
|
export type { CardProps } from "./Card";
|
|
@@ -24,7 +24,10 @@ import {
|
|
|
24
24
|
TableHeadBlock,
|
|
25
25
|
TableHeaderBlock,
|
|
26
26
|
} from "@sparkle/components/markdown/TableBlock";
|
|
27
|
-
import {
|
|
27
|
+
import {
|
|
28
|
+
preprocessDollarSigns,
|
|
29
|
+
sanitizeContent,
|
|
30
|
+
} from "@sparkle/components/markdown/utils";
|
|
28
31
|
import { cn } from "@sparkle/lib/utils";
|
|
29
32
|
|
|
30
33
|
export const markdownHeaderClasses = {
|
|
@@ -70,7 +73,10 @@ export function Markdown({
|
|
|
70
73
|
additionalMarkdownComponents?: Components;
|
|
71
74
|
additionalMarkdownPlugins?: PluggableList;
|
|
72
75
|
}) {
|
|
73
|
-
const processedContent = useMemo(() =>
|
|
76
|
+
const processedContent = useMemo(() => {
|
|
77
|
+
const sanitized = sanitizeContent(content);
|
|
78
|
+
return preprocessDollarSigns(sanitized);
|
|
79
|
+
}, [content]);
|
|
74
80
|
|
|
75
81
|
// Note on re-renderings. A lot of effort has been put into preventing rerendering across markdown
|
|
76
82
|
// AST parsing rounds (happening at each token being streamed).
|
|
@@ -214,7 +220,7 @@ export function Markdown({
|
|
|
214
220
|
() => [
|
|
215
221
|
remarkDirective,
|
|
216
222
|
remarkGfm,
|
|
217
|
-
[remarkMath, { singleDollarTextMath:
|
|
223
|
+
[remarkMath, { singleDollarTextMath: true }],
|
|
218
224
|
...(additionalMarkdownPlugins || []),
|
|
219
225
|
showUnsupportedDirective,
|
|
220
226
|
],
|
|
@@ -39,3 +39,43 @@ export function detectLanguage(children: React.ReactNode) {
|
|
|
39
39
|
|
|
40
40
|
return "text";
|
|
41
41
|
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Preprocesses content to escape dollar signs that are likely NOT inlione LaTeX math. This helps
|
|
45
|
+
* prevent false positives when enabling single $ math rendering.
|
|
46
|
+
*
|
|
47
|
+
* Patterns that are escaped:
|
|
48
|
+
* 1. Solo dollar signs: `$` (not part of a pair)
|
|
49
|
+
* 1. Currency amounts: $100, $5.99, $1,000, $50k, $2.5M, $1 billion
|
|
50
|
+
* 2. Shell/code variables: $HOME, $PATH, ${variable}
|
|
51
|
+
*/
|
|
52
|
+
export function preprocessDollarSigns(content: string): string {
|
|
53
|
+
let processed = content;
|
|
54
|
+
|
|
55
|
+
processed = processed
|
|
56
|
+
.split("\n")
|
|
57
|
+
.map((line) => {
|
|
58
|
+
const unescapedDollarMatches = line.match(/(?<!\\)\$/g) ?? [];
|
|
59
|
+
// 1. Escape solo dollar signs per line: we ignore math spans crossing newlines.
|
|
60
|
+
if (unescapedDollarMatches.length === 1) {
|
|
61
|
+
return line.replace(/(?<!\\)\$/, "\\$");
|
|
62
|
+
} else if (unescapedDollarMatches.length > 1) {
|
|
63
|
+
// 2. Protect currency patterns
|
|
64
|
+
// Matches: $100, $5.99, $1,000.50, $50k, $2.5M, $1 billion, etc.
|
|
65
|
+
line = line.replace(
|
|
66
|
+
/(?<!\\)\$(\d+(?:,\d{3})*(?:\.\d{1,2})?(?:\s*(?:USD|EUR|CAD|GBP|million|billion|thousand|[kKmMbB]))?)\b/g,
|
|
67
|
+
"\\$$$1"
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
// 3. Protect shell/code variables
|
|
71
|
+
// Matches: $HOME, $PATH, $USER, ${variable}, ${foo.bar}
|
|
72
|
+
line = line.replace(/(?<!\\)\$([A-Z_][A-Z0-9_]*)\b/g, "\\$$$1");
|
|
73
|
+
|
|
74
|
+
line = line.replace(/(?<!\\)\$\{([^}]+)\}/g, "\\${$1}");
|
|
75
|
+
}
|
|
76
|
+
return line;
|
|
77
|
+
})
|
|
78
|
+
.join("\n");
|
|
79
|
+
|
|
80
|
+
return processed;
|
|
81
|
+
}
|