@wrdagency/react-islands 0.1.2 → 0.2.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/index.mjs CHANGED
@@ -1768,34 +1768,10 @@ var require_jsx_runtime = __commonJS({
1768
1768
  }
1769
1769
  });
1770
1770
 
1771
- // src/index.tsx
1771
+ // src/render.tsx
1772
1772
  var import_react = __toESM(require_react());
1773
1773
  import { createRoot, hydrateRoot } from "react-dom/client";
1774
1774
  var import_jsx_runtime = __toESM(require_jsx_runtime());
1775
- function createIsland(component, opts) {
1776
- const mergedOpts = __spreadValues({
1777
- multiple: false,
1778
- selector: `[data-hydrate="${opts.name}"]`,
1779
- keepChildren: false
1780
- }, opts);
1781
- const island = {
1782
- type: "island",
1783
- component,
1784
- opts: mergedOpts,
1785
- render(opts2) {
1786
- renderIsland(this, opts2);
1787
- }
1788
- };
1789
- return island;
1790
- }
1791
- function withProps(component, setProps) {
1792
- return (props) => {
1793
- return component(__spreadValues(__spreadValues({}, props), setProps));
1794
- };
1795
- }
1796
- function isServer() {
1797
- return !(typeof window != "undefined" && window.document);
1798
- }
1799
1775
  function RawHTML({ html }) {
1800
1776
  const ref = (0, import_react.useRef)(null);
1801
1777
  (0, import_react.useEffect)(() => {
@@ -1805,6 +1781,11 @@ function RawHTML({ html }) {
1805
1781
  }, []);
1806
1782
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("script", { ref });
1807
1783
  }
1784
+ function withProps(component, setProps) {
1785
+ return (props) => {
1786
+ return component(__spreadValues(__spreadValues({}, props), setProps));
1787
+ };
1788
+ }
1808
1789
  function renderIsland(island, renderOpts = {}) {
1809
1790
  const { component, opts } = island;
1810
1791
  const { selector, multiple, keepChildren } = opts;
@@ -1855,9 +1836,36 @@ function renderIsland(island, renderOpts = {}) {
1855
1836
  }
1856
1837
  }
1857
1838
  }
1839
+ function hydrateIslands(islands) {
1840
+ const isDev = (process.env.NODE_ENV || "development").trim() === "development";
1841
+ for (const island of Object.values(islands)) {
1842
+ island.render({ hydrate: !isDev });
1843
+ }
1844
+ }
1845
+
1846
+ // src/index.tsx
1847
+ function createIsland(component, opts) {
1848
+ const mergedOpts = __spreadValues({
1849
+ multiple: false,
1850
+ selector: `[data-hydrate="${opts.name}"]`,
1851
+ keepChildren: false
1852
+ }, opts);
1853
+ const island = {
1854
+ type: "island",
1855
+ component,
1856
+ opts: mergedOpts,
1857
+ render(opts2) {
1858
+ renderIsland(this, opts2);
1859
+ }
1860
+ };
1861
+ return island;
1862
+ }
1863
+ function isServer() {
1864
+ return !(typeof window != "undefined" && window.document);
1865
+ }
1858
1866
  export {
1859
- RawHTML,
1860
1867
  createIsland,
1868
+ hydrateIslands,
1861
1869
  isServer,
1862
1870
  withProps
1863
1871
  };