@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/README.md CHANGED
@@ -28,12 +28,10 @@ On the client you can then render each of those islands. They'll automatically h
28
28
  ```
29
29
  // index.ts
30
30
  import * as islands from "./islands";
31
+ import { hydrateIslands } from "@wrdagency/react-islands";
31
32
 
32
- const isDev = (process.env.NODE_ENV || "development").trim() === "development";
33
+ hydrateIslands( islands );
33
34
 
34
- for (const island of Object.values(islands)) {
35
- island.render({ hydrate: !isDev });
36
- }
37
35
  ```
38
36
 
39
37
  Create a pre-render script. You can configure your build tool to use this as a seperate entrypoint.
package/dist/index.d.mts CHANGED
@@ -1,12 +1,40 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
1
  import { FC } from 'react';
3
- import { I as IslandOpts, a as Island } from './types-Dn7YlQVB.mjs';
2
+ import { I as Island, a as IslandOpts } from './types-BWtowKeL.mjs';
4
3
 
5
- declare function createIsland(component: FC, opts: IslandOpts): Island;
4
+ /**
5
+ * Create a higher-order component with certain fixed.
6
+ *
7
+ * Useful for quickly creating multiple variants of the same component to use as islands.
8
+ *
9
+ * @param component FC<T>
10
+ * @param setProps Partial<T>
11
+ * @returns FC<T>
12
+ */
6
13
  declare function withProps<T>(component: FC<T>, setProps: Partial<T>): FC<T>;
14
+ /**
15
+ * Render all Islands in a record.
16
+ *
17
+ * Useful if you are importing * from an islands directory.
18
+ *
19
+ * @param islands Record<string, Island>
20
+ */
21
+ declare function hydrateIslands(islands: Record<string, Island>): void;
22
+
23
+ /**
24
+ * Create a React Island.
25
+ *
26
+ * You can render the island using the Island.render function.
27
+ *
28
+ * @param component React.FC
29
+ * @param opts IslandOpts
30
+ * @returns Island
31
+ */
32
+ declare function createIsland(component: FC, opts: IslandOpts): Island;
33
+ /**
34
+ * Checks if the current script is running in a pre-render.
35
+ *
36
+ * @returns boolean
37
+ */
7
38
  declare function isServer(): boolean;
8
- declare function RawHTML({ html }: {
9
- html: string;
10
- }): react_jsx_runtime.JSX.Element;
11
39
 
12
- export { Island, RawHTML, createIsland, isServer, withProps };
40
+ export { Island, createIsland, hydrateIslands, isServer, withProps };
package/dist/index.d.ts CHANGED
@@ -1,12 +1,40 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
1
  import { FC } from 'react';
3
- import { I as IslandOpts, a as Island } from './types-Dn7YlQVB.js';
2
+ import { I as Island, a as IslandOpts } from './types-BWtowKeL.js';
4
3
 
5
- declare function createIsland(component: FC, opts: IslandOpts): Island;
4
+ /**
5
+ * Create a higher-order component with certain fixed.
6
+ *
7
+ * Useful for quickly creating multiple variants of the same component to use as islands.
8
+ *
9
+ * @param component FC<T>
10
+ * @param setProps Partial<T>
11
+ * @returns FC<T>
12
+ */
6
13
  declare function withProps<T>(component: FC<T>, setProps: Partial<T>): FC<T>;
14
+ /**
15
+ * Render all Islands in a record.
16
+ *
17
+ * Useful if you are importing * from an islands directory.
18
+ *
19
+ * @param islands Record<string, Island>
20
+ */
21
+ declare function hydrateIslands(islands: Record<string, Island>): void;
22
+
23
+ /**
24
+ * Create a React Island.
25
+ *
26
+ * You can render the island using the Island.render function.
27
+ *
28
+ * @param component React.FC
29
+ * @param opts IslandOpts
30
+ * @returns Island
31
+ */
32
+ declare function createIsland(component: FC, opts: IslandOpts): Island;
33
+ /**
34
+ * Checks if the current script is running in a pre-render.
35
+ *
36
+ * @returns boolean
37
+ */
7
38
  declare function isServer(): boolean;
