@ai-matrx/context-menu 0.1.5 → 0.1.7

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.
@@ -144,6 +144,17 @@ function toast(props) {
144
144
  else notify.message(message, options);
145
145
  }
146
146
 
147
+ // src/engine/utils/ensure-block-template.ts
148
+ import { supabase } from "@ai-matrx/chat/host/db";
149
+ import { sklActions } from "@ai-matrx/chat/host/ui-slots";
150
+ async function ensureBlockTemplate(blockId, dispatch) {
151
+ const { data, error } = await supabase.schema("skill").from("render_definition").select("template").eq("id", blockId).single();
152
+ if (error) throw new Error(error.message);
153
+ const template = data?.template ?? "";
154
+ dispatch(sklActions.renderDefinitionsMerged([{ id: blockId, template }]));
155
+ return template;
156
+ }
157
+
147
158
  // src/engine/host/port.ts
148
159
  import { confirm as kitConfirm } from "@ai-matrx/kit/confirm-opener";
149
160
  function unwired(name) {
@@ -1425,12 +1436,25 @@ function useContextMenuActions(props) {
1425
1436
  };
1426
1437
  const insertTargets = { editorId, getTextarea, insertAtCaret, onTextReplace };
1427
1438
  const handleContentBlockInsert = (entry) => {
1428
- const template = entry.template;
1429
- if (insertIntoEditor(insertTargets, template)) {
1430
- onContentInserted?.();
1431
- return;
1432
- }
1433
- void kitCopyText(template).then((copied) => {
1439
+ void (async () => {
1440
+ let template = entry.template;
1441
+ if (!template) {
1442
+ try {
1443
+ template = await ensureBlockTemplate(entry.id, dispatch);
1444
+ } catch (error) {
1445
+ toast({
1446
+ title: "Couldn't load that block",
1447
+ description: error instanceof Error ? error.message : "Try again.",
1448
+ variant: "destructive"
1449
+ });
1450
+ return;
1451
+ }
1452
+ }
1453
+ if (insertIntoEditor(insertTargets, template)) {
1454
+ onContentInserted?.();
1455
+ return;
1456
+ }
1457
+ const copied = await kitCopyText(template);
1434
1458
  if (copied) {
1435
1459
  toast({
1436
1460
  title: "Copied to clipboard",
@@ -1439,7 +1463,7 @@ function useContextMenuActions(props) {
1439
1463
  } else {
1440
1464
  getContextMenuHost().showManualCopy({ text: template });
1441
1465
  }
1442
- });
1466
+ })();
1443
1467
  };
1444
1468
  const handleEntrySelect = (entry) => {
1445
1469
  if (entry.entryType === "agent_shortcut") void handleShortcutExecute(entry);