@uniformdev/canvas-next 19.38.3-alpha.70 → 19.38.3-alpha.78

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.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { RichTextRendererComponent, RenderRichTextComponentResolver, UniformRichText as UniformRichText$1, UniformRichTextNode as UniformRichTextNode$1 } from '@uniformdev/canvas-react';
2
2
  import { ParsedUrlQuery } from 'querystring';
3
- export { U as UniformCompositionNextPage, c as UniformGetServerSideProps, b as UniformGetStaticProps, a as UniformPreviewData } from './models-092c0912.js';
3
+ export { U as UniformCompositionNextPage, c as UniformGetServerSideProps, b as UniformGetStaticProps, a as UniformPreviewData } from './models-f9fd03c4.js';
4
4
  import { NextApiHandler, NextApiRequest } from 'next';
5
5
  import { RootComponentInstance } from '@uniformdev/canvas';
6
6
 
@@ -31,6 +31,10 @@ type CreatePreviewHandlerGetOptions = {
31
31
  * defaults to a function that returns the `path` if truthy, otherwise returns `slug`.
32
32
  */
33
33
  resolveFullPath?: ResolveFullPath;
34
+ /**
35
+ * The path to the playground page, to live preview components and patterns
36
+ */
37
+ playgroundPath?: string;
34
38
  };
35
39
  type CreatePreviewHandlerGet = (options?: CreatePreviewHandlerGetOptions) => NextApiHandler;
36
40
  declare const createPreviewHandlerGet: CreatePreviewHandlerGet;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { RichTextRendererComponent, RenderRichTextComponentResolver, UniformRichText as UniformRichText$1, UniformRichTextNode as UniformRichTextNode$1 } from '@uniformdev/canvas-react';
2
2
  import { ParsedUrlQuery } from 'querystring';
3
- export { U as UniformCompositionNextPage, c as UniformGetServerSideProps, b as UniformGetStaticProps, a as UniformPreviewData } from './models-092c0912.js';
3
+ export { U as UniformCompositionNextPage, c as UniformGetServerSideProps, b as UniformGetStaticProps, a as UniformPreviewData } from './models-f9fd03c4.js';
4
4
  import { NextApiHandler, NextApiRequest } from 'next';
5
5
  import { RootComponentInstance } from '@uniformdev/canvas';
6
6
 
@@ -31,6 +31,10 @@ type CreatePreviewHandlerGetOptions = {
31
31
  * defaults to a function that returns the `path` if truthy, otherwise returns `slug`.
32
32
  */
33
33
  resolveFullPath?: ResolveFullPath;
34
+ /**
35
+ * The path to the playground page, to live preview components and patterns
36
+ */
37
+ playgroundPath?: string;
34
38
  };
35
39
  type CreatePreviewHandlerGet = (options?: CreatePreviewHandlerGetOptions) => NextApiHandler;
36
40
  declare const createPreviewHandlerGet: CreatePreviewHandlerGet;
