|
1722 | 1722 | } |
1723 | 1723 |
|
1724 | 1724 | /** |
1725 | | - * Binds author-HTML slot ids to registered region populators and/or table widgets. |
| 1725 | + * Binds author-HTML slot ids to registered region populators. |
1726 | 1726 | * |
1727 | | - * HTML ids are places. A string value is a registered populator name. A `{ table: url | inlineEnvelope }` |
1728 | | - * value mounts a table widget into that empty slot. The string `"juneau-table"` is not a populator and |
1729 | | - * throws. Missing element ids, blank names, unregistered populators, and unrecognized value shapes fail |
1730 | | - * loud and enrol nothing on the page - they do not skip the bad entry and they do not fall through to |
1731 | | - * defaultPopulate. |
| 1727 | + * HTML ids are places. A value is a registered populator name; tables mount as `<@card type="datatables">`, |
| 1728 | + * not through this call. Missing element ids, blank names, unregistered populators, and unrecognized value |
| 1729 | + * shapes fail loud and enrol nothing on the page - they do not skip the bad entry and they do not fall |
| 1730 | + * through to defaultPopulate. |
1732 | 1731 | * |
1733 | 1732 | * Region enrolment is synchronous through initRegion (populate has already run before the returned |
1734 | | - * thenable is handed back). Table entries are fetched/inited asynchronously. The return is a thenable |
1735 | | - * that resolves to the region-handle array (map-key order among region entries). A table fetch/handshake |
1736 | | - * failure paints a banner in that slot and does not unroll already-enrolled regions. |
| 1733 | + * thenable is handed back). The return is a thenable that resolves to the region-handle array (map-key |
| 1734 | + * order). |
1737 | 1735 | * |
1738 | 1736 | * Bus targeting `{to: slotId}` uses the slot id (the map key), which is the region id after mount. |
1739 | 1737 | * |
1740 | | - * @param {Object<string, string|{table: string|Object}>} hookup Map of element id → populator name or table binding. |
| 1738 | + * @param {Object<string, string>} hookup Map of element id → populator name. |
1741 | 1739 | * @returns {Promise<Array>} Thenable resolving to the region handles initRegion minted. |
1742 | 1740 | */ |
1743 | 1741 | function mount(hookup) { // NOSONAR javascript:S3776 -- encodes a views/widgets state machine; complexity is inherent |
|
1757 | 1755 | window.console.error(message); |
1758 | 1756 | throw new Error(message); |
1759 | 1757 | } |
1760 | | - if (value === "juneau-table") { |
1761 | | - const message = "JuneauViews.regions.mount: the string 'juneau-table' is not a populator; " |
1762 | | - + "use { table: url } (or an inline envelope) as the slot value."; |
1763 | | - window.console.error(message); |
1764 | | - throw new Error(message); |
1765 | | - } |
1766 | 1758 | if (typeof value === "string") { |
1767 | 1759 | const name = value; |
1768 | 1760 | if (blank(name)) { |
|
1779 | 1771 | planned.push({ kind: "region", el: el, id: id, name: name }); |
1780 | 1772 | continue; |
1781 | 1773 | } |
1782 | | - if (value != null && typeof value === "object" && !Array.isArray(value) && Object.hasOwn(value, "table")) { |
1783 | | - const table = value.table; |
1784 | | - if (typeof table === "string") { |
1785 | | - if (blank(table)) { |
1786 | | - const message = "JuneauViews.regions.mount: slot '" + id + "' has a blank or missing table URL."; |
1787 | | - window.console.error(message); |
1788 | | - throw new Error(message); |
1789 | | - } |
1790 | | - planned.push({ kind: "table", el: el, id: id, table: table }); |
1791 | | - continue; |
1792 | | - } |
1793 | | - if (table != null && typeof table === "object" && !Array.isArray(table)) { |
1794 | | - planned.push({ kind: "table", el: el, id: id, table: table }); |
1795 | | - continue; |
1796 | | - } |
1797 | | - } |
1798 | 1774 | const message = "JuneauViews.regions.mount: slot '" + id + "' has an unrecognized binding " |
1799 | | - + "(expected a populator name or { table: url | envelope })."; |
| 1775 | + + "(expected a populator name)."; |
1800 | 1776 | window.console.error(message); |
1801 | 1777 | throw new Error(message); |
1802 | 1778 | } |
1803 | 1779 | const handles = []; |
1804 | | - const tableJobs = []; |
1805 | | - for (const plannedItem of planned) { |
1806 | | - const item = plannedItem; |
1807 | | - if (item.kind === "region") { |
1808 | | - item.el.setAttribute(REGION_ATTR, item.id); |
1809 | | - item.el.setAttribute(REGION_POPULATE_ATTR, item.name); |
1810 | | - const handle = initRegion(item.el); |
1811 | | - if (handle) handles.push(handle); |
1812 | | - continue; |
1813 | | - } |
1814 | | - tableJobs.push(mountTableSlot(item.el, item.table)); |
| 1780 | + for (const item of planned) { |
| 1781 | + item.el.setAttribute(REGION_ATTR, item.id); |
| 1782 | + item.el.setAttribute(REGION_POPULATE_ATTR, item.name); |
| 1783 | + const handle = initRegion(item.el); |
| 1784 | + if (handle) handles.push(handle); |
1815 | 1785 | } |
1816 | | - const done = tableJobs.length ? Promise.all(tableJobs) : Promise.resolve(); |
1817 | | - return done.then(function () { return handles; }); |
1818 | | - } |
1819 | | - |
1820 | | - /** |
1821 | | - * Delegates table-slot construction to juneau-views.js. Fetch/handshake failures are swallowed here so |
1822 | | - * Promise.all still resolves (the views helper paints the slot banner). A missing helper is a banner + |
1823 | | - * console.error, not an unroll of already-enrolled regions. |
1824 | | - */ |
1825 | | - function mountTableSlot(slot, tableValue) { |
1826 | | - const init = window.JuneauViews?.init; |
1827 | | - if (!init || typeof init.mountTableSlot !== "function") { |
1828 | | - const message = "JuneauViews.regions.mount: table slots require JuneauViews.init.mountTableSlot."; |
1829 | | - window.console.error(message); |
1830 | | - paintMountBanner(slot, message); |
1831 | | - return Promise.resolve(); |
1832 | | - } |
1833 | | - return Promise.resolve() |
1834 | | - .then(function () { return init.mountTableSlot(slot, tableValue); }) |
1835 | | - .catch(function (err) { |
1836 | | - const message = String(err?.message ? err.message : err); |
1837 | | - window.console.error("JuneauViews.regions.mount: table slot failed: " + message); |
1838 | | - paintMountBanner(slot, message); |
1839 | | - }); |
1840 | | - } |
1841 | | - |
1842 | | - function paintMountBanner(slot, message) { |
1843 | | - if (!slot) return; |
1844 | | - slot.textContent = ""; |
1845 | | - const p = window.document.createElement("p"); |
1846 | | - p.className = "juneau-view-error"; |
1847 | | - p.textContent = message; |
1848 | | - slot.appendChild(p); |
| 1786 | + return Promise.resolve(handles); |
1849 | 1787 | } |
1850 | 1788 |
|
1851 | 1789 | // ================================================================================================================== |
|
0 commit comments