@matterfact/embed 0.12.0 → 0.15.0

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 (42) hide show
  1. package/README.md +41 -0
  2. package/dist/{chunk-M5TS546Z.js → chunk-C7DXO37G.js} +2 -2
  3. package/dist/{chunk-ZXMJWCQV.js → chunk-JLJG3MDX.js} +57 -35
  4. package/dist/chunk-JLJG3MDX.js.map +1 -0
  5. package/dist/chunk-QZCUQZJK.js +3 -0
  6. package/dist/chunk-QZCUQZJK.js.map +7 -0
  7. package/dist/{chunk-C4XGE6BO.js → chunk-S6OT47DL.js} +56 -34
  8. package/dist/chunk-S6OT47DL.js.map +1 -0
  9. package/dist/{chunk-WAUSVV7Y.js → chunk-UA4Y2O64.js} +2 -2
  10. package/dist/{context-4LP3EDXL.js → context-DAXACLSP.js} +3 -3
  11. package/dist/{context-4LP3EDXL.js.map → context-DAXACLSP.js.map} +1 -1
  12. package/dist/{context-ZSPDZWIB.js → context-IJK345PN.js} +2 -2
  13. package/dist/embed.js +1 -1
  14. package/dist/embed.js.map +3 -3
  15. package/dist/index.cjs +82 -32
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.d.cts +73 -2
  18. package/dist/index.d.ts +73 -2
  19. package/dist/index.js +29 -1
  20. package/dist/index.js.map +1 -1
  21. package/dist/react.cjs +281 -55
  22. package/dist/react.cjs.map +1 -1
  23. package/dist/react.d.cts +168 -12
  24. package/dist/react.d.ts +168 -12
  25. package/dist/react.js +221 -19
  26. package/dist/react.js.map +1 -1
  27. package/dist/{snapshot-OR5SVEUD.js → snapshot-EVBNVVCT.js} +2 -2
  28. package/dist/{snapshot-X6FPP3HF.js → snapshot-P5SVKSPB.js} +3 -3
  29. package/dist/{snapshot-X6FPP3HF.js.map → snapshot-P5SVKSPB.js.map} +1 -1
  30. package/examples/embed-demo/.env.example +9 -0
  31. package/examples/embed-demo/README.md +66 -12
  32. package/examples/embed-demo/src/App.tsx +56 -12
  33. package/examples/embed-demo/src/config.ts +8 -0
  34. package/package.json +1 -1
  35. package/dist/chunk-C4XGE6BO.js.map +0 -1
  36. package/dist/chunk-SR4ZNUAN.js +0 -3
  37. package/dist/chunk-SR4ZNUAN.js.map +0 -7
  38. package/dist/chunk-ZXMJWCQV.js.map +0 -1
  39. /package/dist/{chunk-M5TS546Z.js.map → chunk-C7DXO37G.js.map} +0 -0
  40. /package/dist/{chunk-WAUSVV7Y.js.map → chunk-UA4Y2O64.js.map} +0 -0
  41. /package/dist/{context-ZSPDZWIB.js.map → context-IJK345PN.js.map} +0 -0
  42. /package/dist/{snapshot-OR5SVEUD.js.map → snapshot-EVBNVVCT.js.map} +0 -0