package/dist/index.esm.js CHANGED
@@ -49,7 +49,10 @@ var UniformRichTextNode = ({
49
49
  };
50
50
 
51
51
  // src/preview/previewHandlerGet.ts
52
- import { IN_CONTEXT_EDITOR_QUERY_STRING_PARAM } from "@uniformdev/canvas";
52
+ import {
53
+ IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM,
54
+ IN_CONTEXT_EDITOR_QUERY_STRING_PARAM
55
+ } from "@uniformdev/canvas";
53
56
  var BASE_URL_EXAMPLE = "https://exmaple.com";
54
57
  var getQueryParam = (req, paramName) => {
55
58
  const value = req.query[paramName];
@@ -58,16 +61,33 @@ var getQueryParam = (req, paramName) => {
58
61
  }
59
62
  return Array.isArray(value) ? value[0] : value;
60
63
  };
61
- var createPreviewHandlerGet = ({ secret, resolveFullPath = resolveFullPathDefault } = {}) => async (req, res) => {
64
+ var queryParamsToPreserve = [
65
+ IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
66
+ IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM
67
+ ];
68
+ var createPreviewHandlerGet = ({ secret, resolveFullPath = resolveFullPathDefault, playgroundPath } = {}) => async (req, res) => {
69
+ const isConfigCheck = getQueryParam(req, "is_config_check") === "true";
70
+ if (isConfigCheck) {
71
+ return res.json({
72
+ hasPlayground: Boolean(playgroundPath),
73
+ isUsingCustomFullPathResolver: resolveFullPath !== resolveFullPathDefault
74
+ });
75
+ }
62
76
  if (req.headers["sec-fetch-mode"] === "no-cors") {
63
77
  return res.status(204).end();
64
78
  }
65
- const queryParamsToPreserve = [IN_CONTEXT_EDITOR_QUERY_STRING_PARAM];
79
+ const isPlayground = req.query[IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM] === "true";
80
+ let pathToRedirectTo;
81
+ if (isPlayground && playgroundPath) {
82
+ pathToRedirectTo = playgroundPath;
83
+ }
66
84
  const id = getQueryParam(req, "id");
67
85
  const slug = getQueryParam(req, "slug");
68
86
  const path = getQueryParam(req, "path");
69
87
  const locale = getQueryParam(req, "locale");
70
- const pathToRedirectTo = resolveFullPath({ id, slug, path, locale });
88
+ if (typeof pathToRedirectTo === "undefined") {
89
+ pathToRedirectTo = resolveFullPath({ id, slug, path, locale });
90
+ }
71
91
  validateLocalRedirectUrl(pathToRedirectTo);
72
92
  if (!pathToRedirectTo) {
73
93
  return res.status(400).json({ message: "Could not resolve the full path of the preview page" });
@@ -89,7 +109,8 @@ var createPreviewHandlerGet = ({ secret, resolveFullPath = resolveFullPathDefaul
89
109
  compositionId: id,
90
110
  compositionSlug: slug,
91
111
  compositionPath: path,
92
- locale
112
+ locale,
113
+ isPlayground
93
114
  },
94
115
  {
95
116
  // By default the preview cookies stays as long as the tab is open. And in contextual editing mode, people tend to open Canvas editor (one tab) and another tab to see published changes.
@@ -153,17 +174,17 @@ var createPreviewHandlerPost = ({ secret, enhance } = {}) => async (req, res) =>
153
174
  };
154
175
 
155
176
  // src/preview/previewHandler.ts
156
- var createPreviewHandler = ({ secret, enhance, resolveFullPath } = {}) => async (req, res) => {
177
+ var createPreviewHandler = ({ secret, enhance, resolveFullPath, playgroundPath } = {}) => async (req, res) => {
157
178
  var _a;
158
179
  const method = (_a = req.method) == null ? void 0 : _a.toLocaleLowerCase();
180
+ res.setHeader("Access-Control-Allow-Origin", "*");
181
+ res.setHeader("Access-Control-Allow-Headers", "Origin, Content-Type, Accept");
182
+ res.setHeader("Access-Control-Allow-Methods", "GET, HEAD");
159
183
  if (method === "get") {
160
- return createPreviewHandlerGet({ secret, resolveFullPath })(req, res);
184
+ return createPreviewHandlerGet({ secret, resolveFullPath, playgroundPath })(req, res);
161
185
  } else if (method === "post") {
162
186
  return createPreviewHandlerPost({ secret, enhance })(req, res);
163
187
  } else if (method === "options") {
164
- res.setHeader("Access-Control-Allow-Origin", "*");
165
- res.setHeader("Access-Control-Allow-Headers", "Origin, Content-Type, Accept");
166
- res.setHeader("Access-Control-Allow-Methods", "GET");
167
188
  return res.status(204).end();
168
189
  }
169
190
  return res.status(501).json({ message: `Method "${method}" not implemented` });
package/dist/index.js CHANGED
@@ -104,16 +104,33 @@ var getQueryParam = (req, paramName) => {
104
104
  }
105
105
  return Array.isArray(value) ? value[0] : value;
106
106
  };
107
- var createPreviewHandlerGet = ({ secret, resolveFullPath = resolveFullPathDefault } = {}) => async (req, res) => {
107
+ var queryParamsToPreserve = [
108
+ import_canvas.IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
109
+ import_canvas.IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM
110
+ ];
111
+ var createPreviewHandlerGet = ({ secret, resolveFullPath = resolveFullPathDefault, playgroundPath } = {}) => async (req, res) => {
112
+ const isConfigCheck = getQueryParam(req, "is_config_check") === "true";
113
+ if (isConfigCheck) {
114
+ return res.json({
115
+ hasPlayground: Boolean(playgroundPath),
116
+ isUsingCustomFullPathResolver: resolveFullPath !== resolveFullPathDefault
117
+ });
118
+ }
108
119
  if (req.headers["sec-fetch-mode"] === "no-cors") {
109
120
  return res.status(204).end();
110
121
  }
111
- const queryParamsToPreserve = [import_canvas.IN_CONTEXT_EDITOR_QUERY_STRING_PARAM];
122
+ const isPlayground = req.query[import_canvas.IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM] === "true";
123
+ let pathToRedirectTo;
124
+ if (isPlayground && playgroundPath) {
125
+ pathToRedirectTo = playgroundPath;
126
+ }
112
127
  const id = getQueryParam(req, "id");
113
128
  const slug = getQueryParam(req, "slug");
114
129
  const path = getQueryParam(req, "path");
115
130
  const locale = getQueryParam(req, "locale");
116
- const pathToRedirectTo = resolveFullPath({ id, slug, path, locale });
131
+ if (typeof pathToRedirectTo === "undefined") {
132
+ pathToRedirectTo = resolveFullPath({ id, slug, path, locale });
133
+ }
117
134
  validateLocalRedirectUrl(pathToRedirectTo);
118
135
  if (!pathToRedirectTo) {
119
136
  return res.status(400).json({ message: "Could not resolve the full path of the preview page" });
@@ -135,7 +152,8 @@ var createPreviewHandlerGet = ({ secret, resolveFullPath = resolveFullPathDefaul
135
152
  compositionId: id,
136
153
  compositionSlug: slug,
137
154
  compositionPath: path,
138
- locale
155
+ locale,
156
+ isPlayground
139
157
  },
140
158
  {
141
159
  // By default the preview cookies stays as long as the tab is open. And in contextual editing mode, people tend to open Canvas editor (one tab) and another tab to see published changes.
@@ -199,17 +217,17 @@ var createPreviewHandlerPost = ({ secret, enhance } = {}) => async (req, res) =>
199
217
  };
200
218
 
201
219
  // src/preview/previewHandler.ts
202
- var createPreviewHandler = ({ secret, enhance, resolveFullPath } = {}) => async (req, res) => {
220
+ var createPreviewHandler = ({ secret, enhance, resolveFullPath, playgroundPath } = {}) => async (req, res) => {
203
221
  var _a;
204
222
  const method = (_a = req.method) == null ? void 0 : _a.toLocaleLowerCase();
223
+ res.setHeader("Access-Control-Allow-Origin", "*");
224
+ res.setHeader("Access-Control-Allow-Headers", "Origin, Content-Type, Accept");
225
+ res.setHeader("Access-Control-Allow-Methods", "GET, HEAD");
205
226
  if (method === "get") {
206
- return createPreviewHandlerGet({ secret, resolveFullPath })(req, res);
227
+ return createPreviewHandlerGet({ secret, resolveFullPath, playgroundPath })(req, res);
207
228
  } else if (method === "post") {
208
229
  return createPreviewHandlerPost({ secret, enhance })(req, res);
209
230
  } else if (method === "options") {
210
- res.setHeader("Access-Control-Allow-Origin", "*");
211
- res.setHeader("Access-Control-Allow-Headers", "Origin, Content-Type, Accept");
212
- res.setHeader("Access-Control-Allow-Methods", "GET");
213
231
  return res.status(204).end();
214
232
  }
215
233
  return res.status(501).json({ message: `Method "${method}" not implemented` });
package/dist/index.mjs CHANGED
@@ -49,7 +49,10 @@ var UniformRichTextNode = ({
49
49
  };
50
50
 
51
51
  // src/preview/previewHandlerGet.ts
52
- import { IN_CONTEXT_EDITOR_QUERY_STRING_PARAM } from "@uniformdev/canvas";
52
+ import {
53
+ IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM,
54
+ IN_CONTEXT_EDITOR_QUERY_STRING_PARAM
55
+ } from "@uniformdev/canvas";
53
56
  var BASE_URL_EXAMPLE = "https://exmaple.com";
54
57
  var getQueryParam = (req, paramName) => {
55
58
  const value = req.query[paramName];
@@ -58,16 +61,33 @@ var getQueryParam = (req, paramName) => {
58
61
  }
59
62
  return Array.isArray(value) ? value[0] : value;
60
63
  };
61
- var createPreviewHandlerGet = ({ secret, resolveFullPath = resolveFullPathDefault } = {}) => async (req, res) => {
64
+ var queryParamsToPreserve = [
65
+ IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
66
+ IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM
67
+ ];
68
+ var createPreviewHandlerGet = ({ secret, resolveFullPath = resolveFullPathDefault, playgroundPath } = {}) => async (req, res) => {
69
+ const isConfigCheck = getQueryParam(req, "is_config_check") === "true";
70
+ if (isConfigCheck) {
71
+ return res.json({
72
+ hasPlayground: Boolean(playgroundPath),
73
+ isUsingCustomFullPathResolver: resolveFullPath !== resolveFullPathDefault
74
+ });
75
+ }
62
76
  if (req.headers["sec-fetch-mode"] === "no-cors") {
63
77
  return res.status(204).end();
64
78
  }
65
- const queryParamsToPreserve = [IN_CONTEXT_EDITOR_QUERY_STRING_PARAM];
79
+ const isPlayground = req.query[IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM] === "true";
80
+ let pathToRedirectTo;
81
+ if (isPlayground && playgroundPath) {
82
+ pathToRedirectTo = playgroundPath;
83
+ }
66
84
  const id = getQueryParam(req, "id");
67
85
  const slug = getQueryParam(req, "slug");
68
86
  const path = getQueryParam(req, "path");
69
87
  const locale = getQueryParam(req, "locale");
70
- const pathToRedirectTo = resolveFullPath({ id, slug, path, locale });
88
+ if (typeof pathToRedirectTo === "undefined") {
89
+ pathToRedirectTo = resolveFullPath({ id, slug, path, locale });
90
+ }
71
91
  validateLocalRedirectUrl(pathToRedirectTo);
72
92
  if (!pathToRedirectTo) {
73
93
  return res.status(400).json({ message: "Could not resolve the full path of the preview page" });
@@ -89,7 +109,8 @@ var createPreviewHandlerGet = ({ secret, resolveFullPath = resolveFullPathDefaul
89
109
  compositionId: id,
90
110
  compositionSlug: slug,
91
111
  compositionPath: path,
92
- locale
112
+ locale,
113
+ isPlayground
93
114
  },
94
115
  {
95
116
  // By default the preview cookies stays as long as the tab is open. And in contextual editing mode, people tend to open Canvas editor (one tab) and another tab to see published changes.
@@ -153,17 +174,17 @@ var createPreviewHandlerPost = ({ secret, enhance } = {}) => async (req, res) =>
153
174
  };
154
175
 
155
176
  // src/preview/previewHandler.ts
156
- var createPreviewHandler = ({ secret, enhance, resolveFullPath } = {}) => async (req, res) => {
177
+ var createPreviewHandler = ({ secret, enhance, resolveFullPath, playgroundPath } = {}) => async (req, res) => {
157
178
  var _a;
158
179
  const method = (_a = req.method) == null ? void 0 : _a.toLocaleLowerCase();
180
+ res.setHeader("Access-Control-Allow-Origin", "*");
181
+ res.setHeader("Access-Control-Allow-Headers", "Origin, Content-Type, Accept");
182
+ res.setHeader("Access-Control-Allow-Methods", "GET, HEAD");
159
183
  if (method === "get") {
160
- return createPreviewHandlerGet({ secret, resolveFullPath })(req, res);
184
+ return createPreviewHandlerGet({ secret, resolveFullPath, playgroundPath })(req, res);
161
185
  } else if (method === "post") {
162
186
  return createPreviewHandlerPost({ secret, enhance })(req, res);
163
187
  } else if (method === "options") {
164
- res.setHeader("Access-Control-Allow-Origin", "*");
165
- res.setHeader("Access-Control-Allow-Headers", "Origin, Content-Type, Accept");
166
- res.setHeader("Access-Control-Allow-Methods", "GET");
167
188
  return res.status(204).end();
168
189
  }
169
190
  return res.status(501).json({ message: `Method "${method}" not implemented` });
@@ -10,6 +10,7 @@ type UniformPreviewData = PreviewData & {
10
10
  compositionSlug?: string;
11
11
  compositionPath?: string;
12
12
  locale?: string;
13
+ isPlayground?: boolean;
13
14
  };
14
15
  type UniformGetStaticProps<P extends {
15
16
  [key: string]: any;
@@ -1,6 +1,6 @@
1
1
  import * as next from 'next';
2
2
  import { GetServerSidePropsContext, PreviewData, GetServerSideProps, GetStaticPropsContext, GetStaticProps } from 'next';
3
- import { c as UniformGetServerSideProps, a as UniformPreviewData, b as UniformGetStaticProps } from '../models-092c0912.js';
3
+ import { c as UniformGetServerSideProps, a as UniformPreviewData, b as UniformGetStaticProps } from '../models-f9fd03c4.js';
4
4
  import * as querystring from 'querystring';
5
5
  import { ParsedUrlQuery } from 'querystring';
6
6
  import * as _uniformdev_canvas from '@uniformdev/canvas';
@@ -1,6 +1,6 @@
1
1
  import * as next from 'next';
2
2
  import { GetServerSidePropsContext, PreviewData, GetServerSideProps, GetStaticPropsContext, GetStaticProps } from 'next';
3
- import { c as UniformGetServerSideProps, a as UniformPreviewData, b as UniformGetStaticProps } from '../models-092c0912.js';
3
+ import { c as UniformGetServerSideProps, a as UniformPreviewData, b as UniformGetStaticProps } from '../models-f9fd03c4.js';
4
4
  import * as querystring from 'querystring';
5
5
  import { ParsedUrlQuery } from 'querystring';
6
6
  import * as _uniformdev_canvas from '@uniformdev/canvas';
@@ -1,6 +1,6 @@
1
1
  import * as next from 'next';
2
2
  import { GetServerSidePropsContext, GetServerSidePropsResult, GetServerSideProps, GetStaticPropsContext, GetStaticPropsResult, GetStaticProps } from 'next';
3
- import { a as UniformPreviewData } from '../models-092c0912.js';
3
+ import { a as UniformPreviewData } from '../models-f9fd03c4.js';
4
4
  import * as querystring from 'querystring';
5
5
  import { ParsedUrlQuery } from 'querystring';
6
6
  export { w as withUniformGetStaticPaths } from '../withUniformGetStaticPaths-77db0164.js';
@@ -1,6 +1,6 @@
1
1
  import * as next from 'next';
2
2
  import { GetServerSidePropsContext, GetServerSidePropsResult, GetServerSideProps, GetStaticPropsContext, GetStaticPropsResult, GetStaticProps } from 'next';
3
- import { a as UniformPreviewData } from '../models-092c0912.js';
3
+ import { a as UniformPreviewData } from '../models-f9fd03c4.js';
4
4
  import * as querystring from 'querystring';
5
5
  import { ParsedUrlQuery } from 'querystring';
6
6
  export { w as withUniformGetStaticPaths } from '../withUniformGetStaticPaths-77db0164.js';
@@ -1,6 +1,6 @@
1
1
  import * as next from 'next';
2
2
  import { GetServerSidePropsContext, GetServerSideProps, GetStaticPropsContext, GetStaticProps } from 'next';
3
- import { a as UniformPreviewData, c as UniformGetServerSideProps, b as UniformGetStaticProps } from '../models-092c0912.js';
3
+ import { a as UniformPreviewData, c as UniformGetServerSideProps, b as UniformGetStaticProps } from '../models-f9fd03c4.js';
4
4
  import * as querystring from 'querystring';
5
5
  import { ParsedUrlQuery } from 'querystring';
6
6
  import * as _uniformdev_canvas from '@uniformdev/canvas';
@@ -1,6 +1,6 @@
1
1
  import * as next from 'next';
2
2
  import { GetServerSidePropsContext, GetServerSideProps, GetStaticPropsContext, GetStaticProps } from 'next';
3
- import { a as UniformPreviewData, c as UniformGetServerSideProps, b as UniformGetStaticProps } from '../models-092c0912.js';
3
+ import { a as UniformPreviewData, c as UniformGetServerSideProps, b as UniformGetStaticProps } from '../models-f9fd03c4.js';
4
4
  import * as querystring from 'querystring';
5
5
  import { ParsedUrlQuery } from 'querystring';
6
6
  import * as _uniformdev_canvas from '@uniformdev/canvas';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/canvas-next",
3
- "version": "19.38.3-alpha.70+55e5a8fe1",
3
+ "version": "19.38.3-alpha.78+5c9892bf1",
4
4
  "description": "Next.js SDK for Uniform Canvas",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./dist/index.js",
@@ -63,11 +63,11 @@
63
63
  "document": "api-extractor run --local"
64
64
  },
65
65
  "dependencies": {
66
- "@uniformdev/canvas": "19.38.3-alpha.70+55e5a8fe1",
67
- "@uniformdev/canvas-react": "19.38.3-alpha.70+55e5a8fe1",
68
- "@uniformdev/project-map": "19.38.3-alpha.70+55e5a8fe1",
69
- "@uniformdev/redirect": "19.38.3-alpha.70+55e5a8fe1",
70
- "@uniformdev/richtext": "19.38.3-alpha.70+55e5a8fe1",
66
+ "@uniformdev/canvas": "19.38.3-alpha.78+5c9892bf1",
67
+ "@uniformdev/canvas-react": "19.38.3-alpha.78+5c9892bf1",
68
+ "@uniformdev/project-map": "19.38.3-alpha.78+5c9892bf1",
69
+ "@uniformdev/redirect": "19.38.3-alpha.78+5c9892bf1",
70
+ "@uniformdev/richtext": "19.38.3-alpha.78+5c9892bf1",
71
71
  "colorette": "2.0.20"
72
72
  },
73
73
  "peerDependencies": {
@@ -76,7 +76,7 @@
76
76
  "react-dom": ">=16"
77
77
  },
78
78
  "devDependencies": {
79
- "@types/react": "18.2.18",
79
+ "@types/react": "18.2.20",
80
80
  "next": "13.4.12",
81
81
  "react": "18.2.0",
82
82
  "react-dom": "18.2.0"
@@ -87,5 +87,5 @@
87
87
  "publishConfig": {
88
88
  "access": "public"
89
89
  },
90
- "gitHead": "55e5a8fe1d80971a93ea31d3a50cec72e71be70a"
90
+ "gitHead": "5c9892bf101584d351d06b65e1658a1237594cfb"
91
91
  }