@puckeditor/plugin-pages 0.6.1-canary.a7fda263 → 0.6.1-canary.b858ddc5

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.css CHANGED
@@ -1837,12 +1837,12 @@ button._Menu-item_1tu16_55:hover {
1837
1837
  }
1838
1838
 
1839
1839
  /* css-module:/home/runner/work/puck-platform/puck-platform/packages/plugin-pages/src/components/HeaderActions/styles.module.css/#css-module-data */
1840
- ._HeaderActions_1dhws_1 {
1840
+ ._HeaderActions-publish_7nzbl_1 {
1841
1841
  position: relative;
1842
1842
  display: inline-flex;
1843
1843
  align-items: stretch;
1844
1844
  }
1845
- ._HeaderActions-trigger_1dhws_7 {
1845
+ ._HeaderActions-trigger_7nzbl_7 {
1846
1846
  display: inline-flex;
1847
1847
  align-items: center;
1848
1848
  justify-content: center;
@@ -1853,19 +1853,19 @@ button._Menu-item_1tu16_55:hover {
1853
1853
  background: var(--puck-color-white);
1854
1854
  color: var(--puck-color-grey-01);
1855
1855
  }
1856
- ._HeaderActions-versionHeader_1dhws_19 {
1856
+ ._HeaderActions-versionHeader_7nzbl_19 {
1857
1857
  align-items: center;
1858
1858
  display: flex;
1859
1859
  gap: 8px;
1860
1860
  height: 21px;
1861
1861
  }
1862
- ._HeaderActions-versionLabel_1dhws_26 {
1862
+ ._HeaderActions-versionLabel_7nzbl_26 {
1863
1863
  font-family: var(--puck-font-family-monospaced);
1864
1864
  font-size: var(--puck-font-size-xs);
1865
1865
  font-weight: 600;
1866
1866
  line-height: 1;
1867
1867
  }
1868
- ._HeaderActions-versionDate_1dhws_33 {
1868
+ ._HeaderActions-versionDate_7nzbl_33 {
1869
1869
  color: var(--puck-color-grey-06);
1870
1870
  font-size: var(--puck-font-size-xxxs);
1871
1871
  font-weight: 500;
@@ -0,0 +1,23 @@
1
+ import * as react from 'react';
2
+ import * as react_jsx_runtime from 'react/jsx-runtime';
3
+
4
+ type PagePluginOptions = {
5
+ host?: string;
6
+ siteId?: string;
7
+ parentOrigin?: string;
8
+ };
9
+
10
+ declare function createPagesPlugin(opts?: PagePluginOptions): {
11
+ label: string;
12
+ name: string;
13
+ render: () => react_jsx_runtime.JSX.Element;
14
+ icon: react_jsx_runtime.JSX.Element;
15
+ overrides: {
16
+ headerActions: () => react_jsx_runtime.JSX.Element;
17
+ preview: ({ children }: {
18
+ children: react.ReactNode;
19
+ }) => react_jsx_runtime.JSX.Element;
20
+ };
21
+ };
22
+
23
+ export { createPagesPlugin };
@@ -0,0 +1,23 @@
1
+ import * as react from 'react';
2
+ import * as react_jsx_runtime from 'react/jsx-runtime';
3
+
4
+ type PagePluginOptions = {
5
+ host?: string;
6
+ siteId?: string;
7
+ parentOrigin?: string;
8
+ };
9
+
10
+ declare function createPagesPlugin(opts?: PagePluginOptions): {
11
+ label: string;
12
+ name: string;
13
+ render: () => react_jsx_runtime.JSX.Element;
14
+ icon: react_jsx_runtime.JSX.Element;
15
+ overrides: {
16
+ headerActions: () => react_jsx_runtime.JSX.Element;
17
+ preview: ({ children }: {
18
+ children: react.ReactNode;
19
+ }) => react_jsx_runtime.JSX.Element;
20
+ };
21
+ };
22
+
23
+ export { createPagesPlugin };
package/dist/index.js CHANGED
@@ -107,8 +107,7 @@ var require_classnames = __commonJS({
107
107
  // index.ts
108
108
  var index_exports = {};
109
109
  __export(index_exports, {
110
- createPagesPlugin: () => createPagesPlugin,
111
- getPage: () => getPage
110
+ createPagesPlugin: () => createPagesPlugin
112
111
  });
113
112
  module.exports = __toCommonJS(index_exports);
114
113
  init_react_import();
@@ -4769,6 +4768,9 @@ var useModalVisible = (defaultVisible) => {
4769
4768
  const [visible, setVisible] = (0, import_react7.useState)(defaultVisible ?? false);
4770
4769
  const ref = (0, import_react7.useRef)(null);
4771
4770
  (0, import_react7.useEffect)(() => {
4771
+ if (!visible) {
4772
+ return;
4773
+ }
4772
4774
  const handler = (e2) => {
4773
4775
  if (ref.current && !ref.current.contains(e2.target)) {
4774
4776
  setVisible(false);
@@ -4778,7 +4780,7 @@ var useModalVisible = (defaultVisible) => {
4778
4780
  return () => {
4779
4781
  document.body.removeEventListener("click", handler);
4780
4782
  };
4781
- }, []);
4783
+ }, [visible]);
4782
4784
  return [visible, setVisible, ref];
4783
4785
  };
4784
4786
 
@@ -4915,8 +4917,10 @@ var Modal = ({
4915
4917
  !hideButton && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: getClassName3("button"), children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
4916
4918
  Button,
4917
4919
  {
4920
+ type: "button",
4918
4921
  variant: buttonVariant,
4919
- onClick: () => {
4922
+ onClick: (e2) => {
4923
+ e2.stopPropagation();
4920
4924
  setVisible(!visible);
4921
4925
  },
4922
4926
  children: actionLabel
@@ -29620,7 +29624,7 @@ var import_react26 = require("react");
29620
29624
 
29621
29625
  // css-module:/home/runner/work/puck-platform/puck-platform/packages/plugin-pages/src/components/HeaderActions/styles.module.css#css-module
29622
29626
  init_react_import();
29623
- var styles_module_default10 = { "HeaderActions": "_HeaderActions_1dhws_1", "HeaderActions-trigger": "_HeaderActions-trigger_1dhws_7", "HeaderActions-versionHeader": "_HeaderActions-versionHeader_1dhws_19", "HeaderActions-versionLabel": "_HeaderActions-versionLabel_1dhws_26", "HeaderActions-versionDate": "_HeaderActions-versionDate_1dhws_33" };
29627
+ var styles_module_default10 = { "HeaderActions-publish": "_HeaderActions-publish_7nzbl_1", "HeaderActions-trigger": "_HeaderActions-trigger_7nzbl_7", "HeaderActions-versionHeader": "_HeaderActions-versionHeader_7nzbl_19", "HeaderActions-versionLabel": "_HeaderActions-versionLabel_7nzbl_26", "HeaderActions-versionDate": "_HeaderActions-versionDate_7nzbl_33" };
29624
29628
 
29625
29629
  // src/components/HeaderActions/index.tsx
29626
29630
  var import_jsx_runtime51 = require("react/jsx-runtime");
@@ -29980,17 +29984,6 @@ var HeaderActions = (opts) => {
29980
29984
  title: "Unpublish page"
29981
29985
  };
29982
29986
  return /* @__PURE__ */ (0, import_jsx_runtime51.jsxs)(import_jsx_runtime51.Fragment, { children: [
29983
- /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(
29984
- ConfirmModal,
29985
- {
29986
- visible: confirmAction !== null,
29987
- onClose: () => setConfirmAction(null),
29988
- confirmLabel: confirmConfig.confirmLabel,
29989
- message: confirmConfig.message,
29990
- onConfirm: confirmConfig.onConfirm,
29991
- title: confirmConfig.title
29992
- }
29993
- ),
29994
29987
  canvasIsDirty ? /* @__PURE__ */ (0, import_jsx_runtime51.jsxs)(import_jsx_runtime51.Fragment, { children: [
29995
29988
  /* @__PURE__ */ (0, import_jsx_runtime51.jsxs)("div", { className: cx10("version"), children: [
29996
29989
  /* @__PURE__ */ (0, import_jsx_runtime51.jsx)("div", { className: cx10("versionHeader"), children: /* @__PURE__ */ (0, import_jsx_runtime51.jsx)("div", { className: cx10("versionLabel"), children: "Draft" }) }),
@@ -30020,7 +30013,7 @@ var HeaderActions = (opts) => {
30020
30013
  ] }),
30021
30014
  /* @__PURE__ */ (0, import_jsx_runtime51.jsx)("div", { className: cx10("versionDate"), children: currentVersion.createdAt ? format(currentVersion.createdAt, "MMM d yyy, HH:mm") : "" })
30022
30015
  ] }) }) : null,
30023
- /* @__PURE__ */ (0, import_jsx_runtime51.jsxs)("div", { className: cx10(), children: [
30016
+ /* @__PURE__ */ (0, import_jsx_runtime51.jsxs)("div", { className: cx10("publish"), children: [
30024
30017
  /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(
30025
30018
  Button,
30026
30019
  {
@@ -30057,6 +30050,17 @@ var HeaderActions = (opts) => {
30057
30050
  ],
30058
30051
  children: /* @__PURE__ */ (0, import_jsx_runtime51.jsx)("span", { className: cx10("trigger"), children: /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(ChevronDown, { size: 16 }) })
30059
30052
  }
30053
+ ),
30054
+ /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(
30055
+ ConfirmModal,
30056
+ {
30057
+ visible: confirmAction !== null,
30058
+ onClose: () => setConfirmAction(null),
30059
+ confirmLabel: confirmConfig.confirmLabel,
30060
+ message: confirmConfig.message,
30061
+ onConfirm: confirmConfig.onConfirm,
30062
+ title: confirmConfig.title
30063
+ }
30060
30064
  )
30061
30065
  ] })
30062
30066
  ] });
@@ -30096,110 +30100,9 @@ function createPagesPlugin(opts) {
30096
30100
  }
30097
30101
  };
30098
30102
  }
30099
-
30100
- // src/lib/get-page.ts
30101
- init_react_import();
30102
-
30103
- // api/view.ts
30104
- init_react_import();
30105
-
30106
- // api/lib/read-page.ts
30107
- init_react_import();
30108
-
30109
- // api/lib/transport.ts
30110
- init_react_import();
30111
-
30112
- // ../cloud-client/src/lib/get-api-key.ts
30113
- init_react_import();
30114
- var getApiKey = () => process.env.PUCK_API_KEY;
30115
-
30116
- // api/lib/transport.ts
30117
- var resolveRequestOptions = (options = {}) => {
30118
- const {
30119
- apiKey = getApiKey(),
30120
- host = "https://cloud.puckeditor.com/api",
30121
- token
30122
- } = options;
30123
- if (!apiKey && !token) {
30124
- throw new Error(
30125
- "No Puck API key specified. Set the PUCK_API_KEY environment variable, or provide one to the function"
30126
- );
30127
- }
30128
- return {
30129
- apiKey,
30130
- host,
30131
- token
30132
- };
30133
- };
30134
- var assertPuckResponse = async (res) => {
30135
- if (!res.body) {
30136
- throw new Error(`Puck ${res.status} (${res.statusText})`);
30137
- }
30138
- if (!res.ok) {
30139
- const body = await res.json();
30140
- throw new Error(
30141
- `Puck ${res.status} (${res.statusText}): ${body.error ?? "Unknown reason"}`
30142
- );
30143
- }
30144
- };
30145
- var requestPage = async (route, {
30146
- path,
30147
- siteId,
30148
- versionId,
30149
- body,
30150
- method = "GET"
30151
- }, options = {}) => {
30152
- const { apiKey, host, token } = resolveRequestOptions(options);
30153
- const searchParams = new URLSearchParams();
30154
- if (method === "GET") {
30155
- if (path) {
30156
- searchParams.set("path", path);
30157
- }
30158
- if (versionId) {
30159
- searchParams.set("versionId", versionId);
30160
- }
30161
- }
30162
- const queryString = searchParams.toString();
30163
- const res = await fetch(
30164
- `${host}${route}${queryString ? `?${queryString}` : ""}`,
30165
- {
30166
- method,
30167
- headers: {
30168
- "x-site-id": siteId,
30169
- ...token ? { "x-one-time-token": token } : {},
30170
- ...apiKey && !token ? { "x-api-key": apiKey } : {},
30171
- ...body ? { "content-type": "application/json" } : {}
30172
- },
30173
- ...body ? { body: JSON.stringify(body) } : {}
30174
- }
30175
- );
30176
- await assertPuckResponse(res);
30177
- return res;
30178
- };
30179
-
30180
- // api/lib/read-page.ts
30181
- var getPublishedPage = (args, options = {}) => requestPage("/pages/published", args, options);
30182
-
30183
- // src/lib/get-page.ts
30184
- var getPage = async ({
30185
- apiKey,
30186
- host,
30187
- path,
30188
- siteId
30189
- }) => {
30190
- const data = await getPublishedPage(
30191
- { path, siteId },
30192
- {
30193
- host: `${host}/api`,
30194
- apiKey
30195
- }
30196
- );
30197
- return (await data.json()).page?.versions?.at(0)?.data ?? null;
30198
- };
30199
30103
  // Annotate the CommonJS export names for ESM import in node:
30200
30104
  0 && (module.exports = {
30201
- createPagesPlugin,
30202
- getPage
30105
+ createPagesPlugin
30203
30106
  });
30204
30107
  /*! Bundled license information:
30205
30108
 
package/dist/index.mjs CHANGED
@@ -1,13 +1,43 @@
1
- import {
2
- getPage
3
- } from "./chunk-CFUMG5V5.mjs";
4
- import "./chunk-BZD7XJC3.mjs";
5
- import {
6
- __commonJS,
7
- __export,
8
- __toESM,
9
- init_react_import
10
- } from "./chunk-UYZYALB5.mjs";
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __esm = (fn2, res) => function __init() {
8
+ return fn2 && (res = (0, fn2[__getOwnPropNames(fn2)[0]])(fn2 = 0)), res;
9
+ };
10
+ var __commonJS = (cb, mod) => function __require() {
11
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
12
+ };
13
+ var __export = (target, all) => {
14
+ for (var name in all)
15
+ __defProp(target, name, { get: all[name], enumerable: true });
16
+ };
17
+ var __copyProps = (to2, from, except, desc) => {
18
+ if (from && typeof from === "object" || typeof from === "function") {
19
+ for (let key of __getOwnPropNames(from))
20
+ if (!__hasOwnProp.call(to2, key) && key !== except)
21
+ __defProp(to2, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
22
+ }
23
+ return to2;
24
+ };
25
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
26
+ // If the importer is in node compatibility mode or this is not an ESM
27
+ // file that has been converted to a CommonJS file using a Babel-
28
+ // compatible transform (i.e. "__esModule" has not been set), then set
29
+ // "default" to the CommonJS "module.exports" for node compatibility.
30
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
31
+ mod
32
+ ));
33
+
34
+ // ../tsup-config/react-import.js
35
+ import React from "react";
36
+ var init_react_import = __esm({
37
+ "../tsup-config/react-import.js"() {
38
+ "use strict";
39
+ }
40
+ });
11
41
 
12
42
  // ../../node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.js
13
43
  var require_classnames = __commonJS({
@@ -4730,6 +4760,9 @@ var useModalVisible = (defaultVisible) => {
4730
4760
  const [visible, setVisible] = useState7(defaultVisible ?? false);
4731
4761
  const ref = useRef8(null);
4732
4762
  useEffect9(() => {
4763
+ if (!visible) {
4764
+ return;
4765
+ }
4733
4766
  const handler = (e2) => {
4734
4767
  if (ref.current && !ref.current.contains(e2.target)) {
4735
4768
  setVisible(false);
@@ -4739,7 +4772,7 @@ var useModalVisible = (defaultVisible) => {
4739
4772
  return () => {
4740
4773
  document.body.removeEventListener("click", handler);
4741
4774
  };
4742
- }, []);
4775
+ }, [visible]);
4743
4776
  return [visible, setVisible, ref];
4744
4777
  };
4745
4778
 
@@ -4876,8 +4909,10 @@ var Modal = ({
4876
4909
  !hideButton && /* @__PURE__ */ jsx5("div", { className: getClassName3("button"), children: /* @__PURE__ */ jsx5(
4877
4910
  Button,
4878
4911
  {
4912
+ type: "button",
4879
4913
  variant: buttonVariant,
4880
- onClick: () => {
4914
+ onClick: (e2) => {
4915
+ e2.stopPropagation();
4881
4916
  setVisible(!visible);
4882
4917
  },
4883
4918
  children: actionLabel
@@ -5064,7 +5099,7 @@ init_react_import();
5064
5099
  // ../platform-client/components/AutoForm/AutoForm.tsx
5065
5100
  init_react_import();
5066
5101
  import { AutoField, FieldLabel } from "@puckeditor/core";
5067
- import { useEffect as useEffect11, useState as useState9 } from "react";
5102
+ import { useEffect as useEffect11, useRef as useRef9, useState as useState9 } from "react";
5068
5103
 
5069
5104
  // css-module:/home/runner/work/puck-platform/puck-platform/packages/platform-client/components/AutoForm/AutoForm.module.css#css-module
5070
5105
  init_react_import();
@@ -5150,7 +5185,7 @@ import { useEffect as useEffect12, useState as useState10 } from "react";
5150
5185
  import { jsx as jsx13 } from "react/jsx-runtime";
5151
5186
 
5152
5187
  // ../platform-client/components/Code/Code.tsx
5153
- import { useRef as useRef9, useState as useState11 } from "react";
5188
+ import { useRef as useRef10, useState as useState11 } from "react";
5154
5189
  import { jsx as jsx14, jsxs as jsxs9 } from "react/jsx-runtime";
5155
5190
  var getClassName9 = get_class_name_factory_default2("Code", Code_module_default);
5156
5191
  var getClassNameTab = get_class_name_factory_default2("Tab", Code_module_default);
@@ -12890,7 +12925,7 @@ init_react_import();
12890
12925
 
12891
12926
  // ../platform-client/components/Table/Table.tsx
12892
12927
  init_react_import();
12893
- import { useEffect as useEffect28, useMemo as useMemo19, useRef as useRef20, useState as useState27 } from "react";
12928
+ import { useEffect as useEffect28, useMemo as useMemo19, useRef as useRef21, useState as useState27 } from "react";
12894
12929
 
12895
12930
  // css-module:/home/runner/work/puck-platform/puck-platform/packages/platform-client/components/Table/Table.module.css#css-module
12896
12931
  init_react_import();
@@ -12940,7 +12975,7 @@ init_react_import();
12940
12975
  var styles_module_default7 = { "Pages": "_Pages_ey49w_5", "Pages-addPage": "_Pages-addPage_ey49w_12", "Pages-loader": "_Pages-loader_ey49w_18", "Pages-list": "_Pages-list_ey49w_26", "Pages-search": "_Pages-search_ey49w_34", "Pages-searchInput": "_Pages-searchInput_ey49w_38", "PagesPage": "_PagesPage_ey49w_59", "PagesPage--expanded": "_PagesPage--expanded_ey49w_69", "PagesPage-versions": "_PagesPage-versions_ey49w_73", "PagesPage-header": "_PagesPage-header_ey49w_96", "PagesPage--active": "_PagesPage--active_ey49w_124", "PagesPage-headerMain": "_PagesPage-headerMain_ey49w_137", "PagesPage-headerIcon": "_PagesPage-headerIcon_ey49w_144", "PagesPage-loader": "_PagesPage-loader_ey49w_148", "PagesVersion": "_PagesVersion_ey49w_174", "PagesVersion-inner": "_PagesVersion-inner_ey49w_174", "PagesVersion--current": "_PagesVersion--current_ey49w_189", "PagesVersion-header": "_PagesVersion-header_ey49w_204", "PagesVersion-version": "_PagesVersion-version_ey49w_210", "PagesVersion-date": "_PagesVersion-date_ey49w_216" };
12941
12976
 
12942
12977
  // src/components/PagePlugin/index.tsx
12943
- import { useCallback as useCallback9, useEffect as useEffect29, useMemo as useMemo22, useRef as useRef21, useState as useState30 } from "react";
12978
+ import { useCallback as useCallback9, useEffect as useEffect29, useMemo as useMemo22, useRef as useRef22, useState as useState30 } from "react";
12944
12979
  import { resolveAllData as resolveAllData2, useGetPuck as useGetPuck2 } from "@puckeditor/core";
12945
12980
 
12946
12981
  // src/components/CreateForm/index.tsx
@@ -29247,7 +29282,7 @@ var PagePlugin = (opts) => {
29247
29282
  const getPuck = useGetPuck2();
29248
29283
  const [confirmModalOpen, setConfirmModalOpen] = useState30(false);
29249
29284
  const [pendingNavigation, setPendingNavigation] = useState30(null);
29250
- const lastRequestedPathRef = useRef21(void 0);
29285
+ const lastRequestedPathRef = useRef22(void 0);
29251
29286
  const parentOrigin = opts?.parentOrigin ?? "https://cloud.puckeditor.com";
29252
29287
  const siteIdHeader = useSiteId();
29253
29288
  const path = usePath();
@@ -29577,11 +29612,11 @@ var PagePlugin = (opts) => {
29577
29612
  // src/components/HeaderActions/index.tsx
29578
29613
  init_react_import();
29579
29614
  import { createUsePuck, useGetPuck as useGetPuck3 } from "@puckeditor/core";
29580
- import { useMemo as useMemo23, useRef as useRef22, useState as useState31 } from "react";
29615
+ import { useMemo as useMemo23, useRef as useRef23, useState as useState31 } from "react";
29581
29616
 
29582
29617
  // css-module:/home/runner/work/puck-platform/puck-platform/packages/plugin-pages/src/components/HeaderActions/styles.module.css#css-module
29583
29618
  init_react_import();
29584
- var styles_module_default10 = { "HeaderActions": "_HeaderActions_1dhws_1", "HeaderActions-trigger": "_HeaderActions-trigger_1dhws_7", "HeaderActions-versionHeader": "_HeaderActions-versionHeader_1dhws_19", "HeaderActions-versionLabel": "_HeaderActions-versionLabel_1dhws_26", "HeaderActions-versionDate": "_HeaderActions-versionDate_1dhws_33" };
29619
+ var styles_module_default10 = { "HeaderActions-publish": "_HeaderActions-publish_7nzbl_1", "HeaderActions-trigger": "_HeaderActions-trigger_7nzbl_7", "HeaderActions-versionHeader": "_HeaderActions-versionHeader_7nzbl_19", "HeaderActions-versionLabel": "_HeaderActions-versionLabel_7nzbl_26", "HeaderActions-versionDate": "_HeaderActions-versionDate_7nzbl_33" };
29585
29620
 
29586
29621
  // src/components/HeaderActions/index.tsx
29587
29622
  import { Fragment as Fragment9, jsx as jsx44, jsxs as jsxs22 } from "react/jsx-runtime";
@@ -29773,7 +29808,7 @@ var HeaderActions = (opts) => {
29773
29808
  const defaultVersion = getDefaultPageVersion(resolvedPage);
29774
29809
  replaceEditorState(defaultVersion?.data);
29775
29810
  };
29776
- const saving = useRef22(false);
29811
+ const saving = useRef23(false);
29777
29812
  const handleSaveDraft = async () => {
29778
29813
  if (saving.current) return;
29779
29814
  const path = activePage;
@@ -29810,7 +29845,7 @@ var HeaderActions = (opts) => {
29810
29845
  saving.current = false;
29811
29846
  }
29812
29847
  };
29813
- const publishing = useRef22(false);
29848
+ const publishing = useRef23(false);
29814
29849
  const handlePublish = async () => {
29815
29850
  if (publishing.current) return;
29816
29851
  const path = activePage;
@@ -29941,17 +29976,6 @@ var HeaderActions = (opts) => {
29941
29976
  title: "Unpublish page"
29942
29977
  };
29943
29978
  return /* @__PURE__ */ jsxs22(Fragment9, { children: [
29944
- /* @__PURE__ */ jsx44(
29945
- ConfirmModal,
29946
- {
29947
- visible: confirmAction !== null,
29948
- onClose: () => setConfirmAction(null),
29949
- confirmLabel: confirmConfig.confirmLabel,
29950
- message: confirmConfig.message,
29951
- onConfirm: confirmConfig.onConfirm,
29952
- title: confirmConfig.title
29953
- }
29954
- ),
29955
29979
  canvasIsDirty ? /* @__PURE__ */ jsxs22(Fragment9, { children: [
29956
29980
  /* @__PURE__ */ jsxs22("div", { className: cx10("version"), children: [
29957
29981
  /* @__PURE__ */ jsx44("div", { className: cx10("versionHeader"), children: /* @__PURE__ */ jsx44("div", { className: cx10("versionLabel"), children: "Draft" }) }),
@@ -29981,7 +30005,7 @@ var HeaderActions = (opts) => {
29981
30005
  ] }),
29982
30006
  /* @__PURE__ */ jsx44("div", { className: cx10("versionDate"), children: currentVersion.createdAt ? format(currentVersion.createdAt, "MMM d yyy, HH:mm") : "" })
29983
30007
  ] }) }) : null,
29984
- /* @__PURE__ */ jsxs22("div", { className: cx10(), children: [
30008
+ /* @__PURE__ */ jsxs22("div", { className: cx10("publish"), children: [
29985
30009
  /* @__PURE__ */ jsx44(
29986
30010
  Button,
29987
30011
  {
@@ -30018,6 +30042,17 @@ var HeaderActions = (opts) => {
30018
30042
  ],
30019
30043
  children: /* @__PURE__ */ jsx44("span", { className: cx10("trigger"), children: /* @__PURE__ */ jsx44(ChevronDown, { size: 16 }) })
30020
30044
  }
30045
+ ),
30046
+ /* @__PURE__ */ jsx44(
30047
+ ConfirmModal,
30048
+ {
30049
+ visible: confirmAction !== null,
30050
+ onClose: () => setConfirmAction(null),
30051
+ confirmLabel: confirmConfig.confirmLabel,
30052
+ message: confirmConfig.message,
30053
+ onConfirm: confirmConfig.onConfirm,
30054
+ title: confirmConfig.title
30055
+ }
30021
30056
  )
30022
30057
  ] })
30023
30058
  ] });
@@ -30058,8 +30093,7 @@ function createPagesPlugin(opts) {
30058
30093
  };
30059
30094
  }
30060
30095
  export {
30061
- createPagesPlugin,
30062
- getPage
30096
+ createPagesPlugin
30063
30097
  };
30064
30098
  /*! Bundled license information:
30065
30099
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@puckeditor/plugin-pages",
3
- "version": "0.6.1-canary.a7fda263",
3
+ "version": "0.6.1-canary.b858ddc5",
4
4
  "author": "Chris Villa <chris@puckeditor.com>",
5
5
  "repository": "puckeditor/puck",
6
6
  "bugs": "https://github.com/puckeditor/puck/issues",
@@ -16,16 +16,12 @@
16
16
  "import": "./dist/index.mjs",
17
17
  "types": "./dist/index.d.ts"
18
18
  },
19
- "./server": {
20
- "import": "./dist/server.mjs",
21
- "require": "./dist/server.js"
22
- },
23
19
  "./styles.css": "./dist/index.css"
24
20
  },
25
21
  "scripts": {
26
22
  "lint": "eslint \"**/*.ts*\"",
27
- "build": "rm -rf dist && tsup index.ts server.ts api/view.ts api/edit.ts",
28
- "dev": "tsup index.ts server.ts api/view.ts api/edit.ts --watch src api",
23
+ "build": "rm -rf dist && tsup index.ts",
24
+ "dev": "tsup index.ts --watch src",
29
25
  "test": "vitest run --config vitest.config.ts"
30
26
  },
31
27
  "files": [
package/dist/api/edit.js DELETED
@@ -1,163 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // api/edit.ts
31
- var edit_exports = {};
32
- __export(edit_exports, {
33
- DELETE: () => deleteEditablePage,
34
- GET: () => getEditablePage,
35
- POST: () => createEditablePage,
36
- createEditablePage: () => createEditablePage,
37
- deleteEditablePage: () => deleteEditablePage,
38
- getEditablePage: () => getEditablePage,
39
- getPublishedPage: () => getPublishedPage,
40
- updateEditablePage: () => updateEditablePage
41
- });
42
- module.exports = __toCommonJS(edit_exports);
43
-
44
- // ../tsup-config/react-import.js
45
- var import_react = __toESM(require("react"));
46
-
47
- // ../cloud-client/src/lib/get-api-key.ts
48
- var getApiKey = () => process.env.PUCK_API_KEY;
49
-
50
- // api/lib/transport.ts
51
- var resolveRequestOptions = (options = {}) => {
52
- const {
53
- apiKey = getApiKey(),
54
- host = "https://cloud.puckeditor.com/api",
55
- token
56
- } = options;
57
- if (!apiKey && !token) {
58
- throw new Error(
59
- "No Puck API key specified. Set the PUCK_API_KEY environment variable, or provide one to the function"
60
- );
61
- }
62
- return {
63
- apiKey,
64
- host,
65
- token
66
- };
67
- };
68
- var assertPuckResponse = async (res) => {
69
- if (!res.body) {
70
- throw new Error(`Puck ${res.status} (${res.statusText})`);
71
- }
72
- if (!res.ok) {
73
- const body = await res.json();
74
- throw new Error(
75
- `Puck ${res.status} (${res.statusText}): ${body.error ?? "Unknown reason"}`
76
- );
77
- }
78
- };
79
- var requestPage = async (route, {
80
- path,
81
- siteId,
82
- versionId,
83
- body,
84
- method = "GET"
85
- }, options = {}) => {
86
- const { apiKey, host, token } = resolveRequestOptions(options);
87
- const searchParams = new URLSearchParams();
88
- if (method === "GET") {
89
- if (path) {
90
- searchParams.set("path", path);
91
- }
92
- if (versionId) {
93
- searchParams.set("versionId", versionId);
94
- }
95
- }
96
- const queryString = searchParams.toString();
97
- const res = await fetch(
98
- `${host}${route}${queryString ? `?${queryString}` : ""}`,
99
- {
100
- method,
101
- headers: {
102
- "x-site-id": siteId,
103
- ...token ? { "x-one-time-token": token } : {},
104
- ...apiKey && !token ? { "x-api-key": apiKey } : {},
105
- ...body ? { "content-type": "application/json" } : {}
106
- },
107
- ...body ? { body: JSON.stringify(body) } : {}
108
- }
109
- );
110
- await assertPuckResponse(res);
111
- return res;
112
- };
113
-
114
- // api/lib/create-page.ts
115
- var createEditablePage = ({ body, siteId }, options = {}) => requestPage(
116
- "/pages",
117
- {
118
- path: body.path,
119
- siteId,
120
- body,
121
- method: "POST"
122
- },
123
- options
124
- );
125
-
126
- // api/lib/delete-page.ts
127
- var deleteEditablePage = ({ id, siteId }, options = {}) => requestPage(
128
- `/pages/${id}`,
129
- {
130
- id,
131
- siteId,
132
- method: "DELETE"
133
- },
134
- options
135
- );
136
-
137
- // api/lib/read-page.ts
138
- var getPublishedPage = (args, options = {}) => requestPage("/pages/published", args, options);
139
- var getEditablePage = (args, options = {}) => requestPage(args.id ? `/pages/${args.id}` : "/pages", args, options);
140
-
141
- // api/lib/update-page.ts
142
- var updateEditablePage = ({ body, id, siteId }, options = {}) => requestPage(
143
- `/pages/${id}`,
144
- {
145
- id,
146
- path: body.path,
147
- siteId,
148
- body,
149
- method: "POST"
150
- },
151
- options
152
- );
153
- // Annotate the CommonJS export names for ESM import in node:
154
- 0 && (module.exports = {
155
- DELETE,
156
- GET,
157
- POST,
158
- createEditablePage,
159
- deleteEditablePage,
160
- getEditablePage,
161
- getPublishedPage,
162
- updateEditablePage
163
- });
package/dist/api/edit.mjs DELETED
@@ -1,58 +0,0 @@
1
- import {
2
- getEditablePage,
3
- getPublishedPage,
4
- init_react_import,
5
- requestPage
6
- } from "../chunk-UYZYALB5.mjs";
7
-
8
- // api/edit.ts
9
- init_react_import();
10
-
11
- // api/lib/create-page.ts
12
- init_react_import();
13
- var createEditablePage = ({ body, siteId }, options = {}) => requestPage(
14
- "/pages",
15
- {
16
- path: body.path,
17
- siteId,
18
- body,
19
- method: "POST"
20
- },
21
- options
22
- );
23
-
24
- // api/lib/delete-page.ts
25
- init_react_import();
26
- var deleteEditablePage = ({ id, siteId }, options = {}) => requestPage(
27
- `/pages/${id}`,
28
- {
29
- id,
30
- siteId,
31
- method: "DELETE"
32
- },
33
- options
34
- );
35
-
36
- // api/lib/update-page.ts
37
- init_react_import();
38
- var updateEditablePage = ({ body, id, siteId }, options = {}) => requestPage(
39
- `/pages/${id}`,
40
- {
41
- id,
42
- path: body.path,
43
- siteId,
44
- body,
45
- method: "POST"
46
- },
47
- options
48
- );
49
- export {
50
- deleteEditablePage as DELETE,
51
- getEditablePage as GET,
52
- createEditablePage as POST,
53
- createEditablePage,
54
- deleteEditablePage,
55
- getEditablePage,
56
- getPublishedPage,
57
- updateEditablePage
58
- };
package/dist/api/view.js DELETED
@@ -1,114 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // api/view.ts
31
- var view_exports = {};
32
- __export(view_exports, {
33
- GET: () => getPublishedPage,
34
- getPublishedPage: () => getPublishedPage
35
- });
36
- module.exports = __toCommonJS(view_exports);
37
-
38
- // ../tsup-config/react-import.js
39
- var import_react = __toESM(require("react"));
40
-
41
- // ../cloud-client/src/lib/get-api-key.ts
42
- var getApiKey = () => process.env.PUCK_API_KEY;
43
-
44
- // api/lib/transport.ts
45
- var resolveRequestOptions = (options = {}) => {
46
- const {
47
- apiKey = getApiKey(),
48
- host = "https://cloud.puckeditor.com/api",
49
- token
50
- } = options;
51
- if (!apiKey && !token) {
52
- throw new Error(
53
- "No Puck API key specified. Set the PUCK_API_KEY environment variable, or provide one to the function"
54
- );
55
- }
56
- return {
57
- apiKey,
58
- host,
59
- token
60
- };
61
- };
62
- var assertPuckResponse = async (res) => {
63
- if (!res.body) {
64
- throw new Error(`Puck ${res.status} (${res.statusText})`);
65
- }
66
- if (!res.ok) {
67
- const body = await res.json();
68
- throw new Error(
69
- `Puck ${res.status} (${res.statusText}): ${body.error ?? "Unknown reason"}`
70
- );
71
- }
72
- };
73
- var requestPage = async (route, {
74
- path,
75
- siteId,
76
- versionId,
77
- body,
78
- method = "GET"
79
- }, options = {}) => {
80
- const { apiKey, host, token } = resolveRequestOptions(options);
81
- const searchParams = new URLSearchParams();
82
- if (method === "GET") {
83
- if (path) {
84
- searchParams.set("path", path);
85
- }
86
- if (versionId) {
87
- searchParams.set("versionId", versionId);
88
- }
89
- }
90
- const queryString = searchParams.toString();
91
- const res = await fetch(
92
- `${host}${route}${queryString ? `?${queryString}` : ""}`,
93
- {
94
- method,
95
- headers: {
96
- "x-site-id": siteId,
97
- ...token ? { "x-one-time-token": token } : {},
98
- ...apiKey && !token ? { "x-api-key": apiKey } : {},
99
- ...body ? { "content-type": "application/json" } : {}
100
- },
101
- ...body ? { body: JSON.stringify(body) } : {}
102
- }
103
- );
104
- await assertPuckResponse(res);
105
- return res;
106
- };
107
-
108
- // api/lib/read-page.ts
109
- var getPublishedPage = (args, options = {}) => requestPage("/pages/published", args, options);
110
- // Annotate the CommonJS export names for ESM import in node:
111
- 0 && (module.exports = {
112
- GET,
113
- getPublishedPage
114
- });
package/dist/api/view.mjs DELETED
@@ -1,8 +0,0 @@
1
- import "../chunk-BZD7XJC3.mjs";
2
- import {
3
- getPublishedPage
4
- } from "../chunk-UYZYALB5.mjs";
5
- export {
6
- getPublishedPage as GET,
7
- getPublishedPage
8
- };
@@ -1,6 +0,0 @@
1
- import {
2
- init_react_import
3
- } from "./chunk-UYZYALB5.mjs";
4
-
5
- // api/view.ts
6
- init_react_import();
@@ -1,26 +0,0 @@
1
- import {
2
- getPublishedPage,
3
- init_react_import
4
- } from "./chunk-UYZYALB5.mjs";
5
-
6
- // src/lib/get-page.ts
7
- init_react_import();
8
- var getPage = async ({
9
- apiKey,
10
- host,
11
- path,
12
- siteId
13
- }) => {
14
- const data = await getPublishedPage(
15
- { path, siteId },
16
- {
17
- host: `${host}/api`,
18
- apiKey
19
- }
20
- );
21
- return (await data.json()).page?.versions?.at(0)?.data ?? null;
22
- };
23
-
24
- export {
25
- getPage
26
- };
@@ -1,128 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __esm = (fn, res) => function __init() {
8
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
9
- };
10
- var __commonJS = (cb, mod) => function __require() {
11
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
12
- };
13
- var __export = (target, all) => {
14
- for (var name in all)
15
- __defProp(target, name, { get: all[name], enumerable: true });
16
- };
17
- var __copyProps = (to, from, except, desc) => {
18
- if (from && typeof from === "object" || typeof from === "function") {
19
- for (let key of __getOwnPropNames(from))
20
- if (!__hasOwnProp.call(to, key) && key !== except)
21
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
22
- }
23
- return to;
24
- };
25
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
26
- // If the importer is in node compatibility mode or this is not an ESM
27
- // file that has been converted to a CommonJS file using a Babel-
28
- // compatible transform (i.e. "__esModule" has not been set), then set
29
- // "default" to the CommonJS "module.exports" for node compatibility.
30
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
31
- mod
32
- ));
33
-
34
- // ../tsup-config/react-import.js
35
- import React from "react";
36
- var init_react_import = __esm({
37
- "../tsup-config/react-import.js"() {
38
- "use strict";
39
- }
40
- });
41
-
42
- // api/lib/read-page.ts
43
- init_react_import();
44
-
45
- // api/lib/transport.ts
46
- init_react_import();
47
-
48
- // ../cloud-client/src/lib/get-api-key.ts
49
- init_react_import();
50
- var getApiKey = () => process.env.PUCK_API_KEY;
51
-
52
- // api/lib/transport.ts
53
- var resolveRequestOptions = (options = {}) => {
54
- const {
55
- apiKey = getApiKey(),
56
- host = "https://cloud.puckeditor.com/api",
57
- token
58
- } = options;
59
- if (!apiKey && !token) {
60
- throw new Error(
61
- "No Puck API key specified. Set the PUCK_API_KEY environment variable, or provide one to the function"
62
- );
63
- }
64
- return {
65
- apiKey,
66
- host,
67
- token
68
- };
69
- };
70
- var assertPuckResponse = async (res) => {
71
- if (!res.body) {
72
- throw new Error(`Puck ${res.status} (${res.statusText})`);
73
- }
74
- if (!res.ok) {
75
- const body = await res.json();
76
- throw new Error(
77
- `Puck ${res.status} (${res.statusText}): ${body.error ?? "Unknown reason"}`
78
- );
79
- }
80
- };
81
- var requestPage = async (route, {
82
- path,
83
- siteId,
84
- versionId,
85
- body,
86
- method = "GET"
87
- }, options = {}) => {
88
- const { apiKey, host, token } = resolveRequestOptions(options);
89
- const searchParams = new URLSearchParams();
90
- if (method === "GET") {
91
- if (path) {
92
- searchParams.set("path", path);
93
- }
94
- if (versionId) {
95
- searchParams.set("versionId", versionId);
96
- }
97
- }
98
- const queryString = searchParams.toString();
99
- const res = await fetch(
100
- `${host}${route}${queryString ? `?${queryString}` : ""}`,
101
- {
102
- method,
103
- headers: {
104
- "x-site-id": siteId,
105
- ...token ? { "x-one-time-token": token } : {},
106
- ...apiKey && !token ? { "x-api-key": apiKey } : {},
107
- ...body ? { "content-type": "application/json" } : {}
108
- },
109
- ...body ? { body: JSON.stringify(body) } : {}
110
- }
111
- );
112
- await assertPuckResponse(res);
113
- return res;
114
- };
115
-
116
- // api/lib/read-page.ts
117
- var getPublishedPage = (args, options = {}) => requestPage("/pages/published", args, options);
118
- var getEditablePage = (args, options = {}) => requestPage(args.id ? `/pages/${args.id}` : "/pages", args, options);
119
-
120
- export {
121
- __commonJS,
122
- __export,
123
- __toESM,
124
- init_react_import,
125
- requestPage,
126
- getPublishedPage,
127
- getEditablePage
128
- };
package/dist/server.js DELETED
@@ -1,129 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // server.ts
31
- var server_exports = {};
32
- __export(server_exports, {
33
- getPage: () => getPage
34
- });
35
- module.exports = __toCommonJS(server_exports);
36
-
37
- // ../tsup-config/react-import.js
38
- var import_react = __toESM(require("react"));
39
-
40
- // ../cloud-client/src/lib/get-api-key.ts
41
- var getApiKey = () => process.env.PUCK_API_KEY;
42
-
43
- // api/lib/transport.ts
44
- var resolveRequestOptions = (options = {}) => {
45
- const {
46
- apiKey = getApiKey(),
47
- host = "https://cloud.puckeditor.com/api",
48
- token
49
- } = options;
50
- if (!apiKey && !token) {
51
- throw new Error(
52
- "No Puck API key specified. Set the PUCK_API_KEY environment variable, or provide one to the function"
53
- );
54
- }
55
- return {
56
- apiKey,
57
- host,
58
- token
59
- };
60
- };
61
- var assertPuckResponse = async (res) => {
62
- if (!res.body) {
63
- throw new Error(`Puck ${res.status} (${res.statusText})`);
64
- }
65
- if (!res.ok) {
66
- const body = await res.json();
67
- throw new Error(
68
- `Puck ${res.status} (${res.statusText}): ${body.error ?? "Unknown reason"}`
69
- );
70
- }
71
- };
72
- var requestPage = async (route, {
73
- path,
74
- siteId,
75
- versionId,
76
- body,
77
- method = "GET"
78
- }, options = {}) => {
79
- const { apiKey, host, token } = resolveRequestOptions(options);
80
- const searchParams = new URLSearchParams();
81
- if (method === "GET") {
82
- if (path) {
83
- searchParams.set("path", path);
84
- }
85
- if (versionId) {
86
- searchParams.set("versionId", versionId);
87
- }
88
- }
89
- const queryString = searchParams.toString();
90
- const res = await fetch(
91
- `${host}${route}${queryString ? `?${queryString}` : ""}`,
92
- {
93
- method,
94
- headers: {
95
- "x-site-id": siteId,
96
- ...token ? { "x-one-time-token": token } : {},
97
- ...apiKey && !token ? { "x-api-key": apiKey } : {},
98
- ...body ? { "content-type": "application/json" } : {}
99
- },
100
- ...body ? { body: JSON.stringify(body) } : {}
101
- }
102
- );
103
- await assertPuckResponse(res);
104
- return res;
105
- };
106
-
107
- // api/lib/read-page.ts
108
- var getPublishedPage = (args, options = {}) => requestPage("/pages/published", args, options);
109
-
110
- // src/lib/get-page.ts
111
- var getPage = async ({
112
- apiKey,
113
- host,
114
- path,
115
- siteId
116
- }) => {
117
- const data = await getPublishedPage(
118
- { path, siteId },
119
- {
120
- host: `${host}/api`,
121
- apiKey
122
- }
123
- );
124
- return (await data.json()).page?.versions?.at(0)?.data ?? null;
125
- };
126
- // Annotate the CommonJS export names for ESM import in node:
127
- 0 && (module.exports = {
128
- getPage
129
- });
package/dist/server.mjs DELETED
@@ -1,13 +0,0 @@
1
- import {
2
- getPage
3
- } from "./chunk-CFUMG5V5.mjs";
4
- import "./chunk-BZD7XJC3.mjs";
5
- import {
6
- init_react_import
7
- } from "./chunk-UYZYALB5.mjs";
8
-
9
- // server.ts
10
- init_react_import();
11
- export {
12
- getPage
13
- };