@matterfact/embed 0.11.2 → 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/README.md +7 -4
- 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 +12 -10
- package/dist/index.d.ts +12 -10
- 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/index.cjs
CHANGED
|
@@ -12,6 +12,36 @@ var __export = (target, all) => {
|
|
|
12
12
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
+
// src/pageContextMode.ts
|
|
16
|
+
function parsePageContextMode(value) {
|
|
17
|
+
if (typeof value === "boolean") return value ? "full" : "off";
|
|
18
|
+
if (value == null) return "full";
|
|
19
|
+
const s = String(value).trim().toLowerCase();
|
|
20
|
+
if (s === "full" || s === "declared" || s === "off") return s;
|
|
21
|
+
if (s === "true" || s === "on" || s === "1" || s === "yes") return "full";
|
|
22
|
+
if (s === "false" || s === "0" || s === "no") return "off";
|
|
23
|
+
return "full";
|
|
24
|
+
}
|
|
25
|
+
function clampPageContextMode(adminMax, hostRequest) {
|
|
26
|
+
return RANK[adminMax] <= RANK[hostRequest] ? adminMax : hostRequest;
|
|
27
|
+
}
|
|
28
|
+
function allowsDeclared(mode) {
|
|
29
|
+
return mode !== "off";
|
|
30
|
+
}
|
|
31
|
+
function allowsAuto(mode) {
|
|
32
|
+
return mode === "full";
|
|
33
|
+
}
|
|
34
|
+
var RANK;
|
|
35
|
+
var init_pageContextMode = __esm({
|
|
36
|
+
"src/pageContextMode.ts"() {
|
|
37
|
+
RANK = {
|
|
38
|
+
off: 0,
|
|
39
|
+
declared: 1,
|
|
40
|
+
full: 2
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
15
45
|
// src/redact.ts
|
|
16
46
|
function redact(text) {
|
|
17
47
|
let out = text;
|
|
@@ -1043,9 +1073,16 @@ __export(context_exports, {
|
|
|
1043
1073
|
redact: () => redact,
|
|
1044
1074
|
sendRegion: () => sendRegion,
|
|
1045
1075
|
sendSnapshot: () => sendSnapshot,
|
|
1076
|
+
setPageContextMax: () => setPageContextMax,
|
|
1046
1077
|
start: () => start,
|
|
1047
1078
|
stop: () => stop
|
|
1048
1079
|
});
|
|
1080
|
+
function effectivePageContextMode() {
|
|
1081
|
+
return clampPageContextMode(adminPageContextMax, hostPageContextMode);
|
|
1082
|
+
}
|
|
1083
|
+
function pageContextOn() {
|
|
1084
|
+
return allowsDeclared(effectivePageContextMode());
|
|
1085
|
+
}
|
|
1049
1086
|
function isPrivate(el) {
|
|
1050
1087
|
if (el.closest("[data-mf-private]")) return true;
|
|
1051
1088
|
const tag = el.tagName;
|
|
@@ -1132,7 +1169,7 @@ async function resolveDeclaredContext() {
|
|
|
1132
1169
|
return mf?.context ?? {};
|
|
1133
1170
|
}
|
|
1134
1171
|
async function publishContext() {
|
|
1135
|
-
if (!pageContextOn) return;
|
|
1172
|
+
if (!pageContextOn()) return;
|
|
1136
1173
|
const declared = await resolveDeclaredContext();
|
|
1137
1174
|
send?.({ type: "host.context", context: buildPageContext(declared) });
|
|
1138
1175
|
}
|
|
@@ -1194,7 +1231,7 @@ function readSitemap2() {
|
|
|
1194
1231
|
return Array.isArray(s) ? s : [];
|
|
1195
1232
|
}
|
|
1196
1233
|
function publishSitemap() {
|
|
1197
|
-
if (!pageContextOn) return;
|
|
1234
|
+
if (!pageContextOn()) return;
|
|
1198
1235
|
const sitemap = readSitemap2();
|
|
1199
1236
|
if (sitemap.length) send?.({ type: "host.sitemap", sitemap });
|
|
1200
1237
|
}
|
|
@@ -1328,7 +1365,7 @@ function scheduleFocus() {
|
|
|
1328
1365
|
}, 250);
|
|
1329
1366
|
}
|
|
1330
1367
|
async function sendSnapshot(emit) {
|
|
1331
|
-
if (!
|
|
1368
|
+
if (!allowsAuto(effectivePageContextMode())) return;
|
|
1332
1369
|
const hoist = detectHoist(() => readHoistRuntime());
|
|
1333
1370
|
if (hoist) {
|
|
1334
1371
|
const { rows } = readHoistConfig(
|
|
@@ -1353,7 +1390,7 @@ async function sendSnapshot(emit) {
|
|
|
1353
1390
|
emit({ type: "host.focus", focus: lastFocus });
|
|
1354
1391
|
}
|
|
1355
1392
|
async function sendRegion(ref, emit) {
|
|
1356
|
-
if (!
|
|
1393
|
+
if (!allowsAuto(effectivePageContextMode())) return;
|
|
1357
1394
|
const { snapshotRegion: snapshotRegion2, resolveRef: resolveRef2 } = await loadSnapshotModule();
|
|
1358
1395
|
const el = resolveRef2(ref);
|
|
1359
1396
|
if (!el) {
|
|
@@ -1368,15 +1405,6 @@ async function sendRegion(ref, emit) {
|
|
|
1368
1405
|
emit({ type: "host.region", ref, yaml: redact(yaml) });
|
|
1369
1406
|
}
|
|
1370
1407
|
async function callTool(call, emit) {
|
|
1371
|
-
if (!pageContextOn) {
|
|
1372
|
-
emit({
|
|
1373
|
-
type: "host.toolResult",
|
|
1374
|
-
callId: call.callId,
|
|
1375
|
-
ok: false,
|
|
1376
|
-
error: "host tools are disabled"
|
|
1377
|
-
});
|
|
1378
|
-
return;
|
|
1379
|
-
}
|
|
1380
1408
|
const win = typeof window !== "undefined" ? window : void 0;
|
|
1381
1409
|
const cls = toolClass(call.name);
|
|
1382
1410
|
const startedAt = Date.now();
|
|
@@ -1433,45 +1461,50 @@ function stop() {
|
|
|
1433
1461
|
widgetOrigin = "";
|
|
1434
1462
|
snapshotModule?.clearRefs();
|
|
1435
1463
|
}
|
|
1464
|
+
function setPageContextMax(max) {
|
|
1465
|
+
adminPageContextMax = parsePageContextMode(max);
|
|
1466
|
+
}
|
|
1436
1467
|
function start(emit, origin, pageContext = true, provider) {
|
|
1437
1468
|
stop();
|
|
1438
1469
|
send = emit;
|
|
1439
1470
|
widgetOrigin = origin || "";
|
|
1440
1471
|
lastUrl = location.pathname;
|
|
1441
|
-
|
|
1472
|
+
hostPageContextMode = parsePageContextMode(pageContext);
|
|
1442
1473
|
contextProvider = provider;
|
|
1443
|
-
if (
|
|
1474
|
+
if (allowsDeclared(effectivePageContextMode())) {
|
|
1444
1475
|
void publishContext();
|
|
1445
1476
|
publishArtifactGrants();
|
|
1446
1477
|
publishSitemap();
|
|
1447
1478
|
watchNavigation();
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
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
|
+
}
|
|
1471
1504
|
}
|
|
1472
1505
|
const theme = matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
1473
1506
|
emit({ type: "host.theme", mode: theme });
|
|
1474
|
-
|
|
1507
|
+
{
|
|
1475
1508
|
const w = typeof window !== "undefined" ? window : void 0;
|
|
1476
1509
|
const tools = advertise(w);
|
|
1477
1510
|
if (tools.length) {
|
|
@@ -1498,9 +1531,10 @@ function publishTools() {
|
|
|
1498
1531
|
});
|
|
1499
1532
|
}
|
|
1500
1533
|
}
|
|
1501
|
-
var widgetOrigin, MAX_ACTIVITY, send, activitySeq, activity, lastUrl,
|
|
1534
|
+
var widgetOrigin, MAX_ACTIVITY, send, activitySeq, activity, lastUrl, hostPageContextMode, adminPageContextMax, contextProvider, navFire, origPushState, origReplaceState, snapshotModule, FORM_CONTROLS, ACTIONABLE, lastFocus, focusTimer, snapshotSeq;
|
|
1502
1535
|
var init_context = __esm({
|
|
1503
1536
|
"src/context.ts"() {
|
|
1537
|
+
init_pageContextMode();
|
|
1504
1538
|
init_redact();
|
|
1505
1539
|
init_hoist();
|
|
1506
1540
|
init_hoist_runtime();
|
|
@@ -1512,7 +1546,8 @@ var init_context = __esm({
|
|
|
1512
1546
|
activitySeq = 0;
|
|
1513
1547
|
activity = [];
|
|
1514
1548
|
lastUrl = "";
|
|
1515
|
-
|
|
1549
|
+
hostPageContextMode = "full";
|
|
1550
|
+
adminPageContextMax = "full";
|
|
1516
1551
|
navFire = null;
|
|
1517
1552
|
origPushState = null;
|
|
1518
1553
|
origReplaceState = null;
|
|
@@ -1751,11 +1786,19 @@ function dockBox(g, vw, _vh) {
|
|
|
1751
1786
|
var DEFAULT_ORIGIN = "https://app.matterfact.com";
|
|
1752
1787
|
function devRequested() {
|
|
1753
1788
|
try {
|
|
1754
|
-
|
|
1789
|
+
if (new URLSearchParams(location.search).get("mfdev") === "1") return true;
|
|
1790
|
+
try {
|
|
1791
|
+
return localStorage.getItem("mfdev") === "1";
|
|
1792
|
+
} catch {
|
|
1793
|
+
return false;
|
|
1794
|
+
}
|
|
1755
1795
|
} catch {
|
|
1756
1796
|
return false;
|
|
1757
1797
|
}
|
|
1758
1798
|
}
|
|
1799
|
+
function alog(m, x) {
|
|
1800
|
+
if (devRequested()) console.info("[embed auth] host: " + m, x ?? "");
|
|
1801
|
+
}
|
|
1759
1802
|
function readConfig() {
|
|
1760
1803
|
const el = document.currentScript ?? document.querySelector('script[data-key][src*="embed"]');
|
|
1761
1804
|
const publishableKey = el?.dataset.key;
|
|
@@ -1771,13 +1814,21 @@ function readConfig() {
|
|
|
1771
1814
|
);
|
|
1772
1815
|
}
|
|
1773
1816
|
const pageContextAttr = el?.dataset.pageContext?.toLowerCase();
|
|
1817
|
+
let pageContext = true;
|
|
1818
|
+
if (pageContextAttr === "off" || pageContextAttr === "false" || pageContextAttr === "0") {
|
|
1819
|
+
pageContext = false;
|
|
1820
|
+
} else if (pageContextAttr === "declared") {
|
|
1821
|
+
pageContext = "declared";
|
|
1822
|
+
} else if (pageContextAttr === "full" || pageContextAttr === "on" || pageContextAttr === "true" || pageContextAttr === "1") {
|
|
1823
|
+
pageContext = true;
|
|
1824
|
+
}
|
|
1774
1825
|
return {
|
|
1775
1826
|
publishableKey,
|
|
1776
1827
|
origin: el?.dataset.origin || DEFAULT_ORIGIN,
|
|
1777
1828
|
theme: el?.dataset.theme || "auto",
|
|
1778
1829
|
surface: el?.dataset.surface || "",
|
|
1779
1830
|
container,
|
|
1780
|
-
pageContext
|
|
1831
|
+
pageContext
|
|
1781
1832
|
// No `data-dev` — see the `dev` field's doc comment: the URL trigger is the
|
|
1782
1833
|
// point for the script-tag path, so there is deliberately no script-tag knob here.
|
|
1783
1834
|
// No `data-actions` either: the action policy lives entirely in the lazy chunk,
|
|
@@ -2047,6 +2098,11 @@ var EmbedHost = class {
|
|
|
2047
2098
|
case "widget.requestContext":
|
|
2048
2099
|
void this.loadContext().then((m) => m.provideContext());
|
|
2049
2100
|
break;
|
|
2101
|
+
case "widget.pageContextMax":
|
|
2102
|
+
void this.loadContext().then((m) => {
|
|
2103
|
+
m.setPageContextMax(msg.mode);
|
|
2104
|
+
});
|
|
2105
|
+
break;
|
|
2050
2106
|
case "widget.requestSnapshot":
|
|
2051
2107
|
void this.loadContext().then((m) => m.sendSnapshot(this.send));
|
|
2052
2108
|
break;
|
|
@@ -2258,14 +2314,22 @@ var EmbedHost = class {
|
|
|
2258
2314
|
*/
|
|
2259
2315
|
async provideAuth() {
|
|
2260
2316
|
const provider = this.config.authTokenProvider ?? globalThis.matterfact?.getEmbedAuthToken;
|
|
2261
|
-
if (!provider)
|
|
2262
|
-
|
|
2317
|
+
if (!provider) {
|
|
2318
|
+
alog("no provider");
|
|
2319
|
+
return;
|
|
2320
|
+
}
|
|
2321
|
+
if (++this.ac > 5) {
|
|
2322
|
+
alog("storm cap");
|
|
2323
|
+
return;
|
|
2324
|
+
}
|
|
2263
2325
|
try {
|
|
2264
2326
|
const token = await provider();
|
|
2265
2327
|
if (token) this.send({ type: "host.auth", token, expiresAt: 0 });
|
|
2266
2328
|
this.emit({ type: "auth", phase: token ? "granted" : "failed" });
|
|
2267
|
-
|
|
2329
|
+
alog(token ? "token" : "empty");
|
|
2330
|
+
} catch (e) {
|
|
2268
2331
|
this.emit({ type: "auth", phase: "failed" });
|
|
2332
|
+
alog("threw", e);
|
|
2269
2333
|
}
|
|
2270
2334
|
}
|
|
2271
2335
|
loadContext() {
|