8
- declare function RawHTML({ html }: {
9
- html: string;
10
- }): react_jsx_runtime.JSX.Element;
11
39
 
12
- export { Island, RawHTML, createIsland, isServer, withProps };
40
+ export { Island, createIsland, hydrateIslands, isServer, withProps };
package/dist/index.js CHANGED
@@ -1777,39 +1777,17 @@ var require_jsx_runtime = __commonJS({
1777
1777
  // src/index.tsx
1778
1778
  var src_exports = {};
1779
1779
  __export(src_exports, {
1780
- RawHTML: () => RawHTML,
1781
1780
  createIsland: () => createIsland,
1781
+ hydrateIslands: () => hydrateIslands,
1782
1782
  isServer: () => isServer,
1783
1783
  withProps: () => withProps
1784
1784
  });
1785
1785
  module.exports = __toCommonJS(src_exports);
1786
+
1787
+ // src/render.tsx
1786
1788
  var import_react = __toESM(require_react());
1787
1789
  var import_client = require("react-dom/client");
1788
1790
  var import_jsx_runtime = __toESM(require_jsx_runtime());
1789
- function createIsland(component, opts) {
1790
- const mergedOpts = __spreadValues({
1791
- multiple: false,
1792
- selector: `[data-hydrate="${opts.name}"]`,
1793
- keepChildren: false
1794
- }, opts);
1795
- const island = {
1796
- type: "island",
1797
- component,
1798
- opts: mergedOpts,
1799
- render(opts2) {
1800
- renderIsland(this, opts2);
1801
- }
1802
- };
1803
- return island;
1804
- }
1805
- function withProps(component, setProps) {
1806
- return (props) => {
1807
- return component(__spreadValues(__spreadValues({}, props), setProps));
1808
- };
1809
- }
1810
- function isServer() {
1811
- return !(typeof window != "undefined" && window.document);
1812
- }
1813
1791
  function RawHTML({ html }) {
1814
1792
  const ref = (0, import_react.useRef)(null);
1815
1793
  (0, import_react.useEffect)(() => {
@@ -1819,6 +1797,11 @@ function RawHTML({ html }) {
1819
1797
  }, []);
1820
1798
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("script", { ref });
1821
1799
  }
1800
+ function withProps(component, setProps) {
1801
+ return (props) => {
1802
+ return component(__spreadValues(__spreadValues({}, props), setProps));
1803
+ };
1804
+ }
1822
1805
  function renderIsland(island, renderOpts = {}) {
1823
1806
  const { component, opts } = island;
1824
1807
  const { selector, multiple, keepChildren } = opts;
@@ -1869,10 +1852,37 @@ function renderIsland(island, renderOpts = {}) {
1869
1852
  }
1870
1853
  }
1871
1854
  }
1855
+ function hydrateIslands(islands) {
1856
+ const isDev = (process.env.NODE_ENV || "development").trim() === "development";
1857
+ for (const island of Object.values(islands)) {
1858
+ island.render({ hydrate: !isDev });
1859
+ }
1860
+ }
1861
+
1862
+ // src/index.tsx
1863
+ function createIsland(component, opts) {
1864
+ const mergedOpts = __spreadValues({
1865
+ multiple: false,
1866
+ selector: `[data-hydrate="${opts.name}"]`,
1867
+ keepChildren: false
1868
+ }, opts);
1869
+ const island = {
1870
+ type: "island",
1871
+ component,
1872
+ opts: mergedOpts,
1873
+ render(opts2) {
1874
+ renderIsland(this, opts2);
1875
+ }
1876
+ };
1877
+ return island;
1878
+ }
1879
+ function isServer() {
1880
+ return !(typeof window != "undefined" && window.document);
1881
+ }
1872
1882
  // Annotate the CommonJS export names for ESM import in node:
1873
1883
  0 && (module.exports = {
1874
- RawHTML,
1875
1884
  createIsland,
1885
+ hydrateIslands,
1876
1886
  isServer,
1877
1887
  withProps
1878
1888
  });