package/dist/index.cjs CHANGED
@@ -466,7 +466,7 @@ function mfTools(win) {
466
466
  if (typeof document2 === "function") {
467
467
  out.push({
468
468
  name: "mf.resolveDocument",
469
- description: 'Resolve a matterfact document (dossier, report, briefing) that is NOT on the current page to a concrete id. Call it with the document type and a key (e.g. a ticker) when the site map shows the document lives on another route. Returns {id, label, href}. Cite the result inline as <MFRef kind="document" id="<id>" label="<label>" /> \u2014 it renders as a chip that opens the document in the side panel; href is its "open on page" deeplink.',
469
+ description: `Resolve a matterfact document (dossier, report, briefing) that is NOT on the current page to a concrete id. Call it with the document type and the subject's key, when the site map shows the document lives on another route. For the key, use the current route parameter VERBATIM when the page context states one (e.g. ticker = BP~+LN+Equity \u2192 key "BP~+LN+Equity"): it is the host's own identifier and often differs from the ticker or name a person would write. Do not normalise, decode or re-spell it, and do not substitute what the user typed. Returns {id, label, href}. Cite the result inline as <MFRef kind="document" id="<id>" label="<label>" /> \u2014 it renders as a chip that opens the document in the side panel; href is its "open on page" deeplink.`,
470
470
  inputSchema: {
471
471
  type: "object",
472
472
  properties: {
@@ -1171,6 +1171,7 @@ async function resolveDeclaredContext() {
1171
1171
  async function publishContext() {
1172
1172
  if (!pageContextOn()) return;
1173
1173
  const declared = await resolveDeclaredContext();
1174
+ if (!pageContextOn()) return;
1174
1175
  send?.({ type: "host.context", context: buildPageContext(declared) });
1175
1176
  }
1176
1177
  function provideContext() {
@@ -1248,6 +1249,7 @@ function navigateHost(href) {
1248
1249
  location.assign(target.href);
1249
1250
  }
1250
1251
  function pushActivity(e) {
1252
+ if (!allowsAuto(effectivePageContextMode())) return;
1251
1253
  activity.push({ ...e, seq: ++activitySeq, ts: Date.now() });
1252
1254
  if (activity.length > MAX_ACTIVITY) activity.shift();
1253
1255
  send?.({ type: "host.activity", events: [activity[activity.length - 1]] });
@@ -1312,6 +1314,7 @@ function watchNavigation() {
1312
1314
  publishSitemap();
1313
1315
  publishTools();
1314
1316
  };
1317
+ if (navFire) return;
1315
1318
  navFire = fire;
1316
1319
  for (const name of ["pushState", "replaceState"]) {
1317
1320
  const orig = history[name];
@@ -1381,6 +1384,7 @@ async function sendSnapshot(emit) {
1381
1384
  return;
1382
1385
  }
1383
1386
  const { snapshot: snapshot2 } = await loadSnapshotModule();
1387
+ if (!allowsAuto(effectivePageContextMode())) return;
1384
1388
  const { yaml, truncated, visibleRefs } = snapshot2();
1385
1389
  emit({
1386
1390
  type: "host.snapshot",
@@ -1392,6 +1396,7 @@ async function sendSnapshot(emit) {
1392
1396
  async function sendRegion(ref, emit) {
1393
1397
  if (!allowsAuto(effectivePageContextMode())) return;
1394
1398
  const { snapshotRegion: snapshotRegion2, resolveRef: resolveRef2 } = await loadSnapshotModule();
1399
+ if (!allowsAuto(effectivePageContextMode())) return;
1395
1400
  const el = resolveRef2(ref);
1396
1401
  if (!el) {
1397
1402
  emit({
@@ -1431,13 +1436,39 @@ async function callTool(call, emit) {
1431
1436
  error: r.error
1432
1437
  });
1433
1438
  }
1434
- function stop() {
1439
+ function installAutoObservers() {
1440
+ document.addEventListener("click", onClick, { capture: true, passive: true });
1441
+ document.addEventListener("submit", onSubmit, {
1442
+ capture: true,
1443
+ passive: true
1444
+ });
1445
+ document.addEventListener("change", onChange, {
1446
+ capture: true,
1447
+ passive: true
1448
+ });
1449
+ document.addEventListener("selectionchange", scheduleFocus, { passive: true });
1450
+ document.addEventListener("focusin", scheduleFocus, {
1451
+ capture: true,
1452
+ passive: true
1453
+ });
1454
+ window.addEventListener("scroll", scheduleFocus, {
1455
+ capture: true,
1456
+ passive: true
1457
+ });
1458
+ }
1459
+ function removeAutoObservers() {
1435
1460
  document.removeEventListener("click", onClick, { capture: true });
1436
1461
  document.removeEventListener("submit", onSubmit, { capture: true });
1437
1462
  document.removeEventListener("change", onChange, { capture: true });
1438
1463
  document.removeEventListener("selectionchange", scheduleFocus);
1439
1464
  document.removeEventListener("focusin", scheduleFocus, { capture: true });
1440
1465
  window.removeEventListener("scroll", scheduleFocus, { capture: true });
1466
+ if (focusTimer) {
1467
+ clearTimeout(focusTimer);
1468
+ focusTimer = null;
1469
+ }
1470
+ }
1471
+ function unwatchNavigation() {
1441
1472
  if (navFire) {
1442
1473
  window.removeEventListener("popstate", navFire);
1443
1474
  navFire = null;
@@ -1450,10 +1481,10 @@ function stop() {
1450
1481
  history.replaceState = origReplaceState;
1451
1482
  origReplaceState = null;
1452
1483
  }
1453
- if (focusTimer) {
1454
- clearTimeout(focusTimer);
1455
- focusTimer = null;
1456
- }
1484
+ }
1485
+ function stop() {
1486
+ removeAutoObservers();
1487
+ unwatchNavigation();
1457
1488
  send = null;
1458
1489
  contextProvider = void 0;
1459
1490
  activity.length = 0;
@@ -1463,6 +1494,22 @@ function stop() {
1463
1494
  }
1464
1495
  function setPageContextMax(max) {
1465
1496
  adminPageContextMax = parsePageContextMode(max);
1497
+ applyObservation();
1498
+ }
1499
+ function applyObservation() {
1500
+ const mode = effectivePageContextMode();
1501
+ if (allowsAuto(mode)) {
1502
+ installAutoObservers();
1503
+ } else {
1504
+ removeAutoObservers();
1505
+ activity.length = 0;
1506
+ lastFocus = {};
1507
+ }
1508
+ if (allowsDeclared(mode)) {
1509
+ watchNavigation();
1510
+ } else {
1511
+ unwatchNavigation();
1512
+ }
1466
1513
  }
1467
1514
  function start(emit, origin, pageContext = true, provider) {
1468
1515
  stop();
@@ -1475,33 +1522,8 @@ function start(emit, origin, pageContext = true, provider) {
1475
1522
  void publishContext();
1476
1523
  publishArtifactGrants();
1477
1524
  publishSitemap();
1478
- watchNavigation();
1479
- if (allowsAuto(effectivePageContextMode())) {
1480
- document.addEventListener("click", onClick, {
1481
- capture: true,
1482
- passive: true
1483
- });
1484
- document.addEventListener("submit", onSubmit, {
1485
- capture: true,
1486
- passive: true
1487
- });
1488
- document.addEventListener("change", onChange, {
1489
- capture: true,
1490
- passive: true
1491
- });
1492
- document.addEventListener("selectionchange", scheduleFocus, {
1493
- passive: true
1494
- });
1495
- document.addEventListener("focusin", scheduleFocus, {
1496
- capture: true,
1497
- passive: true
1498
- });
1499
- window.addEventListener("scroll", scheduleFocus, {
1500
- capture: true,
1501
- passive: true
1502
- });
1503
- }
1504
1525
  }
1526
+ applyObservation();
1505
1527
  const theme = matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
1506
1528
  emit({ type: "host.theme", mode: theme });
1507
1529
  {
@@ -2207,6 +2229,13 @@ var EmbedHost = class {
2207
2229
  case "widget.chat":
2208
2230
  this.emit({ type: "chat", phase: msg.phase, chatId: msg.chatId });
2209
2231
  break;
2232
+ case "widget.artifactParams":
2233
+ this.emit({
2234
+ type: "artifactParams",
2235
+ params: msg.params,
2236
+ source: msg.source
2237
+ });
2238
+ break;
2210
2239
  }
2211
2240
  }
2212
2241
  /**
@@ -2352,6 +2381,23 @@ var EmbedHost = class {
2352
2381
  this.queue = [];
2353
2382
  for (const m of pending) this.send(m);
2354
2383
  }
2384
+ /**
2385
+ * Push artifact param values into the widget — a PARTIAL patch; only the named
2386
+ * params change. Buffered like every other host→widget message until the widget
2387
+ * says it's listening.
2388
+ *
2389
+ * Explicit and deliberate, so it applies even to a param whose page-context binding
2390
+ * the viewer has overridden (spec §7.3).
2391
+ */
2392
+ setArtifactParams(params) {
2393
+ if (params == null || typeof params !== "object" || Array.isArray(params)) {
2394
+ console.error(
2395
+ "[matterfact] setArtifactParams expects an object of param values"
2396
+ );
2397
+ return;
2398
+ }
2399
+ this.send({ type: "host.artifactParams", params });
2400
+ }
2355
2401
  /** Tear down: stop listening and remove the host element. For the React wrapper's
2356
2402
  * unmount — the vanilla `<script>` loader lives for the page's lifetime and never
2357
2403
  * calls this. */
@@ -2369,6 +2415,10 @@ var EmbedHost = class {
2369
2415
  function mount(config) {
2370
2416
  const host = new EmbedHost(config);
2371
2417
  host.mount();
2418
+ window.matterfact = {
2419
+ ...window.matterfact ?? {},
2420
+ setArtifactParams: (params) => host.setArtifactParams(params)
2421
+ };
2372
2422
  return host;
2373
2423
  }
2374
2424