@prismicio/client 7.23.0-pr.473.7aca245 → 7.23.0-pr.480.965f57f

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/cookie.cjs CHANGED
@@ -1,7 +1,12 @@
1
1
  //#region src/cookie.ts
2
- var cookie_exports = /* @__PURE__ */ require("./_virtual/_rolldown/runtime.cjs").__exportAll({ preview: () => preview });
2
+ var cookie_exports = /* @__PURE__ */ require("./_virtual/_rolldown/runtime.cjs").__exportAll({
3
+ preview: () => preview,
4
+ previewSession: () => previewSession
5
+ });
3
6
  /** The well-known name of the cookie used to store a Prismic preview session's ref. */
4
7
  const preview = "io.prismic.preview";
8
+ /** The well-known name of the cookie used to store a Prismic preview session's ID. */
9
+ const previewSession = "io.prismic.previewSession";
5
10
  //#endregion
6
11
  Object.defineProperty(exports, "cookie_exports", {
7
12
  enumerable: true,
@@ -10,5 +15,6 @@ Object.defineProperty(exports, "cookie_exports", {
10
15
  }
11
16
  });
12
17
  exports.preview = preview;
18
+ exports.previewSession = previewSession;
13
19
 
14
20
  //# sourceMappingURL=cookie.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"cookie.cjs","names":[],"sources":["../src/cookie.ts"],"sourcesContent":["/** The well-known name of the cookie used to store a Prismic preview session's ref. */\nexport const preview = \"io.prismic.preview\"\n"],"mappings":";;;AACA,MAAa,UAAU"}
1
+ {"version":3,"file":"cookie.cjs","names":[],"sources":["../src/cookie.ts"],"sourcesContent":["/** The well-known name of the cookie used to store a Prismic preview session's ref. */\nexport const preview = \"io.prismic.preview\"\n\n/** The well-known name of the cookie used to store a Prismic preview session's ID. */\nexport const previewSession = \"io.prismic.previewSession\"\n"],"mappings":";;;;;;AACA,MAAa,UAAU;;AAGvB,MAAa,iBAAiB"}
package/dist/cookie.d.cts CHANGED
@@ -1,8 +1,10 @@
1
1
  declare namespace cookie_d_exports {
2
- export { preview };
2
+ export { preview, previewSession };
3
3
  }
4
4
  /** The well-known name of the cookie used to store a Prismic preview session's ref. */
5
5
  export declare const preview = "io.prismic.preview";
6
+ /** The well-known name of the cookie used to store a Prismic preview session's ID. */
7
+ export declare const previewSession = "io.prismic.previewSession";
6
8
  //#endregion
7
9
  export { cookie_d_exports };
8
10
  //# sourceMappingURL=cookie.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cookie.d.cts","names":[],"sources":["../src/cookie.ts"],"mappings":";;;;qBACa"}
1
+ {"version":3,"file":"cookie.d.cts","names":[],"sources":["../src/cookie.ts"],"mappings":";;;;qBACa;;qBAGA"}
package/dist/cookie.d.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  declare namespace cookie_d_exports {
2
- export { preview };
2
+ export { preview, previewSession };
3
3
  }
4
4
  /** The well-known name of the cookie used to store a Prismic preview session's ref. */
5
5
  export declare const preview = "io.prismic.preview";
6
+ /** The well-known name of the cookie used to store a Prismic preview session's ID. */
7
+ export declare const previewSession = "io.prismic.previewSession";
6
8
  //#endregion
7
9
  export { cookie_d_exports };
8
10
  //# sourceMappingURL=cookie.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cookie.d.ts","names":[],"sources":["../src/cookie.ts"],"mappings":";;;;qBACa"}
1
+ {"version":3,"file":"cookie.d.ts","names":[],"sources":["../src/cookie.ts"],"mappings":";;;;qBACa;;qBAGA"}
package/dist/cookie.js CHANGED
@@ -1,9 +1,14 @@
1
1
  import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
2
  //#region src/cookie.ts
3
- var cookie_exports = /* @__PURE__ */ __exportAll({ preview: () => preview });
3
+ var cookie_exports = /* @__PURE__ */ __exportAll({
4
+ preview: () => preview,
5
+ previewSession: () => previewSession
6
+ });
4
7
  /** The well-known name of the cookie used to store a Prismic preview session's ref. */
5
8
  const preview = "io.prismic.preview";
9
+ /** The well-known name of the cookie used to store a Prismic preview session's ID. */
10
+ const previewSession = "io.prismic.previewSession";
6
11
  //#endregion
7
- export { cookie_exports, preview };
12
+ export { cookie_exports, preview, previewSession };
8
13
 
9
14
  //# sourceMappingURL=cookie.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"cookie.js","names":[],"sources":["../src/cookie.ts"],"sourcesContent":["/** The well-known name of the cookie used to store a Prismic preview session's ref. */\nexport const preview = \"io.prismic.preview\"\n"],"mappings":";;;;AACA,MAAa,UAAU"}
1
+ {"version":3,"file":"cookie.js","names":[],"sources":["../src/cookie.ts"],"sourcesContent":["/** The well-known name of the cookie used to store a Prismic preview session's ref. */\nexport const preview = \"io.prismic.preview\"\n\n/** The well-known name of the cookie used to store a Prismic preview session's ID. */\nexport const previewSession = \"io.prismic.previewSession\"\n"],"mappings":";;;;;;;AACA,MAAa,UAAU;;AAGvB,MAAa,iBAAiB"}
@@ -30,11 +30,16 @@ const require_isRepositoryName = require("./isRepositoryName.cjs");
30
30
  *
31
31
  * @param repositoryName - The name of the Prismic repository. For example, `"my-repo"` if the
32
32
  * repository URL is `my-repo.prismic.io`.
33
+ * @param config - Options that configure the toolbar URL.
33
34
  * @returns The URL for the given Prismic repository's Prismic Toolbar script.
34
35
  */
35
- const getToolbarSrc = (repositoryName) => {
36
- if (require_isRepositoryName.isRepositoryName(repositoryName)) return `https://static.cdn.prismic.io/prismic.js?new=true&repo=${repositoryName}`;
37
- else throw new require_errors.PrismicError(`An invalid Prismic repository name was given: ${repositoryName}`, void 0, void 0);
36
+ const getToolbarSrc = (repositoryName, config) => {
37
+ if (require_isRepositoryName.isRepositoryName(repositoryName)) {
38
+ const url = new URL(`${config?.host ?? "https://static.cdn.prismic.io"}/prismic.js`);
39
+ url.searchParams.set("repo", repositoryName);
40
+ if (config?.version) url.searchParams.set("v", config.version.toString());
41
+ return url.toString();
42
+ } else throw new require_errors.PrismicError(`An invalid Prismic repository name was given: ${repositoryName}`, void 0, void 0);
38
43
  };
39
44
  //#endregion
40
45
  exports.getToolbarSrc = getToolbarSrc;
@@ -1 +1 @@
1
- {"version":3,"file":"getToolbarSrc.cjs","names":["isRepositoryName","PrismicError"],"sources":["../src/getToolbarSrc.ts"],"sourcesContent":["import { PrismicError } from \"./errors\"\nimport { isRepositoryName } from \"./isRepositoryName\"\n\n/**\n * Returns the URL for a Prismic repository's Prismic Toolbar script. Use the URL to inject the\n * script into your app.\n *\n * @example\n * \t```typescriptreact\n * \t// In Next.js apps, use `next/script` in your `app/layout.tsx` file.\n *\n * \timport Script from \"next/script\";\n * \timport * as prismic from \"@prismicio/client\";\n *\n * \texport default function RootLayout({\n * \tchildren,\n * \t}: {\n * \tchildren: React.ReactNode,\n * \t}) {\n * \tconst toolbarSrc = prismic.getToolbarSrc(\"my-repo\");\n *\n * \treturn (\n * \t<html lang=\"en\">\n * \t<body>{children}</body>\n * \t<Script src={toolbarSrc} />\n * \t</html>\n * \t);\n * \t}\n * \t```\n *\n * @param repositoryName - The name of the Prismic repository. For example, `\"my-repo\"` if the\n * repository URL is `my-repo.prismic.io`.\n * @returns The URL for the given Prismic repository's Prismic Toolbar script.\n */\nexport const getToolbarSrc = <TRepositoryName extends string>(\n\trepositoryName: TRepositoryName,\n): `https://static.cdn.prismic.io/prismic.js?new=true&repo=${TRepositoryName}` => {\n\tif (isRepositoryName(repositoryName)) {\n\t\treturn `https://static.cdn.prismic.io/prismic.js?new=true&repo=${repositoryName}` as const\n\t} else {\n\t\tthrow new PrismicError(\n\t\t\t`An invalid Prismic repository name was given: ${repositoryName}`,\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t)\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAa,iBACZ,mBACiF;CACjF,IAAIA,yBAAAA,iBAAiB,cAAc,GAClC,OAAO,0DAA0D;MAEjE,MAAM,IAAIC,eAAAA,aACT,iDAAiD,kBACjD,KAAA,GACA,KAAA,CACD;AAEF"}
1
+ {"version":3,"file":"getToolbarSrc.cjs","names":["isRepositoryName","PrismicError"],"sources":["../src/getToolbarSrc.ts"],"sourcesContent":["import { PrismicError } from \"./errors\"\nimport { isRepositoryName } from \"./isRepositoryName\"\n\n/**\n * Returns the URL for a Prismic repository's Prismic Toolbar script. Use the URL to inject the\n * script into your app.\n *\n * @example\n * \t```typescriptreact\n * \t// In Next.js apps, use `next/script` in your `app/layout.tsx` file.\n *\n * \timport Script from \"next/script\";\n * \timport * as prismic from \"@prismicio/client\";\n *\n * \texport default function RootLayout({\n * \tchildren,\n * \t}: {\n * \tchildren: React.ReactNode,\n * \t}) {\n * \tconst toolbarSrc = prismic.getToolbarSrc(\"my-repo\");\n *\n * \treturn (\n * \t<html lang=\"en\">\n * \t<body>{children}</body>\n * \t<Script src={toolbarSrc} />\n * \t</html>\n * \t);\n * \t}\n * \t```\n *\n * @param repositoryName - The name of the Prismic repository. For example, `\"my-repo\"` if the\n * repository URL is `my-repo.prismic.io`.\n * @param config - Options that configure the toolbar URL.\n * @returns The URL for the given Prismic repository's Prismic Toolbar script.\n */\nexport const getToolbarSrc = (\n\trepositoryName: string,\n\tconfig?: {\n\t\t/** The version of the Prismic Toolbar to load. Defaults to 4. */\n\t\tversion?: 4 | 5\n\t\t/**\n\t\t * The URL the toolbar script is loaded from, without a trailing slash. For example, a toolbar\n\t\t * preview build. Defaults to `https://static.cdn.prismic.io`.\n\t\t */\n\t\thost?: string\n\t},\n): string => {\n\tif (isRepositoryName(repositoryName)) {\n\t\tconst url = new URL(`${config?.host ?? \"https://static.cdn.prismic.io\"}/prismic.js`)\n\t\turl.searchParams.set(\"repo\", repositoryName)\n\t\tif (config?.version) url.searchParams.set(\"v\", config.version.toString())\n\n\t\treturn url.toString()\n\t} else {\n\t\tthrow new PrismicError(\n\t\t\t`An invalid Prismic repository name was given: ${repositoryName}`,\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t)\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,MAAa,iBACZ,gBACA,WASY;CACZ,IAAIA,yBAAAA,iBAAiB,cAAc,GAAG;EACrC,MAAM,MAAM,IAAI,IAAI,GAAG,QAAQ,QAAQ,gCAAgC,YAAY;EACnF,IAAI,aAAa,IAAI,QAAQ,cAAc;EAC3C,IAAI,QAAQ,SAAS,IAAI,aAAa,IAAI,KAAK,OAAO,QAAQ,SAAS,CAAC;EAExE,OAAO,IAAI,SAAS;CACrB,OACC,MAAM,IAAIC,eAAAA,aACT,iDAAiD,kBACjD,KAAA,GACA,KAAA,CACD;AAEF"}
@@ -28,8 +28,17 @@
28
28
  *
29
29
  * @param repositoryName - The name of the Prismic repository. For example, `"my-repo"` if the
30
30
  * repository URL is `my-repo.prismic.io`.
31
+ * @param config - Options that configure the toolbar URL.
31
32
  * @returns The URL for the given Prismic repository's Prismic Toolbar script.
32
33
  */
33
- export declare const getToolbarSrc: <TRepositoryName extends string>(repositoryName: TRepositoryName) => `https://static.cdn.prismic.io/prismic.js?new=true&repo=${TRepositoryName}`;
34
+ export declare const getToolbarSrc: (repositoryName: string, config?: {
35
+ /** The version of the Prismic Toolbar to load. Defaults to 4. */
36
+ version?: 4 | 5;
37
+ /**
38
+ * The URL the toolbar script is loaded from, without a trailing slash. For example, a toolbar
39
+ * preview build. Defaults to `https://static.cdn.prismic.io`.
40
+ */
41
+ host?: string;
42
+ }) => string;
34
43
  //#endregion
35
44
  //# sourceMappingURL=getToolbarSrc.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getToolbarSrc.d.cts","names":[],"sources":["../src/getToolbarSrc.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAkCa,gBAAiB,gCAA8B,gBAC3C,8EAC4C"}
1
+ {"version":3,"file":"getToolbarSrc.d.cts","names":[],"sources":["../src/getToolbarSrc.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAmCa,gBAAa,wBACH;;EAGrB;;;;;EAKA"}
@@ -28,8 +28,17 @@
28
28
  *
29
29
  * @param repositoryName - The name of the Prismic repository. For example, `"my-repo"` if the
30
30
  * repository URL is `my-repo.prismic.io`.
31
+ * @param config - Options that configure the toolbar URL.
31
32
  * @returns The URL for the given Prismic repository's Prismic Toolbar script.
32
33
  */
33
- export declare const getToolbarSrc: <TRepositoryName extends string>(repositoryName: TRepositoryName) => `https://static.cdn.prismic.io/prismic.js?new=true&repo=${TRepositoryName}`;
34
+ export declare const getToolbarSrc: (repositoryName: string, config?: {
35
+ /** The version of the Prismic Toolbar to load. Defaults to 4. */
36
+ version?: 4 | 5;
37
+ /**
38
+ * The URL the toolbar script is loaded from, without a trailing slash. For example, a toolbar
39
+ * preview build. Defaults to `https://static.cdn.prismic.io`.
40
+ */
41
+ host?: string;
42
+ }) => string;
34
43
  //#endregion
35
44
  //# sourceMappingURL=getToolbarSrc.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getToolbarSrc.d.ts","names":[],"sources":["../src/getToolbarSrc.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAkCa,gBAAiB,gCAA8B,gBAC3C,8EAC4C"}
1
+ {"version":3,"file":"getToolbarSrc.d.ts","names":[],"sources":["../src/getToolbarSrc.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAmCa,gBAAa,wBACH;;EAGrB;;;;;EAKA"}
@@ -30,11 +30,16 @@ import { isRepositoryName } from "./isRepositoryName.js";
30
30
  *
31
31
  * @param repositoryName - The name of the Prismic repository. For example, `"my-repo"` if the
32
32
  * repository URL is `my-repo.prismic.io`.
33
+ * @param config - Options that configure the toolbar URL.
33
34
  * @returns The URL for the given Prismic repository's Prismic Toolbar script.
34
35
  */
35
- const getToolbarSrc = (repositoryName) => {
36
- if (isRepositoryName(repositoryName)) return `https://static.cdn.prismic.io/prismic.js?new=true&repo=${repositoryName}`;
37
- else throw new PrismicError(`An invalid Prismic repository name was given: ${repositoryName}`, void 0, void 0);
36
+ const getToolbarSrc = (repositoryName, config) => {
37
+ if (isRepositoryName(repositoryName)) {
38
+ const url = new URL(`${config?.host ?? "https://static.cdn.prismic.io"}/prismic.js`);
39
+ url.searchParams.set("repo", repositoryName);
40
+ if (config?.version) url.searchParams.set("v", config.version.toString());
41
+ return url.toString();
42
+ } else throw new PrismicError(`An invalid Prismic repository name was given: ${repositoryName}`, void 0, void 0);
38
43
  };
39
44
  //#endregion
40
45
  export { getToolbarSrc };
@@ -1 +1 @@
1
- {"version":3,"file":"getToolbarSrc.js","names":[],"sources":["../src/getToolbarSrc.ts"],"sourcesContent":["import { PrismicError } from \"./errors\"\nimport { isRepositoryName } from \"./isRepositoryName\"\n\n/**\n * Returns the URL for a Prismic repository's Prismic Toolbar script. Use the URL to inject the\n * script into your app.\n *\n * @example\n * \t```typescriptreact\n * \t// In Next.js apps, use `next/script` in your `app/layout.tsx` file.\n *\n * \timport Script from \"next/script\";\n * \timport * as prismic from \"@prismicio/client\";\n *\n * \texport default function RootLayout({\n * \tchildren,\n * \t}: {\n * \tchildren: React.ReactNode,\n * \t}) {\n * \tconst toolbarSrc = prismic.getToolbarSrc(\"my-repo\");\n *\n * \treturn (\n * \t<html lang=\"en\">\n * \t<body>{children}</body>\n * \t<Script src={toolbarSrc} />\n * \t</html>\n * \t);\n * \t}\n * \t```\n *\n * @param repositoryName - The name of the Prismic repository. For example, `\"my-repo\"` if the\n * repository URL is `my-repo.prismic.io`.\n * @returns The URL for the given Prismic repository's Prismic Toolbar script.\n */\nexport const getToolbarSrc = <TRepositoryName extends string>(\n\trepositoryName: TRepositoryName,\n): `https://static.cdn.prismic.io/prismic.js?new=true&repo=${TRepositoryName}` => {\n\tif (isRepositoryName(repositoryName)) {\n\t\treturn `https://static.cdn.prismic.io/prismic.js?new=true&repo=${repositoryName}` as const\n\t} else {\n\t\tthrow new PrismicError(\n\t\t\t`An invalid Prismic repository name was given: ${repositoryName}`,\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t)\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAa,iBACZ,mBACiF;CACjF,IAAI,iBAAiB,cAAc,GAClC,OAAO,0DAA0D;MAEjE,MAAM,IAAI,aACT,iDAAiD,kBACjD,KAAA,GACA,KAAA,CACD;AAEF"}
1
+ {"version":3,"file":"getToolbarSrc.js","names":[],"sources":["../src/getToolbarSrc.ts"],"sourcesContent":["import { PrismicError } from \"./errors\"\nimport { isRepositoryName } from \"./isRepositoryName\"\n\n/**\n * Returns the URL for a Prismic repository's Prismic Toolbar script. Use the URL to inject the\n * script into your app.\n *\n * @example\n * \t```typescriptreact\n * \t// In Next.js apps, use `next/script` in your `app/layout.tsx` file.\n *\n * \timport Script from \"next/script\";\n * \timport * as prismic from \"@prismicio/client\";\n *\n * \texport default function RootLayout({\n * \tchildren,\n * \t}: {\n * \tchildren: React.ReactNode,\n * \t}) {\n * \tconst toolbarSrc = prismic.getToolbarSrc(\"my-repo\");\n *\n * \treturn (\n * \t<html lang=\"en\">\n * \t<body>{children}</body>\n * \t<Script src={toolbarSrc} />\n * \t</html>\n * \t);\n * \t}\n * \t```\n *\n * @param repositoryName - The name of the Prismic repository. For example, `\"my-repo\"` if the\n * repository URL is `my-repo.prismic.io`.\n * @param config - Options that configure the toolbar URL.\n * @returns The URL for the given Prismic repository's Prismic Toolbar script.\n */\nexport const getToolbarSrc = (\n\trepositoryName: string,\n\tconfig?: {\n\t\t/** The version of the Prismic Toolbar to load. Defaults to 4. */\n\t\tversion?: 4 | 5\n\t\t/**\n\t\t * The URL the toolbar script is loaded from, without a trailing slash. For example, a toolbar\n\t\t * preview build. Defaults to `https://static.cdn.prismic.io`.\n\t\t */\n\t\thost?: string\n\t},\n): string => {\n\tif (isRepositoryName(repositoryName)) {\n\t\tconst url = new URL(`${config?.host ?? \"https://static.cdn.prismic.io\"}/prismic.js`)\n\t\turl.searchParams.set(\"repo\", repositoryName)\n\t\tif (config?.version) url.searchParams.set(\"v\", config.version.toString())\n\n\t\treturn url.toString()\n\t} else {\n\t\tthrow new PrismicError(\n\t\t\t`An invalid Prismic repository name was given: ${repositoryName}`,\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t)\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,MAAa,iBACZ,gBACA,WASY;CACZ,IAAI,iBAAiB,cAAc,GAAG;EACrC,MAAM,MAAM,IAAI,IAAI,GAAG,QAAQ,QAAQ,gCAAgC,YAAY;EACnF,IAAI,aAAa,IAAI,QAAQ,cAAc;EAC3C,IAAI,QAAQ,SAAS,IAAI,aAAa,IAAI,KAAK,OAAO,QAAQ,SAAS,CAAC;EAExE,OAAO,IAAI,SAAS;CACrB,OACC,MAAM,IAAI,aACT,iDAAiD,kBACjD,KAAA,GACA,KAAA,CACD;AAEF"}
package/dist/package.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  //#region package.json
2
2
  var name = "@prismicio/client";
3
- var version = "7.23.0-pr.473.7aca245";
3
+ var version = "7.23.0-pr.480.965f57f";
4
4
  //#endregion
5
5
  Object.defineProperty(exports, "name", {
6
6
  enumerable: true,
package/dist/package.js CHANGED
@@ -1,6 +1,6 @@
1
1
  //#region package.json
2
2
  var name = "@prismicio/client";
3
- var version = "7.23.0-pr.473.7aca245";
3
+ var version = "7.23.0-pr.480.965f57f";
4
4
  //#endregion
5
5
  export { name, version };
6
6
 
@@ -14,7 +14,6 @@ uuid.i = 0;
14
14
  * @returns Tree from given rich text or title field
15
15
  */
16
16
  const asTree = (nodes) => {
17
- if (nodes.some((node) => (node.type === require_richText.RichTextNodeType.listItem || node.type === require_richText.RichTextNodeType.oListItem) && (node.depth ?? 0) > 0)) return nestedListsToTree(nodes);
18
17
  const preparedNodes = prepareNodes(nodes);
19
18
  const children = [];
20
19
  for (let i = 0; i < preparedNodes.length; i++) children.push(nodeToTreeNode(preparedNodes[i]));
@@ -23,43 +22,6 @@ const asTree = (nodes) => {
23
22
  children
24
23
  };
25
24
  };
26
- const nestedListsToTree = (nodes) => {
27
- const children = [];
28
- const levels = [];
29
- for (const node of nodes) {
30
- if (node.type !== require_richText.RichTextNodeType.listItem && node.type !== require_richText.RichTextNodeType.oListItem) {
31
- levels.length = 0;
32
- children.push(nodeToTreeNode(node));
33
- continue;
34
- }
35
- const requested = node.depth ?? 0;
36
- const depth = Number.isSafeInteger(requested) && requested >= 0 ? Math.min(requested, levels.length) : 0;
37
- levels.length = Math.min(levels.length, depth + 1);
38
- const listType = node.type === require_richText.RichTextNodeType.listItem ? require_richText.RichTextNodeType.list : require_richText.RichTextNodeType.oList;
39
- let level = levels[depth];
40
- if (!level || level.list.type !== listType) {
41
- const list = createTreeNode(listType === require_richText.RichTextNodeType.list ? {
42
- type: listType,
43
- items: []
44
- } : {
45
- type: listType,
46
- items: []
47
- });
48
- (depth === 0 ? children : levels[depth - 1].lastItem.children).push(list);
49
- level = { list };
50
- levels[depth] = level;
51
- }
52
- const item = nodeToTreeNode(node);
53
- level.list.children.push(item);
54
- if (level.list.node.type === require_richText.RichTextNodeType.list && node.type === require_richText.RichTextNodeType.listItem) level.list.node.items.push(node);
55
- if (level.list.node.type === require_richText.RichTextNodeType.oList && node.type === require_richText.RichTextNodeType.oListItem) level.list.node.items.push(node);
56
- level.lastItem = item;
57
- }
58
- return {
59
- key: uuid(),
60
- children
61
- };
62
- };
63
25
  const createTreeNode = (node, children = []) => {
64
26
  return {
65
27
  key: uuid(),
@@ -1 +1 @@
1
- {"version":3,"file":"asTree.cjs","names":["RichTextNodeType"],"sources":["../../src/richtext/asTree.ts"],"sourcesContent":["import type {\n\tRTAnyNode,\n\tRTBlockNode,\n\tRTInlineNode,\n\tRTListItemNode,\n\tRTNode,\n\tRTOListItemNode,\n\tRTTextNode,\n} from \"../types/value/richText\";\nimport { RichTextNodeType } from \"../types/value/richText\";\nimport type { Tree, TreeNode } from \"./types\";\n\nconst uuid = (): string => {\n\treturn (++uuid.i).toString();\n};\nuuid.i = 0;\n\n/**\n * Parses a rich text or title field into a tree\n *\n * @remarks\n * This is a low level helper mainly intended to be used by higher level packages. Most users\n * aren't expected to this function directly.\n * @param nodes - A rich text or title field from Prismic\n * @returns Tree from given rich text or title field\n */\nexport const asTree = (nodes: RTNode[]): Tree => {\n\tif (\n\t\tnodes.some(\n\t\t\t(node) =>\n\t\t\t\t(node.type === RichTextNodeType.listItem ||\n\t\t\t\t\tnode.type === RichTextNodeType.oListItem) &&\n\t\t\t\t(node.depth ?? 0) > 0,\n\t\t)\n\t) {\n\t\treturn nestedListsToTree(nodes);\n\t}\n\tconst preparedNodes = prepareNodes(nodes);\n\n\tconst children: TreeNode[] = [];\n\tfor (let i = 0; i < preparedNodes.length; i++) {\n\t\tchildren.push(nodeToTreeNode(preparedNodes[i]));\n\t}\n\n\treturn {\n\t\tkey: uuid(),\n\t\tchildren,\n\t};\n};\n\nconst nestedListsToTree = (nodes: RTNode[]): Tree => {\n\tconst children: TreeNode[] = [];\n\tconst levels: { list: TreeNode; lastItem?: TreeNode }[] = [];\n\tfor (const node of nodes) {\n\t\tif (\n\t\t\tnode.type !== RichTextNodeType.listItem &&\n\t\t\tnode.type !== RichTextNodeType.oListItem\n\t\t) {\n\t\t\tlevels.length = 0;\n\t\t\tchildren.push(nodeToTreeNode(node));\n\t\t\tcontinue;\n\t\t}\n\t\tconst requested = node.depth ?? 0;\n\t\tconst depth =\n\t\t\tNumber.isSafeInteger(requested) && requested >= 0\n\t\t\t\t? Math.min(requested, levels.length)\n\t\t\t\t: 0;\n\t\tlevels.length = Math.min(levels.length, depth + 1);\n\t\tconst listType =\n\t\t\tnode.type === RichTextNodeType.listItem\n\t\t\t\t? RichTextNodeType.list\n\t\t\t\t: RichTextNodeType.oList;\n\t\tlet level = levels[depth];\n\t\tif (!level || level.list.type !== listType) {\n\t\t\tconst list = createTreeNode(\n\t\t\t\tlistType === RichTextNodeType.list\n\t\t\t\t\t? { type: listType, items: [] }\n\t\t\t\t\t: { type: listType, items: [] },\n\t\t\t);\n\t\t\tconst siblings =\n\t\t\t\tdepth === 0 ? children : levels[depth - 1].lastItem!.children;\n\t\t\tsiblings.push(list);\n\t\t\tlevel = { list };\n\t\t\tlevels[depth] = level;\n\t\t}\n\t\tconst item = nodeToTreeNode(node);\n\t\tlevel.list.children.push(item);\n\t\tif (\n\t\t\tlevel.list.node.type === RichTextNodeType.list &&\n\t\t\tnode.type === RichTextNodeType.listItem\n\t\t)\n\t\t\tlevel.list.node.items.push(node);\n\t\tif (\n\t\t\tlevel.list.node.type === RichTextNodeType.oList &&\n\t\t\tnode.type === RichTextNodeType.oListItem\n\t\t)\n\t\t\tlevel.list.node.items.push(node);\n\t\tlevel.lastItem = item;\n\t}\n\treturn { key: uuid(), children };\n};\n\nconst createTreeNode = (\n\tnode: RTAnyNode,\n\tchildren: TreeNode[] = [],\n): TreeNode => {\n\treturn {\n\t\tkey: uuid(),\n\t\ttype: node.type,\n\t\ttext: \"text\" in node ? node.text : undefined,\n\t\tnode,\n\t\tchildren,\n\t};\n};\n\nconst createTextTreeNode = (text: string): TreeNode => {\n\treturn createTreeNode({\n\t\ttype: RichTextNodeType.span,\n\t\ttext,\n\t\tspans: [],\n\t});\n};\n\nconst prepareNodes = (nodes: RTNode[]): RTBlockNode[] => {\n\tconst mutNodes: RTBlockNode[] = nodes.slice(0);\n\n\tfor (let i = 0; i < mutNodes.length; i++) {\n\t\tconst node = mutNodes[i];\n\n\t\tif (\n\t\t\tnode.type === RichTextNodeType.listItem ||\n\t\t\tnode.type === RichTextNodeType.oListItem\n\t\t) {\n\t\t\tconst items: (RTListItemNode | RTOListItemNode)[] = [\n\t\t\t\tnode as RTListItemNode | RTOListItemNode,\n\t\t\t];\n\n\t\t\twhile (mutNodes[i + 1] && mutNodes[i + 1].type === node.type) {\n\t\t\t\titems.push(mutNodes[i + 1] as RTListItemNode | RTOListItemNode);\n\t\t\t\tmutNodes.splice(i, 1);\n\t\t\t}\n\n\t\t\tif (node.type === RichTextNodeType.listItem) {\n\t\t\t\tmutNodes[i] = {\n\t\t\t\t\ttype: RichTextNodeType.list,\n\t\t\t\t\titems: items as RTListItemNode[],\n\t\t\t\t};\n\t\t\t} else {\n\t\t\t\tmutNodes[i] = {\n\t\t\t\t\ttype: RichTextNodeType.oList,\n\t\t\t\t\titems: items as RTOListItemNode[],\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t}\n\n\treturn mutNodes;\n};\n\nconst nodeToTreeNode = (node: RTBlockNode): TreeNode => {\n\tif (\"text\" in node) {\n\t\treturn createTreeNode(\n\t\t\tnode,\n\t\t\ttextNodeSpansToTreeNodeChildren(node.spans, node),\n\t\t);\n\t}\n\n\tif (\"items\" in node) {\n\t\tconst children: TreeNode[] = [];\n\t\tfor (let i = 0; i < node.items.length; i++) {\n\t\t\tchildren.push(nodeToTreeNode(node.items[i]));\n\t\t}\n\n\t\treturn createTreeNode(node, children);\n\t}\n\n\treturn createTreeNode(node);\n};\n\nconst textNodeSpansToTreeNodeChildren = (\n\tspans: RTInlineNode[],\n\tnode: RTTextNode,\n\tparentSpan?: RTInlineNode,\n): TreeNode[] => {\n\tif (!spans.length) {\n\t\treturn [createTextTreeNode(node.text)];\n\t}\n\n\tconst mutSpans: RTInlineNode[] = spans.slice(0);\n\n\t// Sort spans using the following criteria:\n\t//\n\t// 1. By start index (ascending)\n\t// 2. If start indices are equal, by end index (descending)\n\t//\n\t// If start and end indices of more than one span are equal, use what\n\t// the API gives without modifications.\n\t//\n\t// Sorting using this algorithm ensures proper detection of child\n\t// spans.\n\tmutSpans.sort((a, b) => a.start - b.start || b.end - a.end);\n\n\tconst children: TreeNode[] = [];\n\n\tfor (let i = 0; i < mutSpans.length; i++) {\n\t\tconst span = mutSpans[i];\n\t\tconst parentSpanStart = (parentSpan && parentSpan.start) || 0;\n\t\tconst spanStart = span.start - parentSpanStart;\n\t\tconst spanEnd = span.end - parentSpanStart;\n\t\tconst text = node.text.slice(spanStart, spanEnd);\n\n\t\tconst childSpans: RTInlineNode[] = [];\n\t\tfor (let j = i; j < mutSpans.length; j++) {\n\t\t\tconst siblingSpan = mutSpans[j];\n\n\t\t\tif (siblingSpan !== span) {\n\t\t\t\tif (siblingSpan.start >= span.start && siblingSpan.end <= span.end) {\n\t\t\t\t\tchildSpans.push(siblingSpan);\n\t\t\t\t\tmutSpans.splice(j, 1);\n\t\t\t\t\tj--;\n\t\t\t\t} else if (\n\t\t\t\t\tsiblingSpan.start < span.end &&\n\t\t\t\t\tsiblingSpan.end > span.start\n\t\t\t\t) {\n\t\t\t\t\tchildSpans.push({\n\t\t\t\t\t\t...siblingSpan,\n\t\t\t\t\t\tend: span.end,\n\t\t\t\t\t});\n\t\t\t\t\tmutSpans[j] = {\n\t\t\t\t\t\t...siblingSpan,\n\t\t\t\t\t\tstart: span.end,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (i === 0 && spanStart > 0) {\n\t\t\tchildren.push(createTextTreeNode(node.text.slice(0, spanStart)));\n\t\t}\n\n\t\tconst spanWithText = { ...span, text };\n\t\tchildren.push(\n\t\t\tcreateTreeNode(\n\t\t\t\tspanWithText,\n\t\t\t\ttextNodeSpansToTreeNodeChildren(\n\t\t\t\t\tchildSpans,\n\t\t\t\t\t{\n\t\t\t\t\t\t...node,\n\t\t\t\t\t\ttext,\n\t\t\t\t\t},\n\t\t\t\t\tspan,\n\t\t\t\t),\n\t\t\t),\n\t\t);\n\n\t\tif (spanEnd < node.text.length) {\n\t\t\tchildren.push(\n\t\t\t\tcreateTextTreeNode(\n\t\t\t\t\tnode.text.slice(\n\t\t\t\t\t\tspanEnd,\n\t\t\t\t\t\tmutSpans[i + 1]\n\t\t\t\t\t\t\t? mutSpans[i + 1].start - parentSpanStart\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t}\n\n\treturn children;\n};\n"],"mappings":";;AAYA,MAAM,aAAqB;CAC1B,QAAQ,EAAE,KAAK,EAAA,CAAG,SAAS;AAC5B;AACA,KAAK,IAAI;;;;;;;;;;AAWT,MAAa,UAAU,UAA0B;CAChD,IACC,MAAM,MACJ,UACC,KAA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,MAAM,KAAK,YAAY,GAC1B,SAAS,KAAK,mBAAmB,KAAK,KAAK,MAAM,GAAG,SAAS,CAAC,CAAC;EAGhE,MAAM,eAAe;GAAE,GAAG;GAAM;EAAK;EACrC,SAAS,KACR,eACC,cACA,gCACC,YACA;GACC,GAAG;GACH;EACD,GACA,IACD,CACD,CACD;EAEA,IAAI,UAAU,KAAK,KAAK,QACvB,SAAS,KACR,mBACC,KAAK,KAAK,MACT,SACA,SAAS,IAAI,KACV,SAAS,IAAI,EAAE,CAAC,QAAQ,kBACxB,KAAA,CACJ,CACD,CACD;CAEF;CAEA,OAAO;AACR"}
1
+ {"version":3,"file":"asTree.cjs","names":["RichTextNodeType"],"sources":["../../src/richtext/asTree.ts"],"sourcesContent":["import type {\n\tRTAnyNode,\n\tRTBlockNode,\n\tRTInlineNode,\n\tRTListItemNode,\n\tRTNode,\n\tRTOListItemNode,\n\tRTTextNode,\n} from \"../types/value/richText\"\nimport { RichTextNodeType } from \"../types/value/richText\"\nimport type { Tree, TreeNode } from \"./types\"\n\nconst uuid = (): string => {\n\treturn (++uuid.i).toString()\n}\nuuid.i = 0\n\n/**\n * Parses a rich text or title field into a tree\n *\n * @remarks\n * This is a low level helper mainly intended to be used by higher level packages. Most users\n * aren't expected to this function directly.\n * @param nodes - A rich text or title field from Prismic\n * @returns Tree from given rich text or title field\n */\nexport const asTree = (nodes: RTNode[]): Tree => {\n\tconst preparedNodes = prepareNodes(nodes)\n\n\tconst children: TreeNode[] = []\n\tfor (let i = 0; i < preparedNodes.length; i++) {\n\t\tchildren.push(nodeToTreeNode(preparedNodes[i]))\n\t}\n\n\treturn {\n\t\tkey: uuid(),\n\t\tchildren,\n\t}\n}\n\nconst createTreeNode = (node: RTAnyNode, children: TreeNode[] = []): TreeNode => {\n\treturn {\n\t\tkey: uuid(),\n\t\ttype: node.type,\n\t\ttext: \"text\" in node ? node.text : undefined,\n\t\tnode,\n\t\tchildren,\n\t}\n}\n\nconst createTextTreeNode = (text: string): TreeNode => {\n\treturn createTreeNode({\n\t\ttype: RichTextNodeType.span,\n\t\ttext,\n\t\tspans: [],\n\t})\n}\n\nconst prepareNodes = (nodes: RTNode[]): RTBlockNode[] => {\n\tconst mutNodes: RTBlockNode[] = nodes.slice(0)\n\n\tfor (let i = 0; i < mutNodes.length; i++) {\n\t\tconst node = mutNodes[i]\n\n\t\tif (node.type === RichTextNodeType.listItem || node.type === RichTextNodeType.oListItem) {\n\t\t\tconst items: (RTListItemNode | RTOListItemNode)[] = [node as RTListItemNode | RTOListItemNode]\n\n\t\t\twhile (mutNodes[i + 1] && mutNodes[i + 1].type === node.type) {\n\t\t\t\titems.push(mutNodes[i + 1] as RTListItemNode | RTOListItemNode)\n\t\t\t\tmutNodes.splice(i, 1)\n\t\t\t}\n\n\t\t\tif (node.type === RichTextNodeType.listItem) {\n\t\t\t\tmutNodes[i] = {\n\t\t\t\t\ttype: RichTextNodeType.list,\n\t\t\t\t\titems: items as RTListItemNode[],\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tmutNodes[i] = {\n\t\t\t\t\ttype: RichTextNodeType.oList,\n\t\t\t\t\titems: items as RTOListItemNode[],\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn mutNodes\n}\n\nconst nodeToTreeNode = (node: RTBlockNode): TreeNode => {\n\tif (\"text\" in node) {\n\t\treturn createTreeNode(node, textNodeSpansToTreeNodeChildren(node.spans, node))\n\t}\n\n\tif (\"items\" in node) {\n\t\tconst children: TreeNode[] = []\n\t\tfor (let i = 0; i < node.items.length; i++) {\n\t\t\tchildren.push(nodeToTreeNode(node.items[i]))\n\t\t}\n\n\t\treturn createTreeNode(node, children)\n\t}\n\n\treturn createTreeNode(node)\n}\n\nconst textNodeSpansToTreeNodeChildren = (\n\tspans: RTInlineNode[],\n\tnode: RTTextNode,\n\tparentSpan?: RTInlineNode,\n): TreeNode[] => {\n\tif (!spans.length) {\n\t\treturn [createTextTreeNode(node.text)]\n\t}\n\n\tconst mutSpans: RTInlineNode[] = spans.slice(0)\n\n\t// Sort spans using the following criteria:\n\t//\n\t// 1. By start index (ascending)\n\t// 2. If start indices are equal, by end index (descending)\n\t//\n\t// If start and end indices of more than one span are equal, use what\n\t// the API gives without modifications.\n\t//\n\t// Sorting using this algorithm ensures proper detection of child\n\t// spans.\n\tmutSpans.sort((a, b) => a.start - b.start || b.end - a.end)\n\n\tconst children: TreeNode[] = []\n\n\tfor (let i = 0; i < mutSpans.length; i++) {\n\t\tconst span = mutSpans[i]\n\t\tconst parentSpanStart = (parentSpan && parentSpan.start) || 0\n\t\tconst spanStart = span.start - parentSpanStart\n\t\tconst spanEnd = span.end - parentSpanStart\n\t\tconst text = node.text.slice(spanStart, spanEnd)\n\n\t\tconst childSpans: RTInlineNode[] = []\n\t\tfor (let j = i; j < mutSpans.length; j++) {\n\t\t\tconst siblingSpan = mutSpans[j]\n\n\t\t\tif (siblingSpan !== span) {\n\t\t\t\tif (siblingSpan.start >= span.start && siblingSpan.end <= span.end) {\n\t\t\t\t\tchildSpans.push(siblingSpan)\n\t\t\t\t\tmutSpans.splice(j, 1)\n\t\t\t\t\tj--\n\t\t\t\t} else if (siblingSpan.start < span.end && siblingSpan.end > span.start) {\n\t\t\t\t\tchildSpans.push({\n\t\t\t\t\t\t...siblingSpan,\n\t\t\t\t\t\tend: span.end,\n\t\t\t\t\t})\n\t\t\t\t\tmutSpans[j] = {\n\t\t\t\t\t\t...siblingSpan,\n\t\t\t\t\t\tstart: span.end,\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (i === 0 && spanStart > 0) {\n\t\t\tchildren.push(createTextTreeNode(node.text.slice(0, spanStart)))\n\t\t}\n\n\t\tconst spanWithText = { ...span, text }\n\t\tchildren.push(\n\t\t\tcreateTreeNode(\n\t\t\t\tspanWithText,\n\t\t\t\ttextNodeSpansToTreeNodeChildren(\n\t\t\t\t\tchildSpans,\n\t\t\t\t\t{\n\t\t\t\t\t\t...node,\n\t\t\t\t\t\ttext,\n\t\t\t\t\t},\n\t\t\t\t\tspan,\n\t\t\t\t),\n\t\t\t),\n\t\t)\n\n\t\tif (spanEnd < node.text.length) {\n\t\t\tchildren.push(\n\t\t\t\tcreateTextTreeNode(\n\t\t\t\t\tnode.text.slice(\n\t\t\t\t\t\tspanEnd,\n\t\t\t\t\t\tmutSpans[i + 1] ? mutSpans[i + 1].start - parentSpanStart : undefined,\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t)\n\t\t}\n\t}\n\n\treturn children\n}\n"],"mappings":";;AAYA,MAAM,aAAqB;CAC1B,QAAQ,EAAE,KAAK,EAAA,CAAG,SAAS;AAC5B;AACA,KAAK,IAAI;;;;;;;;;;AAWT,MAAa,UAAU,UAA0B;CAChD,MAAM,gBAAgB,aAAa,KAAK;CAExC,MAAM,WAAuB,CAAC;CAC9B,KAAK,IAAI,IAAI,GAAG,IAAI,cAAc,QAAQ,KACzC,SAAS,KAAK,eAAe,cAAc,EAAE,CAAC;CAG/C,OAAO;EACN,KAAK,KAAK;EACV;CACD;AACD;AAEA,MAAM,kBAAkB,MAAiB,WAAuB,CAAC,MAAgB;CAChF,OAAO;EACN,KAAK,KAAK;EACV,MAAM,KAAK;EACX,MAAM,UAAU,OAAO,KAAK,OAAO,KAAA;EACnC;EACA;CACD;AACD;AAEA,MAAM,sBAAsB,SAA2B;CACtD,OAAO,eAAe;EACrB,MAAMA,iBAAAA,iBAAiB;EACvB;EACA,OAAO,CAAC;CACT,CAAC;AACF;AAEA,MAAM,gBAAgB,UAAmC;CACxD,MAAM,WAA0B,MAAM,MAAM,CAAC;CAE7C,KAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KAAK;EACzC,MAAM,OAAO,SAAS;EAEtB,IAAI,KAAK,SAASA,iBAAAA,iBAAiB,YAAY,KAAK,SAASA,iBAAAA,iBAAiB,WAAW;GACxF,MAAM,QAA8C,CAAC,IAAwC;GAE7F,OAAO,SAAS,IAAI,MAAM,SAAS,IAAI,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B,IAAI,YAAY,SAAS,KAAK,SAAS,YAAY,OAAO,KAAK,KAAK;KACnE,WAAW,KAAK,WAAW;KAC3B,SAAS,OAAO,GAAG,CAAC;KACpB;IACD,OAAO,IAAI,YAAY,QAAQ,KAAK,OAAO,YAAY,MAAM,KAAK,OAAO;KACxE,WAAW,KAAK;MACf,GAAG;MACH,KAAK,KAAK;KACX,CAAC;KACD,SAAS,KAAK;MACb,GAAG;MACH,OAAO,KAAK;KACb;IACD;GACD;EACD;EAEA,IAAI,MAAM,KAAK,YAAY,GAC1B,SAAS,KAAK,mBAAmB,KAAK,KAAK,MAAM,GAAG,SAAS,CAAC,CAAC;EAGhE,MAAM,eAAe;GAAE,GAAG;GAAM;EAAK;EACrC,SAAS,KACR,eACC,cACA,gCACC,YACA;GACC,GAAG;GACH;EACD,GACA,IACD,CACD,CACD;EAEA,IAAI,UAAU,KAAK,KAAK,QACvB,SAAS,KACR,mBACC,KAAK,KAAK,MACT,SACA,SAAS,IAAI,KAAK,SAAS,IAAI,EAAE,CAAC,QAAQ,kBAAkB,KAAA,CAC7D,CACD,CACD;CAEF;CAEA,OAAO;AACR"}
@@ -14,7 +14,6 @@ uuid.i = 0;
14
14
  * @returns Tree from given rich text or title field
15
15
  */
16
16
  const asTree = (nodes) => {
17
- if (nodes.some((node) => (node.type === RichTextNodeType.listItem || node.type === RichTextNodeType.oListItem) && (node.depth ?? 0) > 0)) return nestedListsToTree(nodes);
18
17
  const preparedNodes = prepareNodes(nodes);
19
18
  const children = [];
20
19
  for (let i = 0; i < preparedNodes.length; i++) children.push(nodeToTreeNode(preparedNodes[i]));
@@ -23,43 +22,6 @@ const asTree = (nodes) => {
23
22
  children
24
23
  };
25
24
  };
26
- const nestedListsToTree = (nodes) => {
27
- const children = [];
28
- const levels = [];
29
- for (const node of nodes) {
30
- if (node.type !== RichTextNodeType.listItem && node.type !== RichTextNodeType.oListItem) {
31
- levels.length = 0;
32
- children.push(nodeToTreeNode(node));
33
- continue;
34
- }
35
- const requested = node.depth ?? 0;
36
- const depth = Number.isSafeInteger(requested) && requested >= 0 ? Math.min(requested, levels.length) : 0;
37
- levels.length = Math.min(levels.length, depth + 1);
38
- const listType = node.type === RichTextNodeType.listItem ? RichTextNodeType.list : RichTextNodeType.oList;
39
- let level = levels[depth];
40
- if (!level || level.list.type !== listType) {
41
- const list = createTreeNode(listType === RichTextNodeType.list ? {
42
- type: listType,
43
- items: []
44
- } : {
45
- type: listType,
46
- items: []
47
- });
48
- (depth === 0 ? children : levels[depth - 1].lastItem.children).push(list);
49
- level = { list };
50
- levels[depth] = level;
51
- }
52
- const item = nodeToTreeNode(node);
53
- level.list.children.push(item);
54
- if (level.list.node.type === RichTextNodeType.list && node.type === RichTextNodeType.listItem) level.list.node.items.push(node);
55
- if (level.list.node.type === RichTextNodeType.oList && node.type === RichTextNodeType.oListItem) level.list.node.items.push(node);
56
- level.lastItem = item;
57
- }
58
- return {
59
- key: uuid(),
60
- children
61
- };
62
- };
63
25
  const createTreeNode = (node, children = []) => {
64
26
  return {
65
27
  key: uuid(),
@@ -1 +1 @@
1
- {"version":3,"file":"asTree.js","names":[],"sources":["../../src/richtext/asTree.ts"],"sourcesContent":["import type {\n\tRTAnyNode,\n\tRTBlockNode,\n\tRTInlineNode,\n\tRTListItemNode,\n\tRTNode,\n\tRTOListItemNode,\n\tRTTextNode,\n} from \"../types/value/richText\";\nimport { RichTextNodeType } from \"../types/value/richText\";\nimport type { Tree, TreeNode } from \"./types\";\n\nconst uuid = (): string => {\n\treturn (++uuid.i).toString();\n};\nuuid.i = 0;\n\n/**\n * Parses a rich text or title field into a tree\n *\n * @remarks\n * This is a low level helper mainly intended to be used by higher level packages. Most users\n * aren't expected to this function directly.\n * @param nodes - A rich text or title field from Prismic\n * @returns Tree from given rich text or title field\n */\nexport const asTree = (nodes: RTNode[]): Tree => {\n\tif (\n\t\tnodes.some(\n\t\t\t(node) =>\n\t\t\t\t(node.type === RichTextNodeType.listItem ||\n\t\t\t\t\tnode.type === RichTextNodeType.oListItem) &&\n\t\t\t\t(node.depth ?? 0) > 0,\n\t\t)\n\t) {\n\t\treturn nestedListsToTree(nodes);\n\t}\n\tconst preparedNodes = prepareNodes(nodes);\n\n\tconst children: TreeNode[] = [];\n\tfor (let i = 0; i < preparedNodes.length; i++) {\n\t\tchildren.push(nodeToTreeNode(preparedNodes[i]));\n\t}\n\n\treturn {\n\t\tkey: uuid(),\n\t\tchildren,\n\t};\n};\n\nconst nestedListsToTree = (nodes: RTNode[]): Tree => {\n\tconst children: TreeNode[] = [];\n\tconst levels: { list: TreeNode; lastItem?: TreeNode }[] = [];\n\tfor (const node of nodes) {\n\t\tif (\n\t\t\tnode.type !== RichTextNodeType.listItem &&\n\t\t\tnode.type !== RichTextNodeType.oListItem\n\t\t) {\n\t\t\tlevels.length = 0;\n\t\t\tchildren.push(nodeToTreeNode(node));\n\t\t\tcontinue;\n\t\t}\n\t\tconst requested = node.depth ?? 0;\n\t\tconst depth =\n\t\t\tNumber.isSafeInteger(requested) && requested >= 0\n\t\t\t\t? Math.min(requested, levels.length)\n\t\t\t\t: 0;\n\t\tlevels.length = Math.min(levels.length, depth + 1);\n\t\tconst listType =\n\t\t\tnode.type === RichTextNodeType.listItem\n\t\t\t\t? RichTextNodeType.list\n\t\t\t\t: RichTextNodeType.oList;\n\t\tlet level = levels[depth];\n\t\tif (!level || level.list.type !== listType) {\n\t\t\tconst list = createTreeNode(\n\t\t\t\tlistType === RichTextNodeType.list\n\t\t\t\t\t? { type: listType, items: [] }\n\t\t\t\t\t: { type: listType, items: [] },\n\t\t\t);\n\t\t\tconst siblings =\n\t\t\t\tdepth === 0 ? children : levels[depth - 1].lastItem!.children;\n\t\t\tsiblings.push(list);\n\t\t\tlevel = { list };\n\t\t\tlevels[depth] = level;\n\t\t}\n\t\tconst item = nodeToTreeNode(node);\n\t\tlevel.list.children.push(item);\n\t\tif (\n\t\t\tlevel.list.node.type === RichTextNodeType.list &&\n\t\t\tnode.type === RichTextNodeType.listItem\n\t\t)\n\t\t\tlevel.list.node.items.push(node);\n\t\tif (\n\t\t\tlevel.list.node.type === RichTextNodeType.oList &&\n\t\t\tnode.type === RichTextNodeType.oListItem\n\t\t)\n\t\t\tlevel.list.node.items.push(node);\n\t\tlevel.lastItem = item;\n\t}\n\treturn { key: uuid(), children };\n};\n\nconst createTreeNode = (\n\tnode: RTAnyNode,\n\tchildren: TreeNode[] = [],\n): TreeNode => {\n\treturn {\n\t\tkey: uuid(),\n\t\ttype: node.type,\n\t\ttext: \"text\" in node ? node.text : undefined,\n\t\tnode,\n\t\tchildren,\n\t};\n};\n\nconst createTextTreeNode = (text: string): TreeNode => {\n\treturn createTreeNode({\n\t\ttype: RichTextNodeType.span,\n\t\ttext,\n\t\tspans: [],\n\t});\n};\n\nconst prepareNodes = (nodes: RTNode[]): RTBlockNode[] => {\n\tconst mutNodes: RTBlockNode[] = nodes.slice(0);\n\n\tfor (let i = 0; i < mutNodes.length; i++) {\n\t\tconst node = mutNodes[i];\n\n\t\tif (\n\t\t\tnode.type === RichTextNodeType.listItem ||\n\t\t\tnode.type === RichTextNodeType.oListItem\n\t\t) {\n\t\t\tconst items: (RTListItemNode | RTOListItemNode)[] = [\n\t\t\t\tnode as RTListItemNode | RTOListItemNode,\n\t\t\t];\n\n\t\t\twhile (mutNodes[i + 1] && mutNodes[i + 1].type === node.type) {\n\t\t\t\titems.push(mutNodes[i + 1] as RTListItemNode | RTOListItemNode);\n\t\t\t\tmutNodes.splice(i, 1);\n\t\t\t}\n\n\t\t\tif (node.type === RichTextNodeType.listItem) {\n\t\t\t\tmutNodes[i] = {\n\t\t\t\t\ttype: RichTextNodeType.list,\n\t\t\t\t\titems: items as RTListItemNode[],\n\t\t\t\t};\n\t\t\t} else {\n\t\t\t\tmutNodes[i] = {\n\t\t\t\t\ttype: RichTextNodeType.oList,\n\t\t\t\t\titems: items as RTOListItemNode[],\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t}\n\n\treturn mutNodes;\n};\n\nconst nodeToTreeNode = (node: RTBlockNode): TreeNode => {\n\tif (\"text\" in node) {\n\t\treturn createTreeNode(\n\t\t\tnode,\n\t\t\ttextNodeSpansToTreeNodeChildren(node.spans, node),\n\t\t);\n\t}\n\n\tif (\"items\" in node) {\n\t\tconst children: TreeNode[] = [];\n\t\tfor (let i = 0; i < node.items.length; i++) {\n\t\t\tchildren.push(nodeToTreeNode(node.items[i]));\n\t\t}\n\n\t\treturn createTreeNode(node, children);\n\t}\n\n\treturn createTreeNode(node);\n};\n\nconst textNodeSpansToTreeNodeChildren = (\n\tspans: RTInlineNode[],\n\tnode: RTTextNode,\n\tparentSpan?: RTInlineNode,\n): TreeNode[] => {\n\tif (!spans.length) {\n\t\treturn [createTextTreeNode(node.text)];\n\t}\n\n\tconst mutSpans: RTInlineNode[] = spans.slice(0);\n\n\t// Sort spans using the following criteria:\n\t//\n\t// 1. By start index (ascending)\n\t// 2. If start indices are equal, by end index (descending)\n\t//\n\t// If start and end indices of more than one span are equal, use what\n\t// the API gives without modifications.\n\t//\n\t// Sorting using this algorithm ensures proper detection of child\n\t// spans.\n\tmutSpans.sort((a, b) => a.start - b.start || b.end - a.end);\n\n\tconst children: TreeNode[] = [];\n\n\tfor (let i = 0; i < mutSpans.length; i++) {\n\t\tconst span = mutSpans[i];\n\t\tconst parentSpanStart = (parentSpan && parentSpan.start) || 0;\n\t\tconst spanStart = span.start - parentSpanStart;\n\t\tconst spanEnd = span.end - parentSpanStart;\n\t\tconst text = node.text.slice(spanStart, spanEnd);\n\n\t\tconst childSpans: RTInlineNode[] = [];\n\t\tfor (let j = i; j < mutSpans.length; j++) {\n\t\t\tconst siblingSpan = mutSpans[j];\n\n\t\t\tif (siblingSpan !== span) {\n\t\t\t\tif (siblingSpan.start >= span.start && siblingSpan.end <= span.end) {\n\t\t\t\t\tchildSpans.push(siblingSpan);\n\t\t\t\t\tmutSpans.splice(j, 1);\n\t\t\t\t\tj--;\n\t\t\t\t} else if (\n\t\t\t\t\tsiblingSpan.start < span.end &&\n\t\t\t\t\tsiblingSpan.end > span.start\n\t\t\t\t) {\n\t\t\t\t\tchildSpans.push({\n\t\t\t\t\t\t...siblingSpan,\n\t\t\t\t\t\tend: span.end,\n\t\t\t\t\t});\n\t\t\t\t\tmutSpans[j] = {\n\t\t\t\t\t\t...siblingSpan,\n\t\t\t\t\t\tstart: span.end,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (i === 0 && spanStart > 0) {\n\t\t\tchildren.push(createTextTreeNode(node.text.slice(0, spanStart)));\n\t\t}\n\n\t\tconst spanWithText = { ...span, text };\n\t\tchildren.push(\n\t\t\tcreateTreeNode(\n\t\t\t\tspanWithText,\n\t\t\t\ttextNodeSpansToTreeNodeChildren(\n\t\t\t\t\tchildSpans,\n\t\t\t\t\t{\n\t\t\t\t\t\t...node,\n\t\t\t\t\t\ttext,\n\t\t\t\t\t},\n\t\t\t\t\tspan,\n\t\t\t\t),\n\t\t\t),\n\t\t);\n\n\t\tif (spanEnd < node.text.length) {\n\t\t\tchildren.push(\n\t\t\t\tcreateTextTreeNode(\n\t\t\t\t\tnode.text.slice(\n\t\t\t\t\t\tspanEnd,\n\t\t\t\t\t\tmutSpans[i + 1]\n\t\t\t\t\t\t\t? mutSpans[i + 1].start - parentSpanStart\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t}\n\n\treturn children;\n};\n"],"mappings":";;AAYA,MAAM,aAAqB;CAC1B,QAAQ,EAAE,KAAK,EAAA,CAAG,SAAS;AAC5B;AACA,KAAK,IAAI;;;;;;;;;;AAWT,MAAa,UAAU,UAA0B;CAChD,IACC,MAAM,MACJ,UACC,KAAK,SAAS,iBAAiB,YAC/B,KAAK,SAAS,iBAAiB,eAC/B,KAAK,SAAS,KAAK,CACtB,GAEA,OAAO,kBAAkB,KAAK;CAE/B,MAAM,gBAAgB,aAAa,KAAK;CAExC,MAAM,WAAuB,CAAC;CAC9B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AAQ,kBACxB,KAAA,CACJ,CACD,CACD;CAEF;CAEA,OAAO;AACR"}
1
+ {"version":3,"file":"asTree.js","names":[],"sources":["../../src/richtext/asTree.ts"],"sourcesContent":["import type {\n\tRTAnyNode,\n\tRTBlockNode,\n\tRTInlineNode,\n\tRTListItemNode,\n\tRTNode,\n\tRTOListItemNode,\n\tRTTextNode,\n} from \"../types/value/richText\"\nimport { RichTextNodeType } from \"../types/value/richText\"\nimport type { Tree, TreeNode } from \"./types\"\n\nconst uuid = (): string => {\n\treturn (++uuid.i).toString()\n}\nuuid.i = 0\n\n/**\n * Parses a rich text or title field into a tree\n *\n * @remarks\n * This is a low level helper mainly intended to be used by higher level packages. Most users\n * aren't expected to this function directly.\n * @param nodes - A rich text or title field from Prismic\n * @returns Tree from given rich text or title field\n */\nexport const asTree = (nodes: RTNode[]): Tree => {\n\tconst preparedNodes = prepareNodes(nodes)\n\n\tconst children: TreeNode[] = []\n\tfor (let i = 0; i < preparedNodes.length; i++) {\n\t\tchildren.push(nodeToTreeNode(preparedNodes[i]))\n\t}\n\n\treturn {\n\t\tkey: uuid(),\n\t\tchildren,\n\t}\n}\n\nconst createTreeNode = (node: RTAnyNode, children: TreeNode[] = []): TreeNode => {\n\treturn {\n\t\tkey: uuid(),\n\t\ttype: node.type,\n\t\ttext: \"text\" in node ? node.text : undefined,\n\t\tnode,\n\t\tchildren,\n\t}\n}\n\nconst createTextTreeNode = (text: string): TreeNode => {\n\treturn createTreeNode({\n\t\ttype: RichTextNodeType.span,\n\t\ttext,\n\t\tspans: [],\n\t})\n}\n\nconst prepareNodes = (nodes: RTNode[]): RTBlockNode[] => {\n\tconst mutNodes: RTBlockNode[] = nodes.slice(0)\n\n\tfor (let i = 0; i < mutNodes.length; i++) {\n\t\tconst node = mutNodes[i]\n\n\t\tif (node.type === RichTextNodeType.listItem || node.type === RichTextNodeType.oListItem) {\n\t\t\tconst items: (RTListItemNode | RTOListItemNode)[] = [node as RTListItemNode | RTOListItemNode]\n\n\t\t\twhile (mutNodes[i + 1] && mutNodes[i + 1].type === node.type) {\n\t\t\t\titems.push(mutNodes[i + 1] as RTListItemNode | RTOListItemNode)\n\t\t\t\tmutNodes.splice(i, 1)\n\t\t\t}\n\n\t\t\tif (node.type === RichTextNodeType.listItem) {\n\t\t\t\tmutNodes[i] = {\n\t\t\t\t\ttype: RichTextNodeType.list,\n\t\t\t\t\titems: items as RTListItemNode[],\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tmutNodes[i] = {\n\t\t\t\t\ttype: RichTextNodeType.oList,\n\t\t\t\t\titems: items as RTOListItemNode[],\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn mutNodes\n}\n\nconst nodeToTreeNode = (node: RTBlockNode): TreeNode => {\n\tif (\"text\" in node) {\n\t\treturn createTreeNode(node, textNodeSpansToTreeNodeChildren(node.spans, node))\n\t}\n\n\tif (\"items\" in node) {\n\t\tconst children: TreeNode[] = []\n\t\tfor (let i = 0; i < node.items.length; i++) {\n\t\t\tchildren.push(nodeToTreeNode(node.items[i]))\n\t\t}\n\n\t\treturn createTreeNode(node, children)\n\t}\n\n\treturn createTreeNode(node)\n}\n\nconst textNodeSpansToTreeNodeChildren = (\n\tspans: RTInlineNode[],\n\tnode: RTTextNode,\n\tparentSpan?: RTInlineNode,\n): TreeNode[] => {\n\tif (!spans.length) {\n\t\treturn [createTextTreeNode(node.text)]\n\t}\n\n\tconst mutSpans: RTInlineNode[] = spans.slice(0)\n\n\t// Sort spans using the following criteria:\n\t//\n\t// 1. By start index (ascending)\n\t// 2. If start indices are equal, by end index (descending)\n\t//\n\t// If start and end indices of more than one span are equal, use what\n\t// the API gives without modifications.\n\t//\n\t// Sorting using this algorithm ensures proper detection of child\n\t// spans.\n\tmutSpans.sort((a, b) => a.start - b.start || b.end - a.end)\n\n\tconst children: TreeNode[] = []\n\n\tfor (let i = 0; i < mutSpans.length; i++) {\n\t\tconst span = mutSpans[i]\n\t\tconst parentSpanStart = (parentSpan && parentSpan.start) || 0\n\t\tconst spanStart = span.start - parentSpanStart\n\t\tconst spanEnd = span.end - parentSpanStart\n\t\tconst text = node.text.slice(spanStart, spanEnd)\n\n\t\tconst childSpans: RTInlineNode[] = []\n\t\tfor (let j = i; j < mutSpans.length; j++) {\n\t\t\tconst siblingSpan = mutSpans[j]\n\n\t\t\tif (siblingSpan !== span) {\n\t\t\t\tif (siblingSpan.start >= span.start && siblingSpan.end <= span.end) {\n\t\t\t\t\tchildSpans.push(siblingSpan)\n\t\t\t\t\tmutSpans.splice(j, 1)\n\t\t\t\t\tj--\n\t\t\t\t} else if (siblingSpan.start < span.end && siblingSpan.end > span.start) {\n\t\t\t\t\tchildSpans.push({\n\t\t\t\t\t\t...siblingSpan,\n\t\t\t\t\t\tend: span.end,\n\t\t\t\t\t})\n\t\t\t\t\tmutSpans[j] = {\n\t\t\t\t\t\t...siblingSpan,\n\t\t\t\t\t\tstart: span.end,\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (i === 0 && spanStart > 0) {\n\t\t\tchildren.push(createTextTreeNode(node.text.slice(0, spanStart)))\n\t\t}\n\n\t\tconst spanWithText = { ...span, text }\n\t\tchildren.push(\n\t\t\tcreateTreeNode(\n\t\t\t\tspanWithText,\n\t\t\t\ttextNodeSpansToTreeNodeChildren(\n\t\t\t\t\tchildSpans,\n\t\t\t\t\t{\n\t\t\t\t\t\t...node,\n\t\t\t\t\t\ttext,\n\t\t\t\t\t},\n\t\t\t\t\tspan,\n\t\t\t\t),\n\t\t\t),\n\t\t)\n\n\t\tif (spanEnd < node.text.length) {\n\t\t\tchildren.push(\n\t\t\t\tcreateTextTreeNode(\n\t\t\t\t\tnode.text.slice(\n\t\t\t\t\t\tspanEnd,\n\t\t\t\t\t\tmutSpans[i + 1] ? mutSpans[i + 1].start - parentSpanStart : undefined,\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t)\n\t\t}\n\t}\n\n\treturn children\n}\n"],"mappings":";;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AAC,CAAC;EAGhE,MAAM,eAAe;GAAE,GAAG;GAAM;EAAK;EACrC,SAAS,KACR,eACC,cACA,gCACC,YACA;GACC,GAAG;GACH;EACD,GACA,IACD,CACD,CACD;EAEA,IAAI,UAAU,KAAK,KAAK,QACvB,SAAS,KACR,mBACC,KAAK,KAAK,MACT,SACA,SAAS,IAAI,KAAK,SAAS,IAAI,EAAE,CAAC,QAAQ,kBAAkB,KAAA,CAC7D,CACD,CACD;CAEF;CAEA,OAAO;AACR"}
@@ -1 +1 @@
1
- {"version":3,"file":"richText.cjs","names":[],"sources":["../../../src/types/value/richText.ts"],"sourcesContent":["import type { EmbedField } from \"./embed\"\nimport type { FilledLinkField } from \"./link\"\nimport type { FieldState } from \"./types\"\n\n/**\n * Types enum for RichTextNodes\n *\n * @see More details: {@link https://prismic.io/docs/rich-text-title}\n */\nexport const RichTextNodeType = {\n\theading1: \"heading1\",\n\theading2: \"heading2\",\n\theading3: \"heading3\",\n\theading4: \"heading4\",\n\theading5: \"heading5\",\n\theading6: \"heading6\",\n\tparagraph: \"paragraph\",\n\tpreformatted: \"preformatted\",\n\tstrong: \"strong\",\n\tem: \"em\",\n\tlistItem: \"list-item\",\n\toListItem: \"o-list-item\",\n\tlist: \"group-list-item\",\n\toList: \"group-o-list-item\",\n\timage: \"image\",\n\tembed: \"embed\",\n\thyperlink: \"hyperlink\",\n\tlabel: \"label\",\n\tspan: \"span\",\n} as const\n\n/**\n * Types for RichTextNodes\n *\n * @see More details: {@link https://prismic.io/docs/rich-text-title}\n */\nexport type RichTextNodeTypes = (typeof RichTextNodeType)[keyof typeof RichTextNodeType]\n\n// Text nodes\n\n/** Base to be extended by other rich text nodes. */\nexport interface RTTextNodeBase {\n\ttext: string\n\tspans: RTInlineNode[]\n\tdirection?: \"ltr\" | \"rtl\"\n}\n\n/** Rich text `heading1` node */\nexport interface RTHeading1Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading1\n}\n\n/** Rich text `heading2` node */\nexport interface RTHeading2Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading2\n}\n\n/** Rich text `heading3` node */\nexport interface RTHeading3Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading3\n}\n\n/** Rich text `heading4` node */\nexport interface RTHeading4Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading4\n}\n\n/** Rich text `heading5` node */\nexport interface RTHeading5Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading5\n}\n\n/** Rich text `heading6` node */\nexport interface RTHeading6Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading6\n}\n\n/** Rich text `paragraph` node */\nexport interface RTParagraphNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.paragraph\n}\n\n/** Rich text `preformatted` node */\nexport interface RTPreformattedNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.preformatted\n}\n\n/** Rich text `list-item` node */\nexport interface RTListItemNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.listItem\n\t/** Indentation level; omitted for a root list item. */\n\tdepth?: number\n}\n\n/** Rich text `o-list-item` node for ordered lists */\nexport interface RTOListItemNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.oListItem\n\t/** Indentation level; omitted for a root list item. */\n\tdepth?: number\n}\n\n// Span nodes\n\n/** @internal Span Node base to be extended for other Span nodes */\nexport interface RTSpanNodeBase {\n\tstart: number\n\tend: number\n}\n/** Rich text `strong` node */\nexport interface RTStrongNode extends RTSpanNodeBase {\n\ttype: typeof RichTextNodeType.strong\n}\n\n/** Rich text `embed` node */\nexport interface RTEmNode extends RTSpanNodeBase {\n\ttype: typeof RichTextNodeType.em\n}\n\n/** Rich text `label` node */\nexport interface RTLabelNode extends RTSpanNodeBase {\n\ttype: typeof RichTextNodeType.label\n\tdata: {\n\t\tlabel: string\n\t}\n}\n\n// Media nodes\n\n/** Rich text `image` nodes. They could link to other documents, external web links and media fields */\nexport type RTImageNode = {\n\ttype: typeof RichTextNodeType.image\n\tid: string\n\turl: string\n\talt: string | null\n\tcopyright: string | null\n\tdimensions: {\n\t\twidth: number\n\t\theight: number\n\t}\n\tedit: {\n\t\tx: number\n\t\ty: number\n\t\tzoom: number\n\t\tbackground: string\n\t}\n\tlinkTo?: FilledLinkField\n}\n\n/** Rich text `embed` node */\nexport type RTEmbedNode = {\n\ttype: typeof RichTextNodeType.embed\n\toembed: EmbedField\n}\n\n// Link nodes\n\n/**\n * Rich text `a` node\n *\n * @see More details: {@link https://prismic.io/docs/rich-text-title#elements-and-styles}\n */\nexport interface RTLinkNode extends RTSpanNodeBase {\n\ttype: typeof RichTextNodeType.hyperlink\n\tdata: FilledLinkField\n}\n\n// Serialization related nodes\n\n/** Rich text `list` node */\nexport interface RTListNode {\n\ttype: typeof RichTextNodeType.list\n\titems: RTListItemNode[]\n}\n\n/** Rich text o-lost node */\nexport interface RTOListNode {\n\ttype: typeof RichTextNodeType.oList\n\titems: RTOListItemNode[]\n}\n\n// This one is confusing but it's actually the inner content of a block\n/** Rich text `span` node */\nexport interface RTSpanNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.span\n}\n\n// Helpers\n\n/** Nodes from a rich text field */\nexport type RTNode =\n\t| RTHeading1Node\n\t| RTHeading2Node\n\t| RTHeading3Node\n\t| RTHeading4Node\n\t| RTHeading5Node\n\t| RTHeading6Node\n\t| RTParagraphNode\n\t| RTPreformattedNode\n\t| RTListItemNode\n\t| RTOListItemNode\n\t| RTImageNode\n\t| RTEmbedNode\n\n/** Rich text nodes with text */\nexport type RTTextNode =\n\t| RTHeading1Node\n\t| RTHeading2Node\n\t| RTHeading3Node\n\t| RTHeading4Node\n\t| RTHeading5Node\n\t| RTHeading6Node\n\t| RTParagraphNode\n\t| RTPreformattedNode\n\t| RTListItemNode\n\t| RTOListItemNode\n\n/** Rich text block nodes */\nexport type RTBlockNode =\n\t| RTHeading1Node\n\t| RTHeading2Node\n\t| RTHeading3Node\n\t| RTHeading4Node\n\t| RTHeading5Node\n\t| RTHeading6Node\n\t| RTParagraphNode\n\t| RTPreformattedNode\n\t| RTListItemNode\n\t| RTOListItemNode\n\t| RTListNode\n\t| RTOListNode\n\t| RTImageNode\n\t| RTEmbedNode\n\n/** Inline rich text nodes */\nexport type RTInlineNode = RTStrongNode | RTEmNode | RTLabelNode | RTLinkNode\n\n/** All rich text nodes */\nexport type RTAnyNode = RTBlockNode | RTInlineNode | RTSpanNode\n\n/**\n * A rich text field.\n *\n * @see Rich text field documentation: {@link https://prismic.io/docs/rich-text-title}\n */\nexport type RichTextField<State extends FieldState = FieldState> =\n\tState extends \"empty\" ? [] : [RTNode, ...RTNode[]]\n"],"mappings":";;;;;;AASA,MAAa,mBAAmB;CAC/B,UAAU;CACV,UAAU;CACV,UAAU;CACV,UAAU;CACV,UAAU;CACV,UAAU;CACV,WAAW;CACX,cAAc;CACd,QAAQ;CACR,IAAI;CACJ,UAAU;CACV,WAAW;CACX,MAAM;CACN,OAAO;CACP,OAAO;CACP,OAAO;CACP,WAAW;CACX,OAAO;CACP,MAAM;AACP"}
1
+ {"version":3,"file":"richText.cjs","names":[],"sources":["../../../src/types/value/richText.ts"],"sourcesContent":["import type { EmbedField } from \"./embed\"\nimport type { FilledLinkField } from \"./link\"\nimport type { FieldState } from \"./types\"\n\n/**\n * Types enum for RichTextNodes\n *\n * @see More details: {@link https://prismic.io/docs/rich-text-title}\n */\nexport const RichTextNodeType = {\n\theading1: \"heading1\",\n\theading2: \"heading2\",\n\theading3: \"heading3\",\n\theading4: \"heading4\",\n\theading5: \"heading5\",\n\theading6: \"heading6\",\n\tparagraph: \"paragraph\",\n\tpreformatted: \"preformatted\",\n\tstrong: \"strong\",\n\tem: \"em\",\n\tlistItem: \"list-item\",\n\toListItem: \"o-list-item\",\n\tlist: \"group-list-item\",\n\toList: \"group-o-list-item\",\n\timage: \"image\",\n\tembed: \"embed\",\n\thyperlink: \"hyperlink\",\n\tlabel: \"label\",\n\tspan: \"span\",\n} as const\n\n/**\n * Types for RichTextNodes\n *\n * @see More details: {@link https://prismic.io/docs/rich-text-title}\n */\nexport type RichTextNodeTypes = (typeof RichTextNodeType)[keyof typeof RichTextNodeType]\n\n// Text nodes\n\n/** Base to be extended by other rich text nodes. */\nexport interface RTTextNodeBase {\n\ttext: string\n\tspans: RTInlineNode[]\n\tdirection?: \"ltr\" | \"rtl\"\n}\n\n/** Rich text `heading1` node */\nexport interface RTHeading1Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading1\n}\n\n/** Rich text `heading2` node */\nexport interface RTHeading2Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading2\n}\n\n/** Rich text `heading3` node */\nexport interface RTHeading3Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading3\n}\n\n/** Rich text `heading4` node */\nexport interface RTHeading4Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading4\n}\n\n/** Rich text `heading5` node */\nexport interface RTHeading5Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading5\n}\n\n/** Rich text `heading6` node */\nexport interface RTHeading6Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading6\n}\n\n/** Rich text `paragraph` node */\nexport interface RTParagraphNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.paragraph\n}\n\n/** Rich text `preformatted` node */\nexport interface RTPreformattedNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.preformatted\n}\n\n/** Rich text `list-item` node */\nexport interface RTListItemNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.listItem\n}\n\n/** Rich text `o-list-item` node for ordered lists */\nexport interface RTOListItemNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.oListItem\n}\n\n// Span nodes\n\n/** @internal Span Node base to be extended for other Span nodes */\nexport interface RTSpanNodeBase {\n\tstart: number\n\tend: number\n}\n/** Rich text `strong` node */\nexport interface RTStrongNode extends RTSpanNodeBase {\n\ttype: typeof RichTextNodeType.strong\n}\n\n/** Rich text `embed` node */\nexport interface RTEmNode extends RTSpanNodeBase {\n\ttype: typeof RichTextNodeType.em\n}\n\n/** Rich text `label` node */\nexport interface RTLabelNode extends RTSpanNodeBase {\n\ttype: typeof RichTextNodeType.label\n\tdata: {\n\t\tlabel: string\n\t}\n}\n\n// Media nodes\n\n/** Rich text `image` nodes. They could link to other documents, external web links and media fields */\nexport type RTImageNode = {\n\ttype: typeof RichTextNodeType.image\n\tid: string\n\turl: string\n\talt: string | null\n\tcopyright: string | null\n\tdimensions: {\n\t\twidth: number\n\t\theight: number\n\t}\n\tedit: {\n\t\tx: number\n\t\ty: number\n\t\tzoom: number\n\t\tbackground: string\n\t}\n\tlinkTo?: FilledLinkField\n}\n\n/** Rich text `embed` node */\nexport type RTEmbedNode = {\n\ttype: typeof RichTextNodeType.embed\n\toembed: EmbedField\n}\n\n// Link nodes\n\n/**\n * Rich text `a` node\n *\n * @see More details: {@link https://prismic.io/docs/rich-text-title#elements-and-styles}\n */\nexport interface RTLinkNode extends RTSpanNodeBase {\n\ttype: typeof RichTextNodeType.hyperlink\n\tdata: FilledLinkField\n}\n\n// Serialization related nodes\n\n/** Rich text `list` node */\nexport interface RTListNode {\n\ttype: typeof RichTextNodeType.list\n\titems: RTListItemNode[]\n}\n\n/** Rich text o-lost node */\nexport interface RTOListNode {\n\ttype: typeof RichTextNodeType.oList\n\titems: RTOListItemNode[]\n}\n\n// This one is confusing but it's actually the inner content of a block\n/** Rich text `span` node */\nexport interface RTSpanNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.span\n}\n\n// Helpers\n\n/** Nodes from a rich text field */\nexport type RTNode =\n\t| RTHeading1Node\n\t| RTHeading2Node\n\t| RTHeading3Node\n\t| RTHeading4Node\n\t| RTHeading5Node\n\t| RTHeading6Node\n\t| RTParagraphNode\n\t| RTPreformattedNode\n\t| RTListItemNode\n\t| RTOListItemNode\n\t| RTImageNode\n\t| RTEmbedNode\n\n/** Rich text nodes with text */\nexport type RTTextNode =\n\t| RTHeading1Node\n\t| RTHeading2Node\n\t| RTHeading3Node\n\t| RTHeading4Node\n\t| RTHeading5Node\n\t| RTHeading6Node\n\t| RTParagraphNode\n\t| RTPreformattedNode\n\t| RTListItemNode\n\t| RTOListItemNode\n\n/** Rich text block nodes */\nexport type RTBlockNode =\n\t| RTHeading1Node\n\t| RTHeading2Node\n\t| RTHeading3Node\n\t| RTHeading4Node\n\t| RTHeading5Node\n\t| RTHeading6Node\n\t| RTParagraphNode\n\t| RTPreformattedNode\n\t| RTListItemNode\n\t| RTOListItemNode\n\t| RTListNode\n\t| RTOListNode\n\t| RTImageNode\n\t| RTEmbedNode\n\n/** Inline rich text nodes */\nexport type RTInlineNode = RTStrongNode | RTEmNode | RTLabelNode | RTLinkNode\n\n/** All rich text nodes */\nexport type RTAnyNode = RTBlockNode | RTInlineNode | RTSpanNode\n\n/**\n * A rich text field.\n *\n * @see Rich text field documentation: {@link https://prismic.io/docs/rich-text-title}\n */\nexport type RichTextField<State extends FieldState = FieldState> = State extends \"empty\"\n\t? []\n\t: [RTNode, ...RTNode[]]\n"],"mappings":";;;;;;AASA,MAAa,mBAAmB;CAC/B,UAAU;CACV,UAAU;CACV,UAAU;CACV,UAAU;CACV,UAAU;CACV,UAAU;CACV,WAAW;CACX,cAAc;CACd,QAAQ;CACR,IAAI;CACJ,UAAU;CACV,WAAW;CACX,MAAM;CACN,OAAO;CACP,OAAO;CACP,OAAO;CACP,WAAW;CACX,OAAO;CACP,MAAM;AACP"}
@@ -75,14 +75,10 @@ export interface RTPreformattedNode extends RTTextNodeBase {
75
75
  /** Rich text `list-item` node */
76
76
  export interface RTListItemNode extends RTTextNodeBase {
77
77
  type: typeof RichTextNodeType.listItem;
78
- /** Indentation level; omitted for a root list item. */
79
- depth?: number;
80
78
  }
81
79
  /** Rich text `o-list-item` node for ordered lists */
82
80
  export interface RTOListItemNode extends RTTextNodeBase {
83
81
  type: typeof RichTextNodeType.oListItem;
84
- /** Indentation level; omitted for a root list item. */
85
- depth?: number;
86
82
  }
87
83
  /** @internal Span Node base to be extended for other Span nodes */
88
84
  export interface RTSpanNodeBase {
@@ -1 +1 @@
1
- {"version":3,"file":"richText.d.cts","names":[],"sources":["../../../src/types/value/richText.ts"],"mappings":";;;;;;;;;qBASa;WACZ;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;;;;;;;YAQW,4BAA4B,+BAA+B;;iBAKtD;EAChB;EACA,OAAO;EACP;;;iBAIgB,uBAAuB;EACvC,aAAa,iBAAiB;;;iBAId,uBAAuB;EACvC,aAAa,iBAAiB;;;iBAId,uBAAuB;EACvC,aAAa,iBAAiB;;;iBAId,uBAAuB;EACvC,aAAa,iBAAiB;;;iBAId,uBAAuB;EACvC,aAAa,iBAAiB;;;iBAId,uBAAuB;EACvC,aAAa,iBAAiB;;;iBAId,wBAAwB;EACxC,aAAa,iBAAiB;;;iBAId,2BAA2B;EAC3C,aAAa,iBAAiB;;;iBAId,uBAAuB;EACvC,aAAa,iBAAiB;;EAE9B;;;iBAIgB,wBAAwB;EACxC,aAAa,iBAAiB;;EAE9B;;;iBAMgB;EAChB;EACA;;;iBAGgB,qBAAqB;EACrC,aAAa,iBAAiB;;;iBAId,iBAAiB;EACjC,aAAa,iBAAiB;;;iBAId,oBAAoB;EACpC,aAAa,iBAAiB;EAC9B;IACC;;;;YAOU;EACX,aAAa,iBAAiB;EAC9B;EACA;EACA;EACA;EACA;IACC;IACA;;EAED;IACC;IACA;IACA;IACA;;EAED,SAAS;;;YAIE;EACX,aAAa,iBAAiB;EAC9B,QAAQ;;;;;;;iBAUQ,mBAAmB;EACnC,aAAa,iBAAiB;EAC9B,MAAM;;;iBAMU;EAChB,aAAa,iBAAiB;EAC9B,OAAO;;;iBAIS;EAChB,aAAa,iBAAiB;EAC9B,OAAO;;;iBAKS,mBAAmB;EACnC,aAAa,iBAAiB;;;YAMnB,SACT,iBACA,iBACA,iBACA,iBACA,iBACA,iBACA,kBACA,qBACA,iBACA,kBACA,cACA;;YAGS,aACT,iBACA,iBACA,iBACA,iBACA,iBACA,iBACA,kBACA,qBACA,iBACA;;YAGS,cACT,iBACA,iBACA,iBACA,iBACA,iBACA,iBACA,kBACA,qBACA,iBACA,kBACA,aACA,cACA,cACA;;YAGS,eAAe,eAAe,WAAW,cAAc;;YAGvD,YAAY,cAAc,eAAe;;;;;;YAOzC,cAAc,cAAc,aAAa,cACpD,8BAA8B,WAAW"}
1
+ {"version":3,"file":"richText.d.cts","names":[],"sources":["../../../src/types/value/richText.ts"],"mappings":";;;;;;;;;qBASa;WACZ;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;;;;;;;YAQW,4BAA4B,+BAA+B;;iBAKtD;EAChB;EACA,OAAO;EACP;;;iBAIgB,uBAAuB;EACvC,aAAa,iBAAiB;;;iBAId,uBAAuB;EACvC,aAAa,iBAAiB;;;iBAId,uBAAuB;EACvC,aAAa,iBAAiB;;;iBAId,uBAAuB;EACvC,aAAa,iBAAiB;;;iBAId,uBAAuB;EACvC,aAAa,iBAAiB;;;iBAId,uBAAuB;EACvC,aAAa,iBAAiB;;;iBAId,wBAAwB;EACxC,aAAa,iBAAiB;;;iBAId,2BAA2B;EAC3C,aAAa,iBAAiB;;;iBAId,uBAAuB;EACvC,aAAa,iBAAiB;;;iBAId,wBAAwB;EACxC,aAAa,iBAAiB;;;iBAMd;EAChB;EACA;;;iBAGgB,qBAAqB;EACrC,aAAa,iBAAiB;;;iBAId,iBAAiB;EACjC,aAAa,iBAAiB;;;iBAId,oBAAoB;EACpC,aAAa,iBAAiB;EAC9B;IACC;;;;YAOU;EACX,aAAa,iBAAiB;EAC9B;EACA;EACA;EACA;EACA;IACC;IACA;;EAED;IACC;IACA;IACA;IACA;;EAED,SAAS;;;YAIE;EACX,aAAa,iBAAiB;EAC9B,QAAQ;;;;;;;iBAUQ,mBAAmB;EACnC,aAAa,iBAAiB;EAC9B,MAAM;;;iBAMU;EAChB,aAAa,iBAAiB;EAC9B,OAAO;;;iBAIS;EAChB,aAAa,iBAAiB;EAC9B,OAAO;;;iBAKS,mBAAmB;EACnC,aAAa,iBAAiB;;;YAMnB,SACT,iBACA,iBACA,iBACA,iBACA,iBACA,iBACA,kBACA,qBACA,iBACA,kBACA,cACA;;YAGS,aACT,iBACA,iBACA,iBACA,iBACA,iBACA,iBACA,kBACA,qBACA,iBACA;;YAGS,cACT,iBACA,iBACA,iBACA,iBACA,iBACA,iBACA,kBACA,qBACA,iBACA,kBACA,aACA,cACA,cACA;;YAGS,eAAe,eAAe,WAAW,cAAc;;YAGvD,YAAY,cAAc,eAAe;;;;;;YAOzC,cAAc,cAAc,aAAa,cAAc,8BAE/D,WAAW"}
@@ -75,14 +75,10 @@ export interface RTPreformattedNode extends RTTextNodeBase {
75
75
  /** Rich text `list-item` node */
76
76
  export interface RTListItemNode extends RTTextNodeBase {
77
77
  type: typeof RichTextNodeType.listItem;
78
- /** Indentation level; omitted for a root list item. */
79
- depth?: number;
80
78
  }
81
79
  /** Rich text `o-list-item` node for ordered lists */
82
80
  export interface RTOListItemNode extends RTTextNodeBase {
83
81
  type: typeof RichTextNodeType.oListItem;
84
- /** Indentation level; omitted for a root list item. */
85
- depth?: number;
86
82
  }
87
83
  /** @internal Span Node base to be extended for other Span nodes */
88
84
  export interface RTSpanNodeBase {
@@ -1 +1 @@
1
- {"version":3,"file":"richText.d.ts","names":[],"sources":["../../../src/types/value/richText.ts"],"mappings":";;;;;;;;;qBASa;WACZ;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;;;;;;;YAQW,4BAA4B,+BAA+B;;iBAKtD;EAChB;EACA,OAAO;EACP;;;iBAIgB,uBAAuB;EACvC,aAAa,iBAAiB;;;iBAId,uBAAuB;EACvC,aAAa,iBAAiB;;;iBAId,uBAAuB;EACvC,aAAa,iBAAiB;;;iBAId,uBAAuB;EACvC,aAAa,iBAAiB;;;iBAId,uBAAuB;EACvC,aAAa,iBAAiB;;;iBAId,uBAAuB;EACvC,aAAa,iBAAiB;;;iBAId,wBAAwB;EACxC,aAAa,iBAAiB;;;iBAId,2BAA2B;EAC3C,aAAa,iBAAiB;;;iBAId,uBAAuB;EACvC,aAAa,iBAAiB;;EAE9B;;;iBAIgB,wBAAwB;EACxC,aAAa,iBAAiB;;EAE9B;;;iBAMgB;EAChB;EACA;;;iBAGgB,qBAAqB;EACrC,aAAa,iBAAiB;;;iBAId,iBAAiB;EACjC,aAAa,iBAAiB;;;iBAId,oBAAoB;EACpC,aAAa,iBAAiB;EAC9B;IACC;;;;YAOU;EACX,aAAa,iBAAiB;EAC9B;EACA;EACA;EACA;EACA;IACC;IACA;;EAED;IACC;IACA;IACA;IACA;;EAED,SAAS;;;YAIE;EACX,aAAa,iBAAiB;EAC9B,QAAQ;;;;;;;iBAUQ,mBAAmB;EACnC,aAAa,iBAAiB;EAC9B,MAAM;;;iBAMU;EAChB,aAAa,iBAAiB;EAC9B,OAAO;;;iBAIS;EAChB,aAAa,iBAAiB;EAC9B,OAAO;;;iBAKS,mBAAmB;EACnC,aAAa,iBAAiB;;;YAMnB,SACT,iBACA,iBACA,iBACA,iBACA,iBACA,iBACA,kBACA,qBACA,iBACA,kBACA,cACA;;YAGS,aACT,iBACA,iBACA,iBACA,iBACA,iBACA,iBACA,kBACA,qBACA,iBACA;;YAGS,cACT,iBACA,iBACA,iBACA,iBACA,iBACA,iBACA,kBACA,qBACA,iBACA,kBACA,aACA,cACA,cACA;;YAGS,eAAe,eAAe,WAAW,cAAc;;YAGvD,YAAY,cAAc,eAAe;;;;;;YAOzC,cAAc,cAAc,aAAa,cACpD,8BAA8B,WAAW"}
1
+ {"version":3,"file":"richText.d.ts","names":[],"sources":["../../../src/types/value/richText.ts"],"mappings":";;;;;;;;;qBASa;WACZ;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WAC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AAc,eAAe;;;;;;YAOzC,cAAc,cAAc,aAAa,cAAc,8BAE/D,WAAW"}
@@ -1 +1 @@
1
- {"version":3,"file":"richText.js","names":[],"sources":["../../../src/types/value/richText.ts"],"sourcesContent":["import type { EmbedField } from \"./embed\"\nimport type { FilledLinkField } from \"./link\"\nimport type { FieldState } from \"./types\"\n\n/**\n * Types enum for RichTextNodes\n *\n * @see More details: {@link https://prismic.io/docs/rich-text-title}\n */\nexport const RichTextNodeType = {\n\theading1: \"heading1\",\n\theading2: \"heading2\",\n\theading3: \"heading3\",\n\theading4: \"heading4\",\n\theading5: \"heading5\",\n\theading6: \"heading6\",\n\tparagraph: \"paragraph\",\n\tpreformatted: \"preformatted\",\n\tstrong: \"strong\",\n\tem: \"em\",\n\tlistItem: \"list-item\",\n\toListItem: \"o-list-item\",\n\tlist: \"group-list-item\",\n\toList: \"group-o-list-item\",\n\timage: \"image\",\n\tembed: \"embed\",\n\thyperlink: \"hyperlink\",\n\tlabel: \"label\",\n\tspan: \"span\",\n} as const\n\n/**\n * Types for RichTextNodes\n *\n * @see More details: {@link https://prismic.io/docs/rich-text-title}\n */\nexport type RichTextNodeTypes = (typeof RichTextNodeType)[keyof typeof RichTextNodeType]\n\n// Text nodes\n\n/** Base to be extended by other rich text nodes. */\nexport interface RTTextNodeBase {\n\ttext: string\n\tspans: RTInlineNode[]\n\tdirection?: \"ltr\" | \"rtl\"\n}\n\n/** Rich text `heading1` node */\nexport interface RTHeading1Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading1\n}\n\n/** Rich text `heading2` node */\nexport interface RTHeading2Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading2\n}\n\n/** Rich text `heading3` node */\nexport interface RTHeading3Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading3\n}\n\n/** Rich text `heading4` node */\nexport interface RTHeading4Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading4\n}\n\n/** Rich text `heading5` node */\nexport interface RTHeading5Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading5\n}\n\n/** Rich text `heading6` node */\nexport interface RTHeading6Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading6\n}\n\n/** Rich text `paragraph` node */\nexport interface RTParagraphNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.paragraph\n}\n\n/** Rich text `preformatted` node */\nexport interface RTPreformattedNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.preformatted\n}\n\n/** Rich text `list-item` node */\nexport interface RTListItemNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.listItem\n\t/** Indentation level; omitted for a root list item. */\n\tdepth?: number\n}\n\n/** Rich text `o-list-item` node for ordered lists */\nexport interface RTOListItemNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.oListItem\n\t/** Indentation level; omitted for a root list item. */\n\tdepth?: number\n}\n\n// Span nodes\n\n/** @internal Span Node base to be extended for other Span nodes */\nexport interface RTSpanNodeBase {\n\tstart: number\n\tend: number\n}\n/** Rich text `strong` node */\nexport interface RTStrongNode extends RTSpanNodeBase {\n\ttype: typeof RichTextNodeType.strong\n}\n\n/** Rich text `embed` node */\nexport interface RTEmNode extends RTSpanNodeBase {\n\ttype: typeof RichTextNodeType.em\n}\n\n/** Rich text `label` node */\nexport interface RTLabelNode extends RTSpanNodeBase {\n\ttype: typeof RichTextNodeType.label\n\tdata: {\n\t\tlabel: string\n\t}\n}\n\n// Media nodes\n\n/** Rich text `image` nodes. They could link to other documents, external web links and media fields */\nexport type RTImageNode = {\n\ttype: typeof RichTextNodeType.image\n\tid: string\n\turl: string\n\talt: string | null\n\tcopyright: string | null\n\tdimensions: {\n\t\twidth: number\n\t\theight: number\n\t}\n\tedit: {\n\t\tx: number\n\t\ty: number\n\t\tzoom: number\n\t\tbackground: string\n\t}\n\tlinkTo?: FilledLinkField\n}\n\n/** Rich text `embed` node */\nexport type RTEmbedNode = {\n\ttype: typeof RichTextNodeType.embed\n\toembed: EmbedField\n}\n\n// Link nodes\n\n/**\n * Rich text `a` node\n *\n * @see More details: {@link https://prismic.io/docs/rich-text-title#elements-and-styles}\n */\nexport interface RTLinkNode extends RTSpanNodeBase {\n\ttype: typeof RichTextNodeType.hyperlink\n\tdata: FilledLinkField\n}\n\n// Serialization related nodes\n\n/** Rich text `list` node */\nexport interface RTListNode {\n\ttype: typeof RichTextNodeType.list\n\titems: RTListItemNode[]\n}\n\n/** Rich text o-lost node */\nexport interface RTOListNode {\n\ttype: typeof RichTextNodeType.oList\n\titems: RTOListItemNode[]\n}\n\n// This one is confusing but it's actually the inner content of a block\n/** Rich text `span` node */\nexport interface RTSpanNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.span\n}\n\n// Helpers\n\n/** Nodes from a rich text field */\nexport type RTNode =\n\t| RTHeading1Node\n\t| RTHeading2Node\n\t| RTHeading3Node\n\t| RTHeading4Node\n\t| RTHeading5Node\n\t| RTHeading6Node\n\t| RTParagraphNode\n\t| RTPreformattedNode\n\t| RTListItemNode\n\t| RTOListItemNode\n\t| RTImageNode\n\t| RTEmbedNode\n\n/** Rich text nodes with text */\nexport type RTTextNode =\n\t| RTHeading1Node\n\t| RTHeading2Node\n\t| RTHeading3Node\n\t| RTHeading4Node\n\t| RTHeading5Node\n\t| RTHeading6Node\n\t| RTParagraphNode\n\t| RTPreformattedNode\n\t| RTListItemNode\n\t| RTOListItemNode\n\n/** Rich text block nodes */\nexport type RTBlockNode =\n\t| RTHeading1Node\n\t| RTHeading2Node\n\t| RTHeading3Node\n\t| RTHeading4Node\n\t| RTHeading5Node\n\t| RTHeading6Node\n\t| RTParagraphNode\n\t| RTPreformattedNode\n\t| RTListItemNode\n\t| RTOListItemNode\n\t| RTListNode\n\t| RTOListNode\n\t| RTImageNode\n\t| RTEmbedNode\n\n/** Inline rich text nodes */\nexport type RTInlineNode = RTStrongNode | RTEmNode | RTLabelNode | RTLinkNode\n\n/** All rich text nodes */\nexport type RTAnyNode = RTBlockNode | RTInlineNode | RTSpanNode\n\n/**\n * A rich text field.\n *\n * @see Rich text field documentation: {@link https://prismic.io/docs/rich-text-title}\n */\nexport type RichTextField<State extends FieldState = FieldState> =\n\tState extends \"empty\" ? [] : [RTNode, ...RTNode[]]\n"],"mappings":";;;;;;AASA,MAAa,mBAAmB;CAC/B,UAAU;CACV,UAAU;CACV,UAAU;CACV,UAAU;CACV,UAAU;CACV,UAAU;CACV,WAAW;CACX,cAAc;CACd,QAAQ;CACR,IAAI;CACJ,UAAU;CACV,WAAW;CACX,MAAM;CACN,OAAO;CACP,OAAO;CACP,OAAO;CACP,WAAW;CACX,OAAO;CACP,MAAM;AACP"}
1
+ {"version":3,"file":"richText.js","names":[],"sources":["../../../src/types/value/richText.ts"],"sourcesContent":["import type { EmbedField } from \"./embed\"\nimport type { FilledLinkField } from \"./link\"\nimport type { FieldState } from \"./types\"\n\n/**\n * Types enum for RichTextNodes\n *\n * @see More details: {@link https://prismic.io/docs/rich-text-title}\n */\nexport const RichTextNodeType = {\n\theading1: \"heading1\",\n\theading2: \"heading2\",\n\theading3: \"heading3\",\n\theading4: \"heading4\",\n\theading5: \"heading5\",\n\theading6: \"heading6\",\n\tparagraph: \"paragraph\",\n\tpreformatted: \"preformatted\",\n\tstrong: \"strong\",\n\tem: \"em\",\n\tlistItem: \"list-item\",\n\toListItem: \"o-list-item\",\n\tlist: \"group-list-item\",\n\toList: \"group-o-list-item\",\n\timage: \"image\",\n\tembed: \"embed\",\n\thyperlink: \"hyperlink\",\n\tlabel: \"label\",\n\tspan: \"span\",\n} as const\n\n/**\n * Types for RichTextNodes\n *\n * @see More details: {@link https://prismic.io/docs/rich-text-title}\n */\nexport type RichTextNodeTypes = (typeof RichTextNodeType)[keyof typeof RichTextNodeType]\n\n// Text nodes\n\n/** Base to be extended by other rich text nodes. */\nexport interface RTTextNodeBase {\n\ttext: string\n\tspans: RTInlineNode[]\n\tdirection?: \"ltr\" | \"rtl\"\n}\n\n/** Rich text `heading1` node */\nexport interface RTHeading1Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading1\n}\n\n/** Rich text `heading2` node */\nexport interface RTHeading2Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading2\n}\n\n/** Rich text `heading3` node */\nexport interface RTHeading3Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading3\n}\n\n/** Rich text `heading4` node */\nexport interface RTHeading4Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading4\n}\n\n/** Rich text `heading5` node */\nexport interface RTHeading5Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading5\n}\n\n/** Rich text `heading6` node */\nexport interface RTHeading6Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading6\n}\n\n/** Rich text `paragraph` node */\nexport interface RTParagraphNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.paragraph\n}\n\n/** Rich text `preformatted` node */\nexport interface RTPreformattedNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.preformatted\n}\n\n/** Rich text `list-item` node */\nexport interface RTListItemNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.listItem\n}\n\n/** Rich text `o-list-item` node for ordered lists */\nexport interface RTOListItemNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.oListItem\n}\n\n// Span nodes\n\n/** @internal Span Node base to be extended for other Span nodes */\nexport interface RTSpanNodeBase {\n\tstart: number\n\tend: number\n}\n/** Rich text `strong` node */\nexport interface RTStrongNode extends RTSpanNodeBase {\n\ttype: typeof RichTextNodeType.strong\n}\n\n/** Rich text `embed` node */\nexport interface RTEmNode extends RTSpanNodeBase {\n\ttype: typeof RichTextNodeType.em\n}\n\n/** Rich text `label` node */\nexport interface RTLabelNode extends RTSpanNodeBase {\n\ttype: typeof RichTextNodeType.label\n\tdata: {\n\t\tlabel: string\n\t}\n}\n\n// Media nodes\n\n/** Rich text `image` nodes. They could link to other documents, external web links and media fields */\nexport type RTImageNode = {\n\ttype: typeof RichTextNodeType.image\n\tid: string\n\turl: string\n\talt: string | null\n\tcopyright: string | null\n\tdimensions: {\n\t\twidth: number\n\t\theight: number\n\t}\n\tedit: {\n\t\tx: number\n\t\ty: number\n\t\tzoom: number\n\t\tbackground: string\n\t}\n\tlinkTo?: FilledLinkField\n}\n\n/** Rich text `embed` node */\nexport type RTEmbedNode = {\n\ttype: typeof RichTextNodeType.embed\n\toembed: EmbedField\n}\n\n// Link nodes\n\n/**\n * Rich text `a` node\n *\n * @see More details: {@link https://prismic.io/docs/rich-text-title#elements-and-styles}\n */\nexport interface RTLinkNode extends RTSpanNodeBase {\n\ttype: typeof RichTextNodeType.hyperlink\n\tdata: FilledLinkField\n}\n\n// Serialization related nodes\n\n/** Rich text `list` node */\nexport interface RTListNode {\n\ttype: typeof RichTextNodeType.list\n\titems: RTListItemNode[]\n}\n\n/** Rich text o-lost node */\nexport interface RTOListNode {\n\ttype: typeof RichTextNodeType.oList\n\titems: RTOListItemNode[]\n}\n\n// This one is confusing but it's actually the inner content of a block\n/** Rich text `span` node */\nexport interface RTSpanNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.span\n}\n\n// Helpers\n\n/** Nodes from a rich text field */\nexport type RTNode =\n\t| RTHeading1Node\n\t| RTHeading2Node\n\t| RTHeading3Node\n\t| RTHeading4Node\n\t| RTHeading5Node\n\t| RTHeading6Node\n\t| RTParagraphNode\n\t| RTPreformattedNode\n\t| RTListItemNode\n\t| RTOListItemNode\n\t| RTImageNode\n\t| RTEmbedNode\n\n/** Rich text nodes with text */\nexport type RTTextNode =\n\t| RTHeading1Node\n\t| RTHeading2Node\n\t| RTHeading3Node\n\t| RTHeading4Node\n\t| RTHeading5Node\n\t| RTHeading6Node\n\t| RTParagraphNode\n\t| RTPreformattedNode\n\t| RTListItemNode\n\t| RTOListItemNode\n\n/** Rich text block nodes */\nexport type RTBlockNode =\n\t| RTHeading1Node\n\t| RTHeading2Node\n\t| RTHeading3Node\n\t| RTHeading4Node\n\t| RTHeading5Node\n\t| RTHeading6Node\n\t| RTParagraphNode\n\t| RTPreformattedNode\n\t| RTListItemNode\n\t| RTOListItemNode\n\t| RTListNode\n\t| RTOListNode\n\t| RTImageNode\n\t| RTEmbedNode\n\n/** Inline rich text nodes */\nexport type RTInlineNode = RTStrongNode | RTEmNode | RTLabelNode | RTLinkNode\n\n/** All rich text nodes */\nexport type RTAnyNode = RTBlockNode | RTInlineNode | RTSpanNode\n\n/**\n * A rich text field.\n *\n * @see Rich text field documentation: {@link https://prismic.io/docs/rich-text-title}\n */\nexport type RichTextField<State extends FieldState = FieldState> = State extends \"empty\"\n\t? []\n\t: [RTNode, ...RTNode[]]\n"],"mappings":";;;;;;AASA,MAAa,mBAAmB;CAC/B,UAAU;CACV,UAAU;CACV,UAAU;CACV,UAAU;CACV,UAAU;CACV,UAAU;CACV,WAAW;CACX,cAAc;CACd,QAAQ;CACR,IAAI;CACJ,UAAU;CACV,WAAW;CACX,MAAM;CACN,OAAO;CACP,OAAO;CACP,OAAO;CACP,WAAW;CACX,OAAO;CACP,MAAM;AACP"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/client",
3
- "version": "7.23.0-pr.473.7aca245",
3
+ "version": "7.23.0-pr.480.965f57f",
4
4
  "description": "The official JavaScript + TypeScript client library for Prismic",
5
5
  "keywords": [
6
6
  "client",
@@ -71,12 +71,12 @@
71
71
  "@prismicio/e2e-tests-utils": "^1.20.0",
72
72
  "@prismicio/types-internal": "^3.17.2",
73
73
  "@types/node": "^26.6.5",
74
- "@vitest/coverage-v8": "^5.0.3",
75
- "oxfmt": "^0.72.0",
76
- "oxlint": "^1.87.0",
74
+ "@vitest/coverage-v8": "^5.0.5",
75
+ "oxfmt": "^0.73.0",
76
+ "oxlint": "^1.88.0",
77
77
  "tsdown": "^0.23.1",
78
78
  "typescript": "^7.0.2",
79
- "vitest": "^5.0.3"
79
+ "vitest": "^5.0.5"
80
80
  },
81
81
  "engines": {
82
82
  "node": ">=22"
package/src/cookie.ts CHANGED
@@ -1,2 +1,5 @@
1
1
  /** The well-known name of the cookie used to store a Prismic preview session's ref. */
2
2
  export const preview = "io.prismic.preview"
3
+
4
+ /** The well-known name of the cookie used to store a Prismic preview session's ID. */
5
+ export const previewSession = "io.prismic.previewSession"
@@ -30,13 +30,27 @@ import { isRepositoryName } from "./isRepositoryName"
30
30
  *
31
31
  * @param repositoryName - The name of the Prismic repository. For example, `"my-repo"` if the
32
32
  * repository URL is `my-repo.prismic.io`.
33
+ * @param config - Options that configure the toolbar URL.
33
34
  * @returns The URL for the given Prismic repository's Prismic Toolbar script.
34
35
  */
35
- export const getToolbarSrc = <TRepositoryName extends string>(
36
- repositoryName: TRepositoryName,
37
- ): `https://static.cdn.prismic.io/prismic.js?new=true&repo=${TRepositoryName}` => {
36
+ export const getToolbarSrc = (
37
+ repositoryName: string,
38
+ config?: {
39
+ /** The version of the Prismic Toolbar to load. Defaults to 4. */
40
+ version?: 4 | 5
41
+ /**
42
+ * The URL the toolbar script is loaded from, without a trailing slash. For example, a toolbar
43
+ * preview build. Defaults to `https://static.cdn.prismic.io`.
44
+ */
45
+ host?: string
46
+ },
47
+ ): string => {
38
48
  if (isRepositoryName(repositoryName)) {
39
- return `https://static.cdn.prismic.io/prismic.js?new=true&repo=${repositoryName}` as const
49
+ const url = new URL(`${config?.host ?? "https://static.cdn.prismic.io"}/prismic.js`)
50
+ url.searchParams.set("repo", repositoryName)
51
+ if (config?.version) url.searchParams.set("v", config.version.toString())
52
+
53
+ return url.toString()
40
54
  } else {
41
55
  throw new PrismicError(
42
56
  `An invalid Prismic repository name was given: ${repositoryName}`,
@@ -6,14 +6,14 @@ import type {
6
6
  RTNode,
7
7
  RTOListItemNode,
8
8
  RTTextNode,
9
- } from "../types/value/richText";
10
- import { RichTextNodeType } from "../types/value/richText";
11
- import type { Tree, TreeNode } from "./types";
9
+ } from "../types/value/richText"
10
+ import { RichTextNodeType } from "../types/value/richText"
11
+ import type { Tree, TreeNode } from "./types"
12
12
 
13
13
  const uuid = (): string => {
14
- return (++uuid.i).toString();
15
- };
16
- uuid.i = 0;
14
+ return (++uuid.i).toString()
15
+ }
16
+ uuid.i = 0
17
17
 
18
18
  /**
19
19
  * Parses a rich text or title field into a tree
@@ -25,157 +25,84 @@ uuid.i = 0;
25
25
  * @returns Tree from given rich text or title field
26
26
  */
27
27
  export const asTree = (nodes: RTNode[]): Tree => {
28
- if (
29
- nodes.some(
30
- (node) =>
31
- (node.type === RichTextNodeType.listItem ||
32
- node.type === RichTextNodeType.oListItem) &&
33
- (node.depth ?? 0) > 0,
34
- )
35
- ) {
36
- return nestedListsToTree(nodes);
37
- }
38
- const preparedNodes = prepareNodes(nodes);
28
+ const preparedNodes = prepareNodes(nodes)
39
29
 
40
- const children: TreeNode[] = [];
30
+ const children: TreeNode[] = []
41
31
  for (let i = 0; i < preparedNodes.length; i++) {
42
- children.push(nodeToTreeNode(preparedNodes[i]));
32
+ children.push(nodeToTreeNode(preparedNodes[i]))
43
33
  }
44
34
 
45
35
  return {
46
36
  key: uuid(),
47
37
  children,
48
- };
49
- };
50
-
51
- const nestedListsToTree = (nodes: RTNode[]): Tree => {
52
- const children: TreeNode[] = [];
53
- const levels: { list: TreeNode; lastItem?: TreeNode }[] = [];
54
- for (const node of nodes) {
55
- if (
56
- node.type !== RichTextNodeType.listItem &&
57
- node.type !== RichTextNodeType.oListItem
58
- ) {
59
- levels.length = 0;
60
- children.push(nodeToTreeNode(node));
61
- continue;
62
- }
63
- const requested = node.depth ?? 0;
64
- const depth =
65
- Number.isSafeInteger(requested) && requested >= 0
66
- ? Math.min(requested, levels.length)
67
- : 0;
68
- levels.length = Math.min(levels.length, depth + 1);
69
- const listType =
70
- node.type === RichTextNodeType.listItem
71
- ? RichTextNodeType.list
72
- : RichTextNodeType.oList;
73
- let level = levels[depth];
74
- if (!level || level.list.type !== listType) {
75
- const list = createTreeNode(
76
- listType === RichTextNodeType.list
77
- ? { type: listType, items: [] }
78
- : { type: listType, items: [] },
79
- );
80
- const siblings =
81
- depth === 0 ? children : levels[depth - 1].lastItem!.children;
82
- siblings.push(list);
83
- level = { list };
84
- levels[depth] = level;
85
- }
86
- const item = nodeToTreeNode(node);
87
- level.list.children.push(item);
88
- if (
89
- level.list.node.type === RichTextNodeType.list &&
90
- node.type === RichTextNodeType.listItem
91
- )
92
- level.list.node.items.push(node);
93
- if (
94
- level.list.node.type === RichTextNodeType.oList &&
95
- node.type === RichTextNodeType.oListItem
96
- )
97
- level.list.node.items.push(node);
98
- level.lastItem = item;
99
38
  }
100
- return { key: uuid(), children };
101
- };
39
+ }
102
40
 
103
- const createTreeNode = (
104
- node: RTAnyNode,
105
- children: TreeNode[] = [],
106
- ): TreeNode => {
41
+ const createTreeNode = (node: RTAnyNode, children: TreeNode[] = []): TreeNode => {
107
42
  return {
108
43
  key: uuid(),
109
44
  type: node.type,
110
45
  text: "text" in node ? node.text : undefined,
111
46
  node,
112
47
  children,
113
- };
114
- };
48
+ }
49
+ }
115
50
 
116
51
  const createTextTreeNode = (text: string): TreeNode => {
117
52
  return createTreeNode({
118
53
  type: RichTextNodeType.span,
119
54
  text,
120
55
  spans: [],
121
- });
122
- };
56
+ })
57
+ }
123
58
 
124
59
  const prepareNodes = (nodes: RTNode[]): RTBlockNode[] => {
125
- const mutNodes: RTBlockNode[] = nodes.slice(0);
60
+ const mutNodes: RTBlockNode[] = nodes.slice(0)
126
61
 
127
62
  for (let i = 0; i < mutNodes.length; i++) {
128
- const node = mutNodes[i];
63
+ const node = mutNodes[i]
129
64
 
130
- if (
131
- node.type === RichTextNodeType.listItem ||
132
- node.type === RichTextNodeType.oListItem
133
- ) {
134
- const items: (RTListItemNode | RTOListItemNode)[] = [
135
- node as RTListItemNode | RTOListItemNode,
136
- ];
65
+ if (node.type === RichTextNodeType.listItem || node.type === RichTextNodeType.oListItem) {
66
+ const items: (RTListItemNode | RTOListItemNode)[] = [node as RTListItemNode | RTOListItemNode]
137
67
 
138
68
  while (mutNodes[i + 1] && mutNodes[i + 1].type === node.type) {
139
- items.push(mutNodes[i + 1] as RTListItemNode | RTOListItemNode);
140
- mutNodes.splice(i, 1);
69
+ items.push(mutNodes[i + 1] as RTListItemNode | RTOListItemNode)
70
+ mutNodes.splice(i, 1)
141
71
  }
142
72
 
143
73
  if (node.type === RichTextNodeType.listItem) {
144
74
  mutNodes[i] = {
145
75
  type: RichTextNodeType.list,
146
76
  items: items as RTListItemNode[],
147
- };
77
+ }
148
78
  } else {
149
79
  mutNodes[i] = {
150
80
  type: RichTextNodeType.oList,
151
81
  items: items as RTOListItemNode[],
152
- };
82
+ }
153
83
  }
154
84
  }
155
85
  }
156
86
 
157
- return mutNodes;
158
- };
87
+ return mutNodes
88
+ }
159
89
 
160
90
  const nodeToTreeNode = (node: RTBlockNode): TreeNode => {
161
91
  if ("text" in node) {
162
- return createTreeNode(
163
- node,
164
- textNodeSpansToTreeNodeChildren(node.spans, node),
165
- );
92
+ return createTreeNode(node, textNodeSpansToTreeNodeChildren(node.spans, node))
166
93
  }
167
94
 
168
95
  if ("items" in node) {
169
- const children: TreeNode[] = [];
96
+ const children: TreeNode[] = []
170
97
  for (let i = 0; i < node.items.length; i++) {
171
- children.push(nodeToTreeNode(node.items[i]));
98
+ children.push(nodeToTreeNode(node.items[i]))
172
99
  }
173
100
 
174
- return createTreeNode(node, children);
101
+ return createTreeNode(node, children)
175
102
  }
176
103
 
177
- return createTreeNode(node);
178
- };
104
+ return createTreeNode(node)
105
+ }
179
106
 
180
107
  const textNodeSpansToTreeNodeChildren = (
181
108
  spans: RTInlineNode[],
@@ -183,10 +110,10 @@ const textNodeSpansToTreeNodeChildren = (
183
110
  parentSpan?: RTInlineNode,
184
111
  ): TreeNode[] => {
185
112
  if (!spans.length) {
186
- return [createTextTreeNode(node.text)];
113
+ return [createTextTreeNode(node.text)]
187
114
  }
188
115
 
189
- const mutSpans: RTInlineNode[] = spans.slice(0);
116
+ const mutSpans: RTInlineNode[] = spans.slice(0)
190
117
 
191
118
  // Sort spans using the following criteria:
192
119
  //
@@ -198,47 +125,44 @@ const textNodeSpansToTreeNodeChildren = (
198
125
  //
199
126
  // Sorting using this algorithm ensures proper detection of child
200
127
  // spans.
201
- mutSpans.sort((a, b) => a.start - b.start || b.end - a.end);
128
+ mutSpans.sort((a, b) => a.start - b.start || b.end - a.end)
202
129
 
203
- const children: TreeNode[] = [];
130
+ const children: TreeNode[] = []
204
131
 
205
132
  for (let i = 0; i < mutSpans.length; i++) {
206
- const span = mutSpans[i];
207
- const parentSpanStart = (parentSpan && parentSpan.start) || 0;
208
- const spanStart = span.start - parentSpanStart;
209
- const spanEnd = span.end - parentSpanStart;
210
- const text = node.text.slice(spanStart, spanEnd);
133
+ const span = mutSpans[i]
134
+ const parentSpanStart = (parentSpan && parentSpan.start) || 0
135
+ const spanStart = span.start - parentSpanStart
136
+ const spanEnd = span.end - parentSpanStart
137
+ const text = node.text.slice(spanStart, spanEnd)
211
138
 
212
- const childSpans: RTInlineNode[] = [];
139
+ const childSpans: RTInlineNode[] = []
213
140
  for (let j = i; j < mutSpans.length; j++) {
214
- const siblingSpan = mutSpans[j];
141
+ const siblingSpan = mutSpans[j]
215
142
 
216
143
  if (siblingSpan !== span) {
217
144
  if (siblingSpan.start >= span.start && siblingSpan.end <= span.end) {
218
- childSpans.push(siblingSpan);
219
- mutSpans.splice(j, 1);
220
- j--;
221
- } else if (
222
- siblingSpan.start < span.end &&
223
- siblingSpan.end > span.start
224
- ) {
145
+ childSpans.push(siblingSpan)
146
+ mutSpans.splice(j, 1)
147
+ j--
148
+ } else if (siblingSpan.start < span.end && siblingSpan.end > span.start) {
225
149
  childSpans.push({
226
150
  ...siblingSpan,
227
151
  end: span.end,
228
- });
152
+ })
229
153
  mutSpans[j] = {
230
154
  ...siblingSpan,
231
155
  start: span.end,
232
- };
156
+ }
233
157
  }
234
158
  }
235
159
  }
236
160
 
237
161
  if (i === 0 && spanStart > 0) {
238
- children.push(createTextTreeNode(node.text.slice(0, spanStart)));
162
+ children.push(createTextTreeNode(node.text.slice(0, spanStart)))
239
163
  }
240
164
 
241
- const spanWithText = { ...span, text };
165
+ const spanWithText = { ...span, text }
242
166
  children.push(
243
167
  createTreeNode(
244
168
  spanWithText,
@@ -251,21 +175,19 @@ const textNodeSpansToTreeNodeChildren = (
251
175
  span,
252
176
  ),
253
177
  ),
254
- );
178
+ )
255
179
 
256
180
  if (spanEnd < node.text.length) {
257
181
  children.push(
258
182
  createTextTreeNode(
259
183
  node.text.slice(
260
184
  spanEnd,
261
- mutSpans[i + 1]
262
- ? mutSpans[i + 1].start - parentSpanStart
263
- : undefined,
185
+ mutSpans[i + 1] ? mutSpans[i + 1].start - parentSpanStart : undefined,
264
186
  ),
265
187
  ),
266
- );
188
+ )
267
189
  }
268
190
  }
269
191
 
270
- return children;
271
- };
192
+ return children
193
+ }
@@ -88,15 +88,11 @@ export interface RTPreformattedNode extends RTTextNodeBase {
88
88
  /** Rich text `list-item` node */
89
89
  export interface RTListItemNode extends RTTextNodeBase {
90
90
  type: typeof RichTextNodeType.listItem
91
- /** Indentation level; omitted for a root list item. */
92
- depth?: number
93
91
  }
94
92
 
95
93
  /** Rich text `o-list-item` node for ordered lists */
96
94
  export interface RTOListItemNode extends RTTextNodeBase {
97
95
  type: typeof RichTextNodeType.oListItem
98
- /** Indentation level; omitted for a root list item. */
99
- depth?: number
100
96
  }
101
97
 
102
98
  // Span nodes
@@ -242,5 +238,6 @@ export type RTAnyNode = RTBlockNode | RTInlineNode | RTSpanNode
242
238
  *
243
239
  * @see Rich text field documentation: {@link https://prismic.io/docs/rich-text-title}
244
240
  */
245
- export type RichTextField<State extends FieldState = FieldState> =
246
- State extends "empty" ? [] : [RTNode, ...RTNode[]]
241
+ export type RichTextField<State extends FieldState = FieldState> = State extends "empty"
242
+ ? []
243
+ : [RTNode, ...RTNode[]]