@panyam/tsappkit 0.0.4 → 0.1.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/docs/DocsPage.css +8 -6
- package/dist/docs/DocsPage.css.map +1 -1
- package/dist/docs/DocsPage.min.css +1 -1
- package/dist/docs/DocsPage.min.css.map +1 -1
- package/dist/index.d.mts +88 -1
- package/dist/index.d.ts +88 -1
- package/dist/index.js +91 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +88 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -3
- package/src/index.ts +7 -0
- package/src/page/IslandPage.test.ts +83 -0
- package/src/page/IslandPage.ts +49 -0
- package/src/page/mount.test.ts +73 -0
- package/src/page/mount.ts +54 -0
- package/src/page/spec.test.ts +65 -0
- package/src/page/spec.ts +79 -0
- package/styles/docs/_content.scss +6 -6
- package/styles/docs/_variables.scss +2 -0
package/dist/index.mjs
CHANGED
|
@@ -1371,6 +1371,93 @@ var MobileBottomDrawer = class extends BaseComponent {
|
|
|
1371
1371
|
}
|
|
1372
1372
|
};
|
|
1373
1373
|
|
|
1374
|
+
// src/page/mount.ts
|
|
1375
|
+
function mountIslands(spec, registry, findSlot, context, bus, log) {
|
|
1376
|
+
const out = [];
|
|
1377
|
+
let ctx;
|
|
1378
|
+
for (const island of spec.islands) {
|
|
1379
|
+
const factory = Object.prototype.hasOwnProperty.call(registry, island.name) ? registry[island.name] : void 0;
|
|
1380
|
+
if (!factory) {
|
|
1381
|
+
log(`page spec: no island called "${island.name}" in this page's registry`);
|
|
1382
|
+
continue;
|
|
1383
|
+
}
|
|
1384
|
+
const el = findSlot(island.slot);
|
|
1385
|
+
if (el === null) {
|
|
1386
|
+
log(`page spec: island "${island.name}" wants slot "${island.slot}", which isn't on the page`);
|
|
1387
|
+
continue;
|
|
1388
|
+
}
|
|
1389
|
+
try {
|
|
1390
|
+
ctx ?? (ctx = context());
|
|
1391
|
+
out.push(factory(el, island, ctx, bus));
|
|
1392
|
+
} catch (err) {
|
|
1393
|
+
log(`page spec: island "${island.name}" failed to mount: ${err instanceof Error ? err.message : String(err)}`);
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
return out;
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
// src/page/spec.ts
|
|
1400
|
+
var SPEC_ELEMENT_ID = "page-spec";
|
|
1401
|
+
var SLOT = /^[a-z][a-z0-9-]*$/;
|
|
1402
|
+
function readSpec(text, extend) {
|
|
1403
|
+
if (!text) return null;
|
|
1404
|
+
let raw;
|
|
1405
|
+
try {
|
|
1406
|
+
raw = JSON.parse(text);
|
|
1407
|
+
} catch {
|
|
1408
|
+
return null;
|
|
1409
|
+
}
|
|
1410
|
+
if (!isObject(raw) || typeof raw.layout !== "string" || !Array.isArray(raw.islands)) return null;
|
|
1411
|
+
const islands = [];
|
|
1412
|
+
for (const is of raw.islands) {
|
|
1413
|
+
if (!isObject(is) || typeof is.name !== "string" || !is.name || typeof is.slot !== "string" || !SLOT.test(is.slot)) continue;
|
|
1414
|
+
islands.push({
|
|
1415
|
+
name: is.name,
|
|
1416
|
+
slot: is.slot,
|
|
1417
|
+
...typeof is.presentation === "string" && { presentation: is.presentation },
|
|
1418
|
+
config: isObject(is.config) ? is.config : {}
|
|
1419
|
+
});
|
|
1420
|
+
}
|
|
1421
|
+
const spec = { layout: raw.layout, islands };
|
|
1422
|
+
if (!extend) return spec;
|
|
1423
|
+
let ext;
|
|
1424
|
+
try {
|
|
1425
|
+
ext = extend(raw);
|
|
1426
|
+
} catch {
|
|
1427
|
+
return null;
|
|
1428
|
+
}
|
|
1429
|
+
return { ...ext, ...spec };
|
|
1430
|
+
}
|
|
1431
|
+
function isObject(v) {
|
|
1432
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1435
|
+
// src/page/IslandPage.ts
|
|
1436
|
+
var IslandPage = class extends BasePage {
|
|
1437
|
+
/**
|
|
1438
|
+
* The app's own fields from the parsed spec. The default reads none.
|
|
1439
|
+
* Throwing makes the spec unreadable, so nothing mounts.
|
|
1440
|
+
*/
|
|
1441
|
+
readExtension(raw) {
|
|
1442
|
+
return {};
|
|
1443
|
+
}
|
|
1444
|
+
initializeSpecificComponents() {
|
|
1445
|
+
const spec = readSpec(document.getElementById(SPEC_ELEMENT_ID)?.textContent, (raw) => this.readExtension(raw));
|
|
1446
|
+
if (!spec) {
|
|
1447
|
+
console.warn(`page spec: no readable #${SPEC_ELEMENT_ID} on this page, so nothing is mounted`);
|
|
1448
|
+
return [];
|
|
1449
|
+
}
|
|
1450
|
+
return mountIslands(
|
|
1451
|
+
spec,
|
|
1452
|
+
this.registry(),
|
|
1453
|
+
(slot) => document.querySelector(`[data-slot="${slot}"]`),
|
|
1454
|
+
() => this.makeContext(spec),
|
|
1455
|
+
this.eventBus,
|
|
1456
|
+
(message) => console.warn(message)
|
|
1457
|
+
);
|
|
1458
|
+
}
|
|
1459
|
+
};
|
|
1460
|
+
|
|
1374
1461
|
// src/DOMUtils.ts
|
|
1375
1462
|
function isInInputContext(element) {
|
|
1376
1463
|
if (!element) return false;
|
|
@@ -1713,6 +1800,6 @@ var KeyboardShortcutManager = class {
|
|
|
1713
1800
|
}
|
|
1714
1801
|
};
|
|
1715
1802
|
|
|
1716
|
-
export { BaseComponent, BasePage, ComponentEventTypes, EventBus, KeyboardShortcutManager, KeyboardState, LifecycleController, LifecycleEventTypes, MobileBottomDrawer, Modal, SplashScreen, TemplateLoader, ThemeManager, ToastManager, hasModifierKeys, isInInputContext, shouldIgnoreShortcut };
|
|
1803
|
+
export { BaseComponent, BasePage, ComponentEventTypes, EventBus, IslandPage, KeyboardShortcutManager, KeyboardState, LifecycleController, LifecycleEventTypes, MobileBottomDrawer, Modal, SPEC_ELEMENT_ID, SplashScreen, TemplateLoader, ThemeManager, ToastManager, hasModifierKeys, isInInputContext, mountIslands, readSpec, shouldIgnoreShortcut };
|
|
1717
1804
|
//# sourceMappingURL=index.mjs.map
|
|
1718
1805
|
//# sourceMappingURL=index.mjs.map
|