@matterfact/embed 0.11.3 → 0.12.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.
- package/dist/{chunk-AANODHBV.js → chunk-C4XGE6BO.js} +71 -42
- package/dist/chunk-C4XGE6BO.js.map +1 -0
- package/dist/chunk-M5TS546Z.js +2 -0
- package/dist/chunk-SR4ZNUAN.js +3 -0
- package/dist/chunk-SR4ZNUAN.js.map +7 -0
- package/dist/{chunk-JO3GWFMJ.js → chunk-WAUSVV7Y.js} +2 -2
- package/dist/{chunk-CTZEDOH7.js → chunk-ZXMJWCQV.js} +72 -44
- package/dist/chunk-ZXMJWCQV.js.map +1 -0
- package/dist/{context-FR7VFENN.js → context-4LP3EDXL.js} +3 -3
- package/dist/{context-FR7VFENN.js.map → context-4LP3EDXL.js.map} +1 -1
- package/dist/{context-IK5MECUW.js → context-ZSPDZWIB.js} +4 -2
- package/dist/embed.js +1 -1
- package/dist/embed.js.map +3 -3
- package/dist/index.cjs +110 -46
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -8
- package/dist/index.d.ts +10 -8
- package/dist/index.js +35 -6
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +102 -45
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +26 -5
- package/dist/react.js.map +1 -1
- package/dist/{snapshot-2V5SDSH2.js → snapshot-OR5SVEUD.js} +2 -2
- package/dist/{snapshot-Y5BF2UJR.js → snapshot-X6FPP3HF.js} +3 -3
- package/dist/{snapshot-Y5BF2UJR.js.map → snapshot-X6FPP3HF.js.map} +1 -1
- package/examples/embed-demo/.env.example +7 -3
- package/examples/embed-demo/README.md +25 -4
- package/examples/embed-demo/src/App.tsx +67 -7
- package/examples/embed-demo/src/styles.css +52 -0
- package/examples/embed-demo/vite.config.ts +3 -2
- package/package.json +1 -1
- package/dist/chunk-AANODHBV.js.map +0 -1
- package/dist/chunk-CTZEDOH7.js.map +0 -1
- package/dist/chunk-SKJFF7RD.js +0 -2
- package/dist/chunk-Y7I25VHL.js +0 -3
- package/dist/chunk-Y7I25VHL.js.map +0 -7
- /package/dist/{chunk-SKJFF7RD.js.map → chunk-M5TS546Z.js.map} +0 -0
- /package/dist/{chunk-JO3GWFMJ.js.map → chunk-WAUSVV7Y.js.map} +0 -0
- /package/dist/{context-IK5MECUW.js.map → context-ZSPDZWIB.js.map} +0 -0
- /package/dist/{snapshot-2V5SDSH2.js.map → snapshot-OR5SVEUD.js.map} +0 -0
package/dist/react.cjs
CHANGED
|
@@ -22,6 +22,37 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
22
22
|
};
|
|
23
23
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
24
|
|
|
25
|
+
// src/pageContextMode.ts
|
|
26
|
+
function parsePageContextMode(value) {
|
|
27
|
+
if (typeof value === "boolean") return value ? "full" : "off";
|
|
28
|
+
if (value == null) return "full";
|
|
29
|
+
const s = String(value).trim().toLowerCase();
|
|
30
|
+
if (s === "full" || s === "declared" || s === "off") return s;
|
|
31
|
+
if (s === "true" || s === "on" || s === "1" || s === "yes") return "full";
|
|
32
|
+
if (s === "false" || s === "0" || s === "no") return "off";
|
|
33
|
+
return "full";
|
|
34
|
+
}
|
|
35
|
+
function clampPageContextMode(adminMax, hostRequest) {
|
|
36
|
+
return RANK[adminMax] <= RANK[hostRequest] ? adminMax : hostRequest;
|
|
37
|
+
}
|
|
38
|
+
function allowsDeclared(mode) {
|
|
39
|
+
return mode !== "off";
|
|
40
|
+
}
|
|
41
|
+
function allowsAuto(mode) {
|
|
42
|
+
return mode === "full";
|
|
43
|
+
}
|
|
44
|
+
var RANK;
|
|
45
|
+
var init_pageContextMode = __esm({
|
|
46
|
+
"src/pageContextMode.ts"() {
|
|
47
|
+
"use strict";
|
|
48
|
+
RANK = {
|
|
49
|
+
off: 0,
|
|
50
|
+
declared: 1,
|
|
51
|
+
full: 2
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
25
56
|
// src/redact.ts
|
|
26
57
|
function redact(text) {
|
|
27
58
|
let out = text;
|
|
@@ -1064,9 +1095,16 @@ __export(context_exports, {
|
|
|
1064
1095
|
redact: () => redact,
|
|
1065
1096
|
sendRegion: () => sendRegion,
|
|
1066
1097
|
sendSnapshot: () => sendSnapshot,
|
|
1098
|
+
setPageContextMax: () => setPageContextMax,
|
|
1067
1099
|
start: () => start,
|
|
1068
1100
|
stop: () => stop
|
|
1069
1101
|
});
|
|
1102
|
+
function effectivePageContextMode() {
|
|
1103
|
+
return clampPageContextMode(adminPageContextMax, hostPageContextMode);
|
|
1104
|
+
}
|
|
1105
|
+
function pageContextOn() {
|
|
1106
|
+
return allowsDeclared(effectivePageContextMode());
|
|
1107
|
+
}
|
|
1070
1108
|
function isPrivate(el) {
|
|
1071
1109
|
if (el.closest("[data-mf-private]")) return true;
|
|
1072
1110
|
const tag = el.tagName;
|
|
@@ -1153,7 +1191,7 @@ async function resolveDeclaredContext() {
|
|
|
1153
1191
|
return mf?.context ?? {};
|
|
1154
1192
|
}
|
|
1155
1193
|
async function publishContext() {
|
|
1156
|
-
if (!pageContextOn) return;
|
|
1194
|
+
if (!pageContextOn()) return;
|
|
1157
1195
|
const declared = await resolveDeclaredContext();
|
|
1158
1196
|
send?.({ type: "host.context", context: buildPageContext(declared) });
|
|
1159
1197
|
}
|
|
@@ -1215,7 +1253,7 @@ function readSitemap2() {
|
|
|
1215
1253
|
return Array.isArray(s) ? s : [];
|
|
1216
1254
|
}
|
|
1217
1255
|
function publishSitemap() {
|
|
1218
|
-
if (!pageContextOn) return;
|
|
1256
|
+
if (!pageContextOn()) return;
|
|
1219
1257
|
const sitemap = readSitemap2();
|
|
1220
1258
|
if (sitemap.length) send?.({ type: "host.sitemap", sitemap });
|
|
1221
1259
|
}
|
|
@@ -1350,7 +1388,7 @@ function scheduleFocus() {
|
|
|
1350
1388
|
}, 250);
|
|
1351
1389
|
}
|
|
1352
1390
|
async function sendSnapshot(emit) {
|
|
1353
|
-
if (!
|
|
1391
|
+
if (!allowsAuto(effectivePageContextMode())) return;
|
|
1354
1392
|
const hoist = detectHoist(() => readHoistRuntime());
|
|
1355
1393
|
if (hoist) {
|
|
1356
1394
|
const { rows } = readHoistConfig(
|
|
@@ -1375,7 +1413,7 @@ async function sendSnapshot(emit) {
|
|
|
1375
1413
|
emit({ type: "host.focus", focus: lastFocus });
|
|
1376
1414
|
}
|
|
1377
1415
|
async function sendRegion(ref, emit) {
|
|
1378
|
-
if (!
|
|
1416
|
+
if (!allowsAuto(effectivePageContextMode())) return;
|
|
1379
1417
|
const { snapshotRegion: snapshotRegion2, resolveRef: resolveRef2 } = await loadSnapshotModule();
|
|
1380
1418
|
const el = resolveRef2(ref);
|
|
1381
1419
|
if (!el) {
|
|
@@ -1390,15 +1428,6 @@ async function sendRegion(ref, emit) {
|
|
|
1390
1428
|
emit({ type: "host.region", ref, yaml: redact(yaml) });
|
|
1391
1429
|
}
|
|
1392
1430
|
async function callTool(call, emit) {
|
|
1393
|
-
if (!pageContextOn) {
|
|
1394
|
-
emit({
|
|
1395
|
-
type: "host.toolResult",
|
|
1396
|
-
callId: call.callId,
|
|
1397
|
-
ok: false,
|
|
1398
|
-
error: "host tools are disabled"
|
|
1399
|
-
});
|
|
1400
|
-
return;
|
|
1401
|
-
}
|
|
1402
1431
|
const win = typeof window !== "undefined" ? window : void 0;
|
|
1403
1432
|
const cls = toolClass(call.name);
|
|
1404
1433
|
const startedAt = Date.now();
|
|
@@ -1455,45 +1484,50 @@ function stop() {
|
|
|
1455
1484
|
widgetOrigin = "";
|
|
1456
1485
|
snapshotModule?.clearRefs();
|
|
1457
1486
|
}
|
|
1487
|
+
function setPageContextMax(max) {
|
|
1488
|
+
adminPageContextMax = parsePageContextMode(max);
|
|
1489
|
+
}
|
|
1458
1490
|
function start(emit, origin, pageContext = true, provider) {
|
|
1459
1491
|
stop();
|
|
1460
1492
|
send = emit;
|
|
1461
1493
|
widgetOrigin = origin || "";
|
|
1462
1494
|
lastUrl = location.pathname;
|
|
1463
|
-
|
|
1495
|
+
hostPageContextMode = parsePageContextMode(pageContext);
|
|
1464
1496
|
contextProvider = provider;
|
|
1465
|
-
if (
|
|
1497
|
+
if (allowsDeclared(effectivePageContextMode())) {
|
|
1466
1498
|
void publishContext();
|
|
1467
1499
|
publishArtifactGrants();
|
|
1468
1500
|
publishSitemap();
|
|
1469
1501
|
watchNavigation();
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1502
|
+
if (allowsAuto(effectivePageContextMode())) {
|
|
1503
|
+
document.addEventListener("click", onClick, {
|
|
1504
|
+
capture: true,
|
|
1505
|
+
passive: true
|
|
1506
|
+
});
|
|
1507
|
+
document.addEventListener("submit", onSubmit, {
|
|
1508
|
+
capture: true,
|
|
1509
|
+
passive: true
|
|
1510
|
+
});
|
|
1511
|
+
document.addEventListener("change", onChange, {
|
|
1512
|
+
capture: true,
|
|
1513
|
+
passive: true
|
|
1514
|
+
});
|
|
1515
|
+
document.addEventListener("selectionchange", scheduleFocus, {
|
|
1516
|
+
passive: true
|
|
1517
|
+
});
|
|
1518
|
+
document.addEventListener("focusin", scheduleFocus, {
|
|
1519
|
+
capture: true,
|
|
1520
|
+
passive: true
|
|
1521
|
+
});
|
|
1522
|
+
window.addEventListener("scroll", scheduleFocus, {
|
|
1523
|
+
capture: true,
|
|
1524
|
+
passive: true
|
|
1525
|
+
});
|
|
1526
|
+
}
|
|
1493
1527
|
}
|
|
1494
1528
|
const theme = matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
1495
1529
|
emit({ type: "host.theme", mode: theme });
|
|
1496
|
-
|
|
1530
|
+
{
|
|
1497
1531
|
const w = typeof window !== "undefined" ? window : void 0;
|
|
1498
1532
|
const tools = advertise(w);
|
|
1499
1533
|
if (tools.length) {
|
|
@@ -1520,10 +1554,11 @@ function publishTools() {
|
|
|
1520
1554
|
});
|
|
1521
1555
|
}
|
|
1522
1556
|
}
|
|
1523
|
-
var widgetOrigin, MAX_ACTIVITY, send, activitySeq, activity, lastUrl,
|
|
1557
|
+
var widgetOrigin, MAX_ACTIVITY, send, activitySeq, activity, lastUrl, hostPageContextMode, adminPageContextMax, contextProvider, navFire, origPushState, origReplaceState, snapshotModule, FORM_CONTROLS, ACTIONABLE, lastFocus, focusTimer, snapshotSeq;
|
|
1524
1558
|
var init_context = __esm({
|
|
1525
1559
|
"src/context.ts"() {
|
|
1526
1560
|
"use strict";
|
|
1561
|
+
init_pageContextMode();
|
|
1527
1562
|
init_redact();
|
|
1528
1563
|
init_hoist();
|
|
1529
1564
|
init_hoist_runtime();
|
|
@@ -1535,7 +1570,8 @@ var init_context = __esm({
|
|
|
1535
1570
|
activitySeq = 0;
|
|
1536
1571
|
activity = [];
|
|
1537
1572
|
lastUrl = "";
|
|
1538
|
-
|
|
1573
|
+
hostPageContextMode = "full";
|
|
1574
|
+
adminPageContextMax = "full";
|
|
1539
1575
|
navFire = null;
|
|
1540
1576
|
origPushState = null;
|
|
1541
1577
|
origReplaceState = null;
|
|
@@ -1782,11 +1818,19 @@ function dockBox(g, vw, _vh) {
|
|
|
1782
1818
|
// src/loader.ts
|
|
1783
1819
|
function devRequested() {
|
|
1784
1820
|
try {
|
|
1785
|
-
|
|
1821
|
+
if (new URLSearchParams(location.search).get("mfdev") === "1") return true;
|
|
1822
|
+
try {
|
|
1823
|
+
return localStorage.getItem("mfdev") === "1";
|
|
1824
|
+
} catch {
|
|
1825
|
+
return false;
|
|
1826
|
+
}
|
|
1786
1827
|
} catch {
|
|
1787
1828
|
return false;
|
|
1788
1829
|
}
|
|
1789
1830
|
}
|
|
1831
|
+
function alog(m, x) {
|
|
1832
|
+
if (devRequested()) console.info("[embed auth] host: " + m, x ?? "");
|
|
1833
|
+
}
|
|
1790
1834
|
var POS_KEY = "mf.embed.pos";
|
|
1791
1835
|
var EmbedHost = class {
|
|
1792
1836
|
constructor(config) {
|
|
@@ -2048,6 +2092,11 @@ var EmbedHost = class {
|
|
|
2048
2092
|
case "widget.requestContext":
|
|
2049
2093
|
void this.loadContext().then((m) => m.provideContext());
|
|
2050
2094
|
break;
|
|
2095
|
+
case "widget.pageContextMax":
|
|
2096
|
+
void this.loadContext().then((m) => {
|
|
2097
|
+
m.setPageContextMax(msg.mode);
|
|
2098
|
+
});
|
|
2099
|
+
break;
|
|
2051
2100
|
case "widget.requestSnapshot":
|
|
2052
2101
|
void this.loadContext().then((m) => m.sendSnapshot(this.send));
|
|
2053
2102
|
break;
|
|
@@ -2260,14 +2309,22 @@ var EmbedHost = class {
|
|
|
2260
2309
|
*/
|
|
2261
2310
|
async provideAuth() {
|
|
2262
2311
|
const provider = this.config.authTokenProvider ?? globalThis.matterfact?.getEmbedAuthToken;
|
|
2263
|
-
if (!provider)
|
|
2264
|
-
|
|
2312
|
+
if (!provider) {
|
|
2313
|
+
alog("no provider");
|
|
2314
|
+
return;
|
|
2315
|
+
}
|
|
2316
|
+
if (++this.ac > 5) {
|
|
2317
|
+
alog("storm cap");
|
|
2318
|
+
return;
|
|
2319
|
+
}
|
|
2265
2320
|
try {
|
|
2266
2321
|
const token = await provider();
|
|
2267
2322
|
if (token) this.send({ type: "host.auth", token, expiresAt: 0 });
|
|
2268
2323
|
this.emit({ type: "auth", phase: token ? "granted" : "failed" });
|
|
2269
|
-
|
|
2324
|
+
alog(token ? "token" : "empty");
|
|
2325
|
+
} catch (e) {
|
|
2270
2326
|
this.emit({ type: "auth", phase: "failed" });
|
|
2327
|
+
alog("threw", e);
|
|
2271
2328
|
}
|
|
2272
2329
|
}
|
|
2273
2330
|
loadContext() {
|