@openbkn/workshop 0.2.2-rc.5 → 0.2.2
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 +83 -13
- package/component.d.ts +10 -0
- package/dist/ActionConfirm-DJ91X3ml.js +236 -0
- package/dist/ActionFailure-ZgPt_3B-.js +37 -0
- package/dist/AgentChat-CRYai8ge.js +1062 -0
- package/dist/AppFormModal-D73ucaHK.js +4282 -0
- package/dist/AppListPage-D87piiOw.js +1364 -0
- package/dist/AskDrawer-BUMYsRnt.js +38 -0
- package/dist/ComputedView-CgYrDbx1.js +3221 -0
- package/dist/ConclusionApply-sjGfoEBY.js +153 -0
- package/dist/CypherEditor-lus6FA5L.js +485 -0
- package/dist/LandingList-6JI6864C.js +230 -0
- package/dist/MenuUnfoldOutlined-Cdg24l2h.js +27 -0
- package/dist/ModelTrial-ClHFGTpQ.js +359 -0
- package/dist/PageRenderer-DBd_g6mN.js +85480 -0
- package/dist/README-DjRyTQSR.js +76 -0
- package/dist/ScenarioApply-DtW_hh47.js +590 -0
- package/dist/SimulateForm-C-i08Jjd.js +153 -0
- package/dist/Subgraph-CnrkH9AN.js +32586 -0
- package/dist/WorkshopLabPage-DiVXQL9e.js +11364 -0
- package/dist/WorkshopRunPage-6hjRUf64.js +253 -0
- package/dist/abnfDiagram-WEYOIA3C-beRNhN3c.js +87 -0
- package/dist/action-type-tool.service-B2B74fKC.js +1060 -0
- package/dist/actionButton-DA5CNEzx.js +94 -0
- package/dist/actionButton.en-US-qjeqA7hs.js +94 -0
- package/dist/agentChat-EoDznd58.js +116 -0
- package/dist/agentChat.en-US-B6-pFd9Y.js +116 -0
- package/dist/alertList-DqditwM8.js +84 -0
- package/dist/alertList.en-US-BAXAgltP.js +84 -0
- package/dist/architectureDiagram-ZHVYKT53-DY2l1qxx.js +4779 -0
- package/dist/asOfSlider-QPvHWUMV.js +83 -0
- package/dist/asOfSlider.en-US-BI4jVfSn.js +83 -0
- package/dist/bkn-agent-execution.service-DVh-SHyl.js +205 -0
- package/dist/blockDiagram-RJAE7QA3-DR0mjN2h.js +1435 -0
- package/dist/c4Diagram-XDPPPE54-DH5zsGug.js +1518 -0
- package/dist/channel-B034hcOF.js +5 -0
- package/dist/china-C6m7zXIv.js +9 -0
- package/dist/chunk-2E7WHVMD-Ba3svxgx.js +664 -0
- package/dist/chunk-2Q5K7J3B-rT4eU6_y.js +15 -0
- package/dist/chunk-4EMNKR2T-C1kQZYHK.js +262 -0
- package/dist/chunk-55XCU76K-dcpLOktb.js +68 -0
- package/dist/chunk-5VM5RSS4-BdpQuzmO.js +19 -0
- package/dist/chunk-JWPE2WC7-CDBrSjU7.js +8 -0
- package/dist/chunk-VQ5W62QI-BiVKc40w.js +19 -0
- package/dist/chunk-XXDRQBXY-CPYrcdVW.js +8 -0
- package/dist/chunk-ZCHMQSOR-BG8OLpvb.js +451 -0
- package/dist/classDiagram-v2-4MYWR3UA-DqbpQpwI.js +1564 -0
- package/dist/component.d-DFoMKuUv.js +179 -0
- package/dist/cose-bilkent-JH36ORCC-CdXk4sPf.js +2609 -0
- package/dist/customComponents-DasaZ6pq.js +4 -0
- package/dist/customComponents.en-US-CkabuCXg.js +79 -0
- package/dist/customParseFormat-C0uLEpdq.js +182 -0
- package/dist/cynefin-EF2NZ3EQ-D7MVnMHu.js +21746 -0
- package/dist/cynefinDiagram-WF24UDRP-BYT_KpDL.js +299 -0
- package/dist/cytoscape.esm-BCV9V6aO.js +18760 -0
- package/dist/d3-scale-DA8IHmf0.js +1841 -0
- package/dist/dagre-NK4GIZVX-l-ghPdM8.js +2154 -0
- package/dist/dateRange-BbkLMg8L.js +79 -0
- package/dist/dateRange.en-US-CV12Q02G.js +79 -0
- package/dist/dayjs.min-DZ-YV8Mv.js +284 -0
- package/dist/diagram-CBK3MWTC-Bt3HiwvA.js +542 -0
- package/dist/diagram-I5XIIV2D-DcbqfBjx.js +150 -0
- package/dist/diagram-ODIL2UCW-9PC1n3n5.js +346 -0
- package/dist/diagram-PFBEJUXE-DGhr2kc7.js +478 -0
- package/dist/diagram-RJA3I4VV-DwzpOjZ_.js +219 -0
- package/dist/diagram-TYUNFSNR-B3Bd3TDU.js +2583 -0
- package/dist/dropdownFilter-DOi_8-ZT.js +76 -0
- package/dist/dropdownFilter.en-US-BiXpvXtF.js +76 -0
- package/dist/ebnfDiagram-V4P3TTPT-E5NN2oKc.js +109 -0
- package/dist/elk-QONTBCTQ-dFjcujl_.js +49170 -0
- package/dist/erDiagram-KYQIGQAA-BMrasBzB.js +1061 -0
- package/dist/eventList-CnsAwfDS.js +115 -0
- package/dist/eventList.en-US-Cof3rCLq.js +115 -0
- package/dist/eventReport-XS-HegnH.js +76 -0
- package/dist/eventReport.en-US-DTx4vzWT.js +76 -0
- package/dist/flowDiagram-IUGLLWBU-BGIBH0q0.js +1769 -0
- package/dist/ganttChart-DEeSvTJA.js +77 -0
- package/dist/ganttChart.en-US-SwRKrnoD.js +77 -0
- package/dist/ganttDiagram-R7GPNTJY-C0tb1Lpp.js +1741 -0
- package/dist/generateCypher-Ch9_lQa6.js +399 -0
- package/dist/gitGraphDiagram-PDYL7XHY-DBqcOa-c.js +815 -0
- package/dist/graph-CKJmgLki.js +1541 -0
- package/dist/index-BA-GzCXt.js +441 -0
- package/dist/infoDiagram-MVDRKAX5-Bwuki4JA.js +24 -0
- package/dist/ishikawaDiagram-HPEHV2GE-Dz4d6ygx.js +622 -0
- package/dist/journeyDiagram-BOSHW7O7-C99m34Bb.js +834 -0
- package/dist/kanban-definition-FNSA4HC5-mdqjODsT.js +724 -0
- package/dist/katex-BsrBVQKd.js +11314 -0
- package/dist/manifest-BjV1PJ6u.js +41 -0
- package/dist/mermaid.core-yQghUlIz.js +17642 -0
- package/dist/metricCards-CSb-_cT2.js +104 -0
- package/dist/metricCards.en-US-BLLhRsQU.js +104 -0
- package/dist/mindmap-definition-6OY57UG3-BZhO2wX4.js +834 -0
- package/dist/modelTrial-Bvb-RhGt.js +137 -0
- package/dist/modelTrial.en-US-DYcuor-G.js +137 -0
- package/dist/models-DekiCOuZ.js +6 -0
- package/dist/object-metric-numeric-vs3BeDkH.js +42 -0
- package/dist/object-metric.service-flZgBMRX.js +233 -0
- package/dist/objectDetail-SQUbp4Py.js +117 -0
- package/dist/objectDetail.en-US-DW3mlONM.js +117 -0
- package/dist/objectList-D99wPtJH.js +97 -0
- package/dist/objectList.en-US-PBBNyVLW.js +97 -0
- package/dist/objectTable-0jsFFMN3.js +127 -0
- package/dist/objectTable.en-US-yWEs8qc_.js +127 -0
- package/dist/pegDiagram-ECIUJNBX-BDa5RfZt.js +95 -0
- package/dist/pieDiagram-GNMPY74T-DNVtzXPv.js +165 -0
- package/dist/pivotTable-CHmQw18-.js +102 -0
- package/dist/pivotTable.en-US-B4uv4P08.js +102 -0
- package/dist/prompt-DYrjlEFr.js +373 -0
- package/dist/quadrantDiagram-D57K4MC3-vK0f2OvQ.js +1023 -0
- package/dist/railroadDiagram-Y72NRBL7-j6ZrTmRp.js +77 -0
- package/dist/regionMap-Cme-JyV_.js +128 -0
- package/dist/regionMap.en-US-Bwr2_p32.js +128 -0
- package/dist/requirementDiagram-EQYSW5RA-DgfEyljA.js +886 -0
- package/dist/sankeyDiagram-SY24JHO5-CImx-IX0.js +1160 -0
- package/dist/scenarioBar-BV43p7n-.js +122 -0
- package/dist/scenarioBar.en-US-5KqMQ2Bg.js +122 -0
- package/dist/scheduleGantt-CTYO-zYP.js +180 -0
- package/dist/scheduleGantt.en-US-hE7mvVUW.js +180 -0
- package/dist/searchBox-Ca7w0f_6.js +67 -0
- package/dist/searchBox.en-US-ArS_XBvB.js +67 -0
- package/dist/segmentedFilter-MhjVcWo0.js +80 -0
- package/dist/segmentedFilter.en-US-BxNrQO5T.js +80 -0
- package/dist/sequenceDiagram-BLEHNHQU-nWmjd1ci.js +2969 -0
- package/dist/sizeCapture-INFHLROL-D3jlbt7h.js +46 -0
- package/dist/stageChain-BxBafwjD.js +74 -0
- package/dist/stageChain.en-US-CP0G27n8.js +74 -0
- package/dist/stateDiagram-v2-A6IESKWZ-DG1ZetEu.js +1514 -0
- package/dist/subgraph-7n4SwliR.js +71 -0
- package/dist/subgraph.en-US-BNvY18IW.js +71 -0
- package/dist/swimlanes-B3ENRKFQ-cCmJE8AU.js +4991 -0
- package/dist/swimlanesDiagram-AYQRV4AK-CtuhyguU.js +14 -0
- package/dist/taskInbox-DGWYeI2b.js +118 -0
- package/dist/taskInbox.en-US-B-OzDmVl.js +118 -0
- package/dist/text-BqSVQKS6.js +78 -0
- package/dist/text.en-US-BhAxy_LE.js +78 -0
- package/dist/timeline-definition-JXYKGLGB-Cc-INsOv.js +1057 -0
- package/dist/trendChart-BjEeRS5_.js +135 -0
- package/dist/trendChart.en-US-BBGqWUKM.js +135 -0
- package/dist/useLabData-Df-jEHKs.js +20470 -0
- package/dist/usecaseDiagram-WPOLBNNX-r8wVjopm.js +7920 -0
- package/dist/vennDiagram-Q3Y3IDCW-BZiOcgrj.js +1579 -0
- package/dist/wardleyDiagram-IVAIDKWA-16jd07C_.js +675 -0
- package/dist/workshop-app-DnHNjBqy.js +86038 -0
- package/dist/workshop-app.css +1 -0
- package/dist/workshop-app.js +4 -0
- package/dist/world-Djau1JyJ.js +9 -0
- package/dist/xychartDiagram-4URNHDU4-C8DwWQNh.js +1460 -0
- package/dist-cli/workshop.js +341 -218
- package/example/host.js +109 -0
- package/example/index.html +93 -0
- package/example/server.mjs +237 -0
- package/index.d.ts +48 -0
- package/lib/validate.js +47 -1
- package/package.json +17 -5
- package/runtime/frame-runtime.js +13 -1
- package/workshop-component.js +32 -12
- package/workshop.js +2 -0
package/example/host.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// Copyright openbkn.ai. All rights reserved.
|
|
2
|
+
// Proprietary — OpenBKN Enterprise Edition. See LICENSE in the repository root.
|
|
3
|
+
|
|
4
|
+
// A page of another system with the whole of Workshop in it. The page keeps Workshop's place in
|
|
5
|
+
// its address after the #, signs its user in its own way (here, server.mjs's /host/token) and
|
|
6
|
+
// switches Workshop's language with its own. With a bundler the import below is the same; this
|
|
7
|
+
// page maps it to the package's file in index.html.
|
|
8
|
+
|
|
9
|
+
import { mountWorkshop } from "@openbkn/workshop";
|
|
10
|
+
|
|
11
|
+
const TEXTS = {
|
|
12
|
+
"zh-CN": { system: "示例业务系统", apps: "应用", noToken: "取不到用户的令牌:" },
|
|
13
|
+
"en-US": { system: "Example system", apps: "Apps", noToken: "No token for the user: " },
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
function remembered() {
|
|
17
|
+
try {
|
|
18
|
+
const language = localStorage.getItem("example.locale");
|
|
19
|
+
return language === "en-US" ? "en-US" : "zh-CN";
|
|
20
|
+
} catch {
|
|
21
|
+
return "zh-CN";
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let locale = remembered();
|
|
26
|
+
|
|
27
|
+
/** The page's own words, in its language. */
|
|
28
|
+
function word() {
|
|
29
|
+
const texts = TEXTS[locale];
|
|
30
|
+
document.documentElement.lang = locale;
|
|
31
|
+
document.querySelector("#system").textContent = texts.system;
|
|
32
|
+
document.querySelector("#apps").textContent = texts.apps;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// The page's sign-in: a token of the platform's for its user, asked again when it runs out.
|
|
36
|
+
let token = null;
|
|
37
|
+
async function signIn() {
|
|
38
|
+
const answer = await fetch("/host/token", { cache: "no-store" });
|
|
39
|
+
if (!answer.ok) throw new Error(await answer.text());
|
|
40
|
+
({ token } = await answer.json());
|
|
41
|
+
return token;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Who the token is, which tells the user's own apps from those shared with them. */
|
|
45
|
+
async function whoAmI() {
|
|
46
|
+
try {
|
|
47
|
+
const answer = await fetch("/api/safe/v1/me", {
|
|
48
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
49
|
+
});
|
|
50
|
+
if (!answer.ok) return {};
|
|
51
|
+
const me = await answer.json();
|
|
52
|
+
return { id: me.id, name: me.name };
|
|
53
|
+
} catch {
|
|
54
|
+
return {};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** #/apps/<id> is the builder, #/apps/<id>/run and #/apps/<id>/preview the app; else the list. */
|
|
59
|
+
function placeOf(hash) {
|
|
60
|
+
const found = /^#\/apps\/([^/]+)(?:\/(run|preview))?$/.exec(hash);
|
|
61
|
+
if (!found) return { page: "apps" };
|
|
62
|
+
return { page: found[2] ?? "builder", appId: decodeURIComponent(found[1]) };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function hashOf(place) {
|
|
66
|
+
if (place.page === "apps") return "#/apps";
|
|
67
|
+
const app = `#/apps/${encodeURIComponent(place.appId)}`;
|
|
68
|
+
return place.page === "builder" ? app : `${app}/${place.page}`;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
word();
|
|
72
|
+
const container = document.querySelector("#workshop");
|
|
73
|
+
try {
|
|
74
|
+
await signIn();
|
|
75
|
+
} catch (error) {
|
|
76
|
+
container.textContent = TEXTS[locale].noToken + error.message;
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
79
|
+
const user = await whoAmI();
|
|
80
|
+
document.querySelector("#user").textContent = user.name ?? "";
|
|
81
|
+
|
|
82
|
+
const workshop = mountWorkshop(container, {
|
|
83
|
+
// The page's own origin: its server passes /api on to the platform.
|
|
84
|
+
apiBase: "/api",
|
|
85
|
+
getToken: () => token,
|
|
86
|
+
refreshToken: () => signIn().catch(() => null),
|
|
87
|
+
user,
|
|
88
|
+
locale,
|
|
89
|
+
place: placeOf(window.location.hash),
|
|
90
|
+
href: hashOf,
|
|
91
|
+
onNavigate: (place) => {
|
|
92
|
+
window.location.hash = hashOf(place);
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
// The address changed by the page itself, or by back and forward.
|
|
96
|
+
window.addEventListener("hashchange", () => workshop.show(placeOf(window.location.hash)));
|
|
97
|
+
|
|
98
|
+
const language = document.querySelector("#language");
|
|
99
|
+
language.value = locale;
|
|
100
|
+
language.addEventListener("change", () => {
|
|
101
|
+
locale = language.value;
|
|
102
|
+
try {
|
|
103
|
+
localStorage.setItem("example.locale", locale);
|
|
104
|
+
} catch {
|
|
105
|
+
// Remembering it is a convenience.
|
|
106
|
+
}
|
|
107
|
+
word();
|
|
108
|
+
workshop.setLocale(locale);
|
|
109
|
+
});
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<title>Workshop host example</title>
|
|
7
|
+
<link rel="icon" href="data:," />
|
|
8
|
+
<!-- With a bundler, import "@openbkn/workshop/style.css" and the package by name instead. -->
|
|
9
|
+
<link rel="stylesheet" href="/workshop/workshop-app.css" />
|
|
10
|
+
<script type="importmap">
|
|
11
|
+
{ "imports": { "@openbkn/workshop": "/workshop/workshop-app.js" } }
|
|
12
|
+
</script>
|
|
13
|
+
<style>
|
|
14
|
+
/*
|
|
15
|
+
* The page's own look, as another system has one. Workshop draws in the page itself, not in a
|
|
16
|
+
* frame: rules named by element alone (header, main, a, table...) reach into it too, so the
|
|
17
|
+
* page names its own parts by class.
|
|
18
|
+
*/
|
|
19
|
+
:root {
|
|
20
|
+
--host-text: #1d2129;
|
|
21
|
+
--host-bg: #eef0f3;
|
|
22
|
+
--host-bar: #23324d;
|
|
23
|
+
--host-bar-text: #fff;
|
|
24
|
+
--host-surface: #fff;
|
|
25
|
+
}
|
|
26
|
+
* {
|
|
27
|
+
box-sizing: border-box;
|
|
28
|
+
}
|
|
29
|
+
html,
|
|
30
|
+
body {
|
|
31
|
+
height: 100%;
|
|
32
|
+
margin: 0;
|
|
33
|
+
}
|
|
34
|
+
body {
|
|
35
|
+
display: flex;
|
|
36
|
+
flex-direction: column;
|
|
37
|
+
font:
|
|
38
|
+
14px/1.5 system-ui,
|
|
39
|
+
-apple-system,
|
|
40
|
+
"PingFang SC",
|
|
41
|
+
sans-serif;
|
|
42
|
+
color: var(--host-text);
|
|
43
|
+
background: var(--host-bg);
|
|
44
|
+
}
|
|
45
|
+
.host-bar {
|
|
46
|
+
display: flex;
|
|
47
|
+
flex-wrap: wrap;
|
|
48
|
+
gap: 16px;
|
|
49
|
+
align-items: center;
|
|
50
|
+
min-height: 48px;
|
|
51
|
+
padding: 8px 16px;
|
|
52
|
+
color: var(--host-bar-text);
|
|
53
|
+
background: var(--host-bar);
|
|
54
|
+
}
|
|
55
|
+
.host-bar strong {
|
|
56
|
+
font-size: 16px;
|
|
57
|
+
}
|
|
58
|
+
.host-bar nav {
|
|
59
|
+
flex: 1;
|
|
60
|
+
}
|
|
61
|
+
.host-bar a {
|
|
62
|
+
color: var(--host-bar-text);
|
|
63
|
+
}
|
|
64
|
+
.host-bar select {
|
|
65
|
+
font: inherit;
|
|
66
|
+
}
|
|
67
|
+
.host-main {
|
|
68
|
+
flex: 1;
|
|
69
|
+
min-height: 0;
|
|
70
|
+
padding: 12px;
|
|
71
|
+
}
|
|
72
|
+
#workshop {
|
|
73
|
+
height: 100%;
|
|
74
|
+
overflow: hidden;
|
|
75
|
+
background: var(--host-surface);
|
|
76
|
+
border-radius: 8px;
|
|
77
|
+
}
|
|
78
|
+
</style>
|
|
79
|
+
</head>
|
|
80
|
+
<body>
|
|
81
|
+
<header class="host-bar">
|
|
82
|
+
<strong id="system"></strong>
|
|
83
|
+
<nav><a id="apps" href="#/apps"></a></nav>
|
|
84
|
+
<span id="user"></span>
|
|
85
|
+
<select id="language" aria-label="Language">
|
|
86
|
+
<option value="zh-CN">中文</option>
|
|
87
|
+
<option value="en-US">English</option>
|
|
88
|
+
</select>
|
|
89
|
+
</header>
|
|
90
|
+
<main class="host-main"><div id="workshop"></div></main>
|
|
91
|
+
<script type="module" src="/host.js"></script>
|
|
92
|
+
</body>
|
|
93
|
+
</html>
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Copyright openbkn.ai. All rights reserved.
|
|
3
|
+
// Proprietary — OpenBKN Enterprise Edition. See LICENSE in the repository root.
|
|
4
|
+
|
|
5
|
+
// What the backend of a page holding Workshop does, to try it out on this computer: it serves the
|
|
6
|
+
// page and the package's library, passes /api on to the platform so that the page reaches it from
|
|
7
|
+
// its own origin, and stands in for the page's own sign-in at /host/token.
|
|
8
|
+
//
|
|
9
|
+
// node example/server.mjs [--port 8050] [-k] [--lang en-US]
|
|
10
|
+
//
|
|
11
|
+
// The platform and the token are found as the workshop command finds them: BKN_BASE_URL and
|
|
12
|
+
// BKN_TOKEN where they are set, else the openbkn command line's own login. It listens on
|
|
13
|
+
// 127.0.0.1 only, as it hands the token to whoever asks.
|
|
14
|
+
|
|
15
|
+
import { execFile } from "node:child_process";
|
|
16
|
+
import { readFile } from "node:fs/promises";
|
|
17
|
+
import { createServer, request as plainRequest } from "node:http";
|
|
18
|
+
import { request as secureRequest } from "node:https";
|
|
19
|
+
import { dirname, extname, isAbsolute, join, relative } from "node:path";
|
|
20
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
21
|
+
import { parseArgs } from "node:util";
|
|
22
|
+
|
|
23
|
+
import { fill, languageOf } from "../lib/lang.js";
|
|
24
|
+
|
|
25
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
26
|
+
|
|
27
|
+
/** What the example says, in the language the workshop command speaks. */
|
|
28
|
+
const TEXT = {
|
|
29
|
+
"zh-CN": {
|
|
30
|
+
usage: `用法:node example/server.mjs [--port 8050] [-k] [--lang en-US]
|
|
31
|
+
|
|
32
|
+
在本机起一个挂着 Workshop 的示例宿主页。平台地址与令牌按 workshop 命令的方式找:
|
|
33
|
+
环境变量 BKN_BASE_URL、BKN_TOKEN,没有时用 openbkn 命令行当前的登录。
|
|
34
|
+
--port 端口,默认 8050
|
|
35
|
+
-k 平台是自签证书时不校验证书
|
|
36
|
+
--lang zh-CN 或 en-US,与 workshop 命令的语言一样定`,
|
|
37
|
+
unreachable: "连不上平台 {platform}:{message}",
|
|
38
|
+
noOpenbkn:
|
|
39
|
+
"找不到 openbkn 命令行:安装 @openbkn/bkn-sdk 后运行 openbkn auth login <平台地址>,或设置环境变量 BKN_BASE_URL 与 BKN_TOKEN",
|
|
40
|
+
openbknFailed: "openbkn {args} 失败:{reason}",
|
|
41
|
+
tokenWithoutBase: "设置了 BKN_TOKEN,也要设置 BKN_BASE_URL(平台地址)",
|
|
42
|
+
notLoggedIn: "openbkn 还没有登录:先运行 openbkn auth login <平台地址>",
|
|
43
|
+
otherLogin:
|
|
44
|
+
"openbkn 当前登录的平台是 {active},不是 {named}:先运行 openbkn auth use {named},或设置 BKN_TOKEN",
|
|
45
|
+
badPort: "端口不对:{port}",
|
|
46
|
+
started: "示例宿主页:http://127.0.0.1:{port}/\n平台:{platform}\n按 Ctrl+C 停止",
|
|
47
|
+
},
|
|
48
|
+
"en-US": {
|
|
49
|
+
usage: `Usage: node example/server.mjs [--port 8050] [-k] [--lang en-US]
|
|
50
|
+
|
|
51
|
+
Runs an example page holding Workshop on this computer. The platform and the token are found as
|
|
52
|
+
the workshop command finds them: BKN_BASE_URL and BKN_TOKEN, else the openbkn command line's login.
|
|
53
|
+
--port The port, 8050 unless named
|
|
54
|
+
-k Does not check the certificate of a self-signed platform
|
|
55
|
+
--lang zh-CN or en-US, picked as the workshop command picks its language`,
|
|
56
|
+
unreachable: "Cannot reach the platform {platform}: {message}",
|
|
57
|
+
noOpenbkn:
|
|
58
|
+
"The openbkn command line was not found: install @openbkn/bkn-sdk and run openbkn auth login <platform>, or set BKN_BASE_URL and BKN_TOKEN",
|
|
59
|
+
openbknFailed: "openbkn {args} failed: {reason}",
|
|
60
|
+
tokenWithoutBase: "With BKN_TOKEN, set BKN_BASE_URL (the platform's address) too",
|
|
61
|
+
notLoggedIn: "openbkn is not logged in: run openbkn auth login <platform> first",
|
|
62
|
+
otherLogin:
|
|
63
|
+
"openbkn is logged in to {active}, not {named}: run openbkn auth use {named} first, or set BKN_TOKEN",
|
|
64
|
+
badPort: "The port is not right: {port}",
|
|
65
|
+
started: "Example page: http://127.0.0.1:{port}/\nPlatform: {platform}\nCtrl+C to stop",
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const say = (language, key, values) => fill(TEXT[language][key], values);
|
|
70
|
+
|
|
71
|
+
const TYPES = {
|
|
72
|
+
".html": "text/html; charset=utf-8",
|
|
73
|
+
".js": "text/javascript; charset=utf-8",
|
|
74
|
+
".css": "text/css; charset=utf-8",
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/** The files of the page itself; everything else it loads is the library's. */
|
|
78
|
+
const PAGE = { "/": "index.html", "/index.html": "index.html", "/host.js": "host.js" };
|
|
79
|
+
|
|
80
|
+
/** A file of `dir` named by the rest of an address, or nothing for one that leads out of it. */
|
|
81
|
+
function within(dir, rest) {
|
|
82
|
+
let name;
|
|
83
|
+
try {
|
|
84
|
+
name = decodeURIComponent(rest);
|
|
85
|
+
} catch {
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
const file = join(dir, name);
|
|
89
|
+
const inside = relative(dir, file);
|
|
90
|
+
return inside && !inside.startsWith("..") && !isAbsolute(inside) ? file : undefined;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function sendFile(res, file) {
|
|
94
|
+
try {
|
|
95
|
+
const body = await readFile(file);
|
|
96
|
+
res.writeHead(200, {
|
|
97
|
+
"Content-Type": TYPES[extname(file)] ?? "application/octet-stream",
|
|
98
|
+
"Cache-Control": "no-cache",
|
|
99
|
+
});
|
|
100
|
+
res.end(body);
|
|
101
|
+
} catch {
|
|
102
|
+
res.writeHead(404).end();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** The request as the platform gets it: its own host, and none of the page's cookies. */
|
|
107
|
+
function pass(req, res, platform, insecure, language) {
|
|
108
|
+
const target = new URL(req.url, platform);
|
|
109
|
+
const headers = { ...req.headers, host: target.host };
|
|
110
|
+
// The page's cookies are its own; the platform is reached with the bearer token alone.
|
|
111
|
+
delete headers.cookie;
|
|
112
|
+
const send = target.protocol === "https:" ? secureRequest : plainRequest;
|
|
113
|
+
const upstream = send(
|
|
114
|
+
target,
|
|
115
|
+
{ method: req.method, headers, rejectUnauthorized: !insecure },
|
|
116
|
+
(answer) => {
|
|
117
|
+
res.writeHead(answer.statusCode ?? 502, answer.headers);
|
|
118
|
+
answer.pipe(res);
|
|
119
|
+
},
|
|
120
|
+
);
|
|
121
|
+
upstream.on("error", (error) => {
|
|
122
|
+
if (!res.headersSent) res.writeHead(502, { "Content-Type": "text/plain; charset=utf-8" });
|
|
123
|
+
res.end(say(language, "unreachable", { platform, message: error.message }));
|
|
124
|
+
});
|
|
125
|
+
req.pipe(upstream);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Serves the example. `platform` is the platform's address; `token` gives the user's token at
|
|
130
|
+
* each sign-in; `dist` is where the library is, the package's own unless named.
|
|
131
|
+
*/
|
|
132
|
+
export function startExample({
|
|
133
|
+
platform,
|
|
134
|
+
token,
|
|
135
|
+
port = 8050,
|
|
136
|
+
insecure = false,
|
|
137
|
+
dist = join(here, "..", "dist"),
|
|
138
|
+
language = "zh-CN",
|
|
139
|
+
}) {
|
|
140
|
+
const server = createServer((req, res) => {
|
|
141
|
+
const path = new URL(req.url ?? "/", "http://page").pathname;
|
|
142
|
+
if (path === "/api" || path.startsWith("/api/"))
|
|
143
|
+
return pass(req, res, platform, insecure, language);
|
|
144
|
+
if (path === "/host/token") {
|
|
145
|
+
// The page's own sign-in stands here; a real page signs its user in its own way and gets
|
|
146
|
+
// them a token of the platform's.
|
|
147
|
+
return void token().then(
|
|
148
|
+
(value) => {
|
|
149
|
+
res.writeHead(200, {
|
|
150
|
+
"Content-Type": "application/json",
|
|
151
|
+
"Cache-Control": "no-store",
|
|
152
|
+
});
|
|
153
|
+
res.end(JSON.stringify({ token: value }));
|
|
154
|
+
},
|
|
155
|
+
(error) => {
|
|
156
|
+
res.writeHead(503, { "Content-Type": "text/plain; charset=utf-8" });
|
|
157
|
+
res.end(error.message);
|
|
158
|
+
},
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
if (req.method !== "GET" && req.method !== "HEAD") return void res.writeHead(405).end();
|
|
162
|
+
if (PAGE[path]) return void sendFile(res, join(here, PAGE[path]));
|
|
163
|
+
const file = path.startsWith("/workshop/")
|
|
164
|
+
? within(dist, path.slice("/workshop/".length))
|
|
165
|
+
: undefined;
|
|
166
|
+
if (file) return void sendFile(res, file);
|
|
167
|
+
res.writeHead(404).end();
|
|
168
|
+
});
|
|
169
|
+
return new Promise((resolve, reject) => {
|
|
170
|
+
server.once("error", reject);
|
|
171
|
+
server.listen(port, "127.0.0.1", () => resolve(server));
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** Runs openbkn with these arguments and gives what it prints. */
|
|
176
|
+
function openbkn(args, language) {
|
|
177
|
+
return new Promise((resolve, reject) =>
|
|
178
|
+
execFile(
|
|
179
|
+
"openbkn",
|
|
180
|
+
args,
|
|
181
|
+
{ shell: process.platform === "win32", timeout: 60_000 },
|
|
182
|
+
(error, stdout, stderr) => {
|
|
183
|
+
if (!error) return resolve(stdout.trim());
|
|
184
|
+
if (error.code === "ENOENT")
|
|
185
|
+
return reject(new Error(say(language, "noOpenbkn")));
|
|
186
|
+
const reason = (stderr || error.message).trim();
|
|
187
|
+
reject(new Error(say(language, "openbknFailed", { args: args.join(" "), reason })));
|
|
188
|
+
},
|
|
189
|
+
),
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const trimmed = (url) => url.trim().replace(/\/+$/, "");
|
|
194
|
+
|
|
195
|
+
/** The platform and how to get the user's token, as the workshop command finds them. */
|
|
196
|
+
async function connection(env, language) {
|
|
197
|
+
const named = env.BKN_BASE_URL ? trimmed(env.BKN_BASE_URL) : undefined;
|
|
198
|
+
const fixed = env.BKN_TOKEN?.trim();
|
|
199
|
+
if (fixed) {
|
|
200
|
+
if (!named) throw new Error(say(language, "tokenWithoutBase"));
|
|
201
|
+
return { platform: named, token: async () => fixed };
|
|
202
|
+
}
|
|
203
|
+
const status = JSON.parse(await openbkn(["auth", "status"], language));
|
|
204
|
+
const active = status.baseUrl ? trimmed(status.baseUrl) : undefined;
|
|
205
|
+
if (!active) throw new Error(say(language, "notLoggedIn"));
|
|
206
|
+
if (named && named !== active) throw new Error(say(language, "otherLogin", { active, named }));
|
|
207
|
+
// Asked at each sign-in: the command line renews it once it runs out.
|
|
208
|
+
return { platform: active, token: () => openbkn(["auth", "token"], language) };
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
async function main() {
|
|
212
|
+
const { values } = parseArgs({
|
|
213
|
+
options: {
|
|
214
|
+
port: { type: "string", default: "8050" },
|
|
215
|
+
insecure: { type: "boolean", short: "k", default: false },
|
|
216
|
+
lang: { type: "string" },
|
|
217
|
+
help: { type: "boolean", short: "h", default: false },
|
|
218
|
+
},
|
|
219
|
+
});
|
|
220
|
+
const language = languageOf(values.lang);
|
|
221
|
+
if (values.help) {
|
|
222
|
+
console.log(say(language, "usage"));
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
const port = Number(values.port);
|
|
226
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535)
|
|
227
|
+
throw new Error(say(language, "badPort", { port: values.port }));
|
|
228
|
+
const { platform, token } = await connection(process.env, language);
|
|
229
|
+
await startExample({ platform, token, port, insecure: values.insecure, language });
|
|
230
|
+
console.log(say(language, "started", { port, platform }));
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href)
|
|
234
|
+
main().catch((error) => {
|
|
235
|
+
console.error(error.message);
|
|
236
|
+
process.exit(1);
|
|
237
|
+
});
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Copyright openbkn.ai. All rights reserved.
|
|
2
|
+
// Proprietary — OpenBKN Enterprise Edition. See LICENSE in the repository root.
|
|
3
|
+
|
|
4
|
+
// The public face of src/workshop-app.tsx. Kept by hand; src/workshop-app.types.test.ts fails the
|
|
5
|
+
// type check when the two part.
|
|
6
|
+
|
|
7
|
+
/** One of Workshop's pages. */
|
|
8
|
+
export type WorkshopPlace =
|
|
9
|
+
| { page: "apps" }
|
|
10
|
+
| { page: "builder" | "run" | "preview"; appId: string };
|
|
11
|
+
|
|
12
|
+
export type WorkshopLocale = "zh-CN" | "en-US";
|
|
13
|
+
|
|
14
|
+
export type WorkshopOptions = {
|
|
15
|
+
/** The gateway's address for requests, such as /api or https://host/api. */
|
|
16
|
+
apiBase: string;
|
|
17
|
+
/** The user's access token now; asked at each request. */
|
|
18
|
+
getToken: () => string | null;
|
|
19
|
+
/** A new token when the platform refuses the current one; without it the refusal stands. */
|
|
20
|
+
refreshToken?: () => Promise<string | null>;
|
|
21
|
+
user?: { id?: string; name?: string };
|
|
22
|
+
locale?: WorkshopLocale;
|
|
23
|
+
/** The page shown first; the app list unless named. */
|
|
24
|
+
place?: WorkshopPlace;
|
|
25
|
+
/** Workshop moved to another of its pages, by a click inside it. */
|
|
26
|
+
onNavigate?: (place: WorkshopPlace) => void;
|
|
27
|
+
/** A place's address in the page, for links and new windows; without it links lead nowhere. */
|
|
28
|
+
href?: (place: WorkshopPlace) => string;
|
|
29
|
+
/**
|
|
30
|
+
* How many rule-tool calls a page may have out at once: as many as the platform's sandbox
|
|
31
|
+
* runs side by side. A whole number from 1 to 10; 3 when left out or out of range.
|
|
32
|
+
*/
|
|
33
|
+
ruleConcurrency?: number;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type WorkshopHandle = {
|
|
37
|
+
/** Shows another of Workshop's pages, as the page's own address changed. */
|
|
38
|
+
show(place: WorkshopPlace): void;
|
|
39
|
+
/** Speaks another language where it is, as the page's own language changed. */
|
|
40
|
+
setLocale(locale: WorkshopLocale): void;
|
|
41
|
+
unmount(): void;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Renders Workshop into `container`. The platform is reached at `apiBase` with the token
|
|
46
|
+
* `getToken` returns; one page holds one Workshop.
|
|
47
|
+
*/
|
|
48
|
+
export function mountWorkshop(container: HTMLElement, options: WorkshopOptions): WorkshopHandle;
|
package/lib/validate.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// The checks a component package must pass, as Workshop runs them on upload: the manifest, the
|
|
5
5
|
// config schema's subset, the entry and the files. See the custom component spec, sections 3 and 6.
|
|
6
6
|
|
|
7
|
+
import { spawnSync } from "node:child_process";
|
|
7
8
|
import { readdirSync, readFileSync, statSync } from "node:fs";
|
|
8
9
|
import { extname, join, posix, relative, sep } from "node:path";
|
|
9
10
|
|
|
@@ -57,6 +58,8 @@ const TEXT = {
|
|
|
57
58
|
noElement: "入口中没有定义自定义元素 {element}",
|
|
58
59
|
bigEntry: "入口超过 300 KB:首屏不需要的部分建议拆成分块",
|
|
59
60
|
remoteScript: "{name} 从外部地址加载脚本:依赖须全部打进包里",
|
|
61
|
+
syntax: "{name} 第 {line} 行有语法错误,浏览器加载不了:{message}",
|
|
62
|
+
syntaxOldNode: "{name} 第 {line} 行在本机 Node {node} 下解析不了:{message}。Node 24 以前的版本不认识部分新语法,上传时以 Workshop 的检查为准;用 Node 24 及以上校验才能确定",
|
|
60
63
|
evalUsed: "{name} 用了 eval 或 new Function:内容安全策略下会被拒绝",
|
|
61
64
|
noReadme: "没有 README.md:每个组件都应附说明(本体契约、扩展点、场景配方)",
|
|
62
65
|
noPreview: "没有 preview.json:组件库预览与本地开发都需要示例数据",
|
|
@@ -90,6 +93,8 @@ const TEXT = {
|
|
|
90
93
|
noElement: "The entry does not define the custom element {element}",
|
|
91
94
|
bigEntry: "The entry is over 300 KB: split what the first screen does not need into chunks",
|
|
92
95
|
remoteScript: "{name} loads a script from an outside address: bundle every dependency into the package",
|
|
96
|
+
syntax: "{name} has a syntax error at line {line}, so the browser cannot load it: {message}",
|
|
97
|
+
syntaxOldNode: "{name} does not parse at line {line} under this Node {node}: {message}. Node before 24 does not know some newer syntax, and the upload check decides; validate with Node 24 or later to be sure",
|
|
93
98
|
evalUsed: "{name} uses eval or new Function, which the content security policy refuses",
|
|
94
99
|
noReadme: "No README.md: every component should come with a guide (ontology contract, extension points, recipes)",
|
|
95
100
|
noPreview: "No preview.json: the component library's preview and local development both need sample data",
|
|
@@ -242,11 +247,48 @@ export function manifestErrors(manifest, language = "zh-CN") {
|
|
|
242
247
|
return errors;
|
|
243
248
|
}
|
|
244
249
|
|
|
250
|
+
/**
|
|
251
|
+
* The first Node whose parser knows what browsers and the upload check accept: Node 22 refuses
|
|
252
|
+
* `using` declarations and regular expression modifiers such as (?i:), which both take. Under
|
|
253
|
+
* an older Node a script that does not parse is a warning, as the upload may still take it,
|
|
254
|
+
* unless the error is one no newer syntax explains.
|
|
255
|
+
*/
|
|
256
|
+
export const SYNTAX_NODE_MAJOR = 24;
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Syntax errors no newer syntax explains: every Node reports them alike, and the upload refuses
|
|
260
|
+
* them, so under an older Node they still fail the package. A private field the class never
|
|
261
|
+
* declared is one (bkn-studio#1485).
|
|
262
|
+
*/
|
|
263
|
+
const SYNTAX_ERRORS_ON_ANY_NODE = [
|
|
264
|
+
/^Private field '#[^']+' must be declared in an enclosing class$/,
|
|
265
|
+
/^Identifier '[^']+' has already been declared$/,
|
|
266
|
+
/^Unexpected end of input$/,
|
|
267
|
+
/^Strict mode code may not include a with statement$/,
|
|
268
|
+
/^Octal literals are not allowed in strict mode\.$/,
|
|
269
|
+
];
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* The syntax error that stops a script loading, or null. The frame imports scripts as ES modules,
|
|
273
|
+
* so this parses them as one, by the Node running the kit: a private field the class never
|
|
274
|
+
* declared otherwise passed and then failed in every page (bkn-studio#1485). The code goes in on
|
|
275
|
+
* standard input: given a .js path, Node can take a module's syntax error for a CommonJS one and
|
|
276
|
+
* pass it.
|
|
277
|
+
*/
|
|
278
|
+
export function syntaxError(code) {
|
|
279
|
+
const parsed = spawnSync(process.execPath, ["--input-type=module", "--check"], { input: code, encoding: "utf8" });
|
|
280
|
+
if (parsed.status === 0) return null;
|
|
281
|
+
const output = `${parsed.stderr ?? ""}${parsed.error?.message ?? ""}`;
|
|
282
|
+
const line = Number(/^\[stdin\]:(\d+)/m.exec(output)?.[1] ?? 0);
|
|
283
|
+
const message = /^\w*Error: (.+)$/m.exec(output)?.[1] ?? output.trim().split("\n").at(-1);
|
|
284
|
+
return { line, message };
|
|
285
|
+
}
|
|
286
|
+
|
|
245
287
|
/**
|
|
246
288
|
* The whole package in a directory: its manifest, files and entry. Errors stop an upload;
|
|
247
289
|
* warnings are what the spec asks for and an upload does not check.
|
|
248
290
|
*/
|
|
249
|
-
export function validatePackage(dir, { language = "zh-CN" } = {}) {
|
|
291
|
+
export function validatePackage(dir, { language = "zh-CN", nodeMajor = Number(process.versions.node.split(".")[0]) } = {}) {
|
|
250
292
|
const say = wordsOf(language);
|
|
251
293
|
const errors = [];
|
|
252
294
|
const warnings = [];
|
|
@@ -277,6 +319,10 @@ export function validatePackage(dir, { language = "zh-CN" } = {}) {
|
|
|
277
319
|
}
|
|
278
320
|
for (const file of files.filter((f) => /\.(m?js)$/.test(f.name))) {
|
|
279
321
|
const code = readFileSync(file.path, "utf8");
|
|
322
|
+
const broken = syntaxError(code);
|
|
323
|
+
const certain = broken && SYNTAX_ERRORS_ON_ANY_NODE.some((known) => known.test(broken.message));
|
|
324
|
+
if (broken && (nodeMajor >= SYNTAX_NODE_MAJOR || certain)) errors.push(say("syntax", { name: file.name, ...broken }));
|
|
325
|
+
else if (broken) warnings.push(say("syntaxOldNode", { name: file.name, node: process.versions.node, ...broken }));
|
|
280
326
|
if (/import\s*\(\s*["'`]https?:\/\//.test(code) || /from\s+["']https?:\/\//.test(code))
|
|
281
327
|
errors.push(say("remoteScript", { name: file.name }));
|
|
282
328
|
if (/\beval\s*\(|new\s+Function\s*\(/.test(code))
|
package/package.json
CHANGED
|
@@ -1,26 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openbkn/workshop",
|
|
3
|
-
"version": "0.2.2
|
|
4
|
-
"description": "OpenBKN Workshop
|
|
3
|
+
"version": "0.2.2",
|
|
4
|
+
"description": "OpenBKN Workshop outside the Studio: mount the app list, the builder and running apps into a page; develop apps in an IDE (workshop); develop, check and pack custom components (workshop-component).",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "git+https://github.com/openbkn-ai/openbkn-ee.git",
|
|
9
9
|
"directory": "studio/packages/workshop"
|
|
10
10
|
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
11
14
|
"type": "module",
|
|
12
15
|
"bin": {
|
|
13
16
|
"workshop": "./workshop.js",
|
|
14
17
|
"workshop-component": "./workshop-component.js"
|
|
15
18
|
},
|
|
16
19
|
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./index.d.ts",
|
|
22
|
+
"import": "./dist/workshop-app.js"
|
|
23
|
+
},
|
|
17
24
|
"./component": {
|
|
18
25
|
"types": "./component.d.ts"
|
|
19
26
|
},
|
|
27
|
+
"./style.css": "./dist/workshop-app.css",
|
|
20
28
|
"./package.json": "./package.json"
|
|
21
29
|
},
|
|
30
|
+
"types": "./index.d.ts",
|
|
22
31
|
"files": [
|
|
32
|
+
"dist",
|
|
23
33
|
"dist-cli",
|
|
34
|
+
"example",
|
|
35
|
+
"index.d.ts",
|
|
24
36
|
"component.d.ts",
|
|
25
37
|
"workshop.js",
|
|
26
38
|
"workshop-component.js",
|
|
@@ -30,13 +42,13 @@
|
|
|
30
42
|
"skill",
|
|
31
43
|
"README.md"
|
|
32
44
|
],
|
|
45
|
+
"sideEffects": [
|
|
46
|
+
"./dist/workshop-app.css"
|
|
47
|
+
],
|
|
33
48
|
"engines": {
|
|
34
49
|
"node": ">=20"
|
|
35
50
|
},
|
|
36
51
|
"scripts": {
|
|
37
52
|
"test": "node --test \"test/*.test.js\""
|
|
38
|
-
},
|
|
39
|
-
"publishConfig": {
|
|
40
|
-
"access": "public"
|
|
41
53
|
}
|
|
42
54
|
}
|
package/runtime/frame-runtime.js
CHANGED
|
@@ -13,6 +13,11 @@ let seq = 0;
|
|
|
13
13
|
const pending = new Map();
|
|
14
14
|
// Properties that came before the element was defined.
|
|
15
15
|
const latest = {};
|
|
16
|
+
// Each property as last set, as text. The host sends every property again when any one of them
|
|
17
|
+
// changes; one whose value is the same is not set again, so a component's setter runs only when
|
|
18
|
+
// its own property changed (a component that loads data when its config is set would otherwise
|
|
19
|
+
// load it again on every filter or date change).
|
|
20
|
+
const sent = {};
|
|
16
21
|
|
|
17
22
|
const THEME_VARS = {
|
|
18
23
|
colorPrimary: "--workshop-color-primary",
|
|
@@ -53,7 +58,14 @@ const workshop = Object.freeze({
|
|
|
53
58
|
},
|
|
54
59
|
});
|
|
55
60
|
|
|
56
|
-
function applyProps(
|
|
61
|
+
function applyProps(all) {
|
|
62
|
+
const props = {};
|
|
63
|
+
for (const [key, value] of Object.entries(all)) {
|
|
64
|
+
const text = JSON.stringify(value);
|
|
65
|
+
if (key in sent && sent[key] === text) continue;
|
|
66
|
+
sent[key] = text;
|
|
67
|
+
props[key] = value;
|
|
68
|
+
}
|
|
57
69
|
Object.assign(latest, props);
|
|
58
70
|
if (props.theme) {
|
|
59
71
|
const root = document.documentElement.style;
|