@portabletext/editor 7.10.15 → 7.10.17
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/lib/{_chunks-dts/behavior.types.action.d.ts → behavior.types.action-CYtiRDck.d.ts} +260 -59
- package/lib/behavior.types.action-CYtiRDck.d.ts.map +1 -0
- package/lib/behavior.types.behavior-B_77VtQR.js +159 -0
- package/lib/behavior.types.behavior-B_77VtQR.js.map +1 -0
- package/lib/behaviors/index.d.ts +1 -1
- package/lib/behaviors/index.js +2 -35
- package/lib/get-container-BeXYKpoi.js +222 -0
- package/lib/get-container-BeXYKpoi.js.map +1 -0
- package/lib/get-parent-51Kzgaf9.js +237 -0
- package/lib/get-parent-51Kzgaf9.js.map +1 -0
- package/lib/get-path-sub-schema--2I4NJbG.js +513 -0
- package/lib/get-path-sub-schema--2I4NJbG.js.map +1 -0
- package/lib/index.d.ts +2 -67
- package/lib/index.js +16743 -18963
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.ts +1 -2
- package/lib/plugins/index.d.ts.map +1 -1
- package/lib/plugins/index.js +103 -41
- package/lib/plugins/index.js.map +1 -1
- package/lib/selector.is-at-the-start-of-block-gJIMWRpU.js +822 -0
- package/lib/selector.is-at-the-start-of-block-gJIMWRpU.js.map +1 -0
- package/lib/selectors/index.d.ts +1 -3
- package/lib/selectors/index.d.ts.map +1 -1
- package/lib/selectors/index.js +256 -215
- package/lib/selectors/index.js.map +1 -1
- package/lib/traversal/index.d.ts +1 -1
- package/lib/traversal/index.d.ts.map +1 -1
- package/lib/traversal/index.js +33 -52
- package/lib/traversal/index.js.map +1 -1
- package/lib/use-editor-CwNeVwVC.js +47 -0
- package/lib/use-editor-CwNeVwVC.js.map +1 -0
- package/lib/util.is-equal-selections-BF4WJtz5.js +25 -0
- package/lib/util.is-equal-selections-BF4WJtz5.js.map +1 -0
- package/lib/util.slice-blocks-DQnr9X2s.js +633 -0
- package/lib/util.slice-blocks-DQnr9X2s.js.map +1 -0
- package/lib/utils/index.d.ts +11 -39
- package/lib/utils/index.d.ts.map +1 -1
- package/lib/utils/index.js +87 -123
- package/lib/utils/index.js.map +1 -1
- package/package.json +18 -15
- package/lib/_chunks-dts/behavior.types.action.d.ts.map +0 -1
- package/lib/_chunks-dts/block-offset.d.ts +0 -10
- package/lib/_chunks-dts/block-offset.d.ts.map +0 -1
- package/lib/_chunks-dts/editor-selector.d.ts +0 -33
- package/lib/_chunks-dts/editor-selector.d.ts.map +0 -1
- package/lib/_chunks-dts/editor.d.ts +0 -99
- package/lib/_chunks-dts/editor.d.ts.map +0 -1
- package/lib/_chunks-es/get-container.js +0 -187
- package/lib/_chunks-es/get-container.js.map +0 -1
- package/lib/_chunks-es/get-parent.js +0 -195
- package/lib/_chunks-es/get-parent.js.map +0 -1
- package/lib/_chunks-es/get-path-sub-schema.js +0 -399
- package/lib/_chunks-es/get-path-sub-schema.js.map +0 -1
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js +0 -947
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +0 -1
- package/lib/_chunks-es/use-editor.js +0 -20
- package/lib/_chunks-es/use-editor.js.map +0 -1
- package/lib/_chunks-es/util.is-equal-selections.js +0 -20
- package/lib/_chunks-es/util.is-equal-selections.js.map +0 -1
- package/lib/_chunks-es/util.slice-blocks.js +0 -720
- package/lib/_chunks-es/util.slice-blocks.js.map +0 -1
- package/lib/behaviors/index.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/traversal/get-ancestor.ts","../../src/traversal/get-ancestors.ts","../../src/traversal/get-annotation.ts","../../src/traversal/is-block.ts","../../src/traversal/get-children.ts","../../src/traversal/get-container.ts","../../src/traversal/get-container-children.ts","../../src/traversal/get-enclosing-block.ts","../../src/traversal/get-first-child.ts","../../src/traversal/get-last-child.ts","../../src/traversal/get-leaf.ts","../../src/traversal/get-node.ts","../../src/traversal/get-parent.ts","../../src/traversal/get-path-sub-schema.ts","../../src/traversal/get-sibling.ts","../../src/traversal/compare-points.ts","../../src/traversal/path-contains.ts","../../src/traversal/range-intersects.ts","../../src/traversal/get-span.ts","../../src/traversal/get-text.ts","../../src/traversal/get-text-block.ts","../../src/traversal/get-union-schema.ts","../../src/traversal/has-node.ts","../../src/traversal/is-inline.ts","../../src/traversal/is-leaf-object.ts","../../src/traversal/is-object.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/traversal/get-ancestor.ts","../../src/traversal/get-ancestors.ts","../../src/traversal/get-annotation.ts","../../src/traversal/is-block.ts","../../src/traversal/get-children.ts","../../src/traversal/get-container.ts","../../src/traversal/get-container-children.ts","../../src/traversal/get-enclosing-block.ts","../../src/traversal/get-first-child.ts","../../src/traversal/get-last-child.ts","../../src/traversal/get-leaf.ts","../../src/traversal/get-node.ts","../../src/traversal/get-parent.ts","../../src/traversal/get-path-sub-schema.ts","../../src/traversal/get-sibling.ts","../../src/traversal/compare-points.ts","../../src/traversal/path-contains.ts","../../src/traversal/range-intersects.ts","../../src/traversal/get-span.ts","../../src/traversal/get-text.ts","../../src/traversal/get-text-block.ts","../../src/traversal/get-union-schema.ts","../../src/traversal/has-node.ts","../../src/traversal/is-inline.ts","../../src/traversal/is-leaf-object.ts","../../src/traversal/is-object.ts"],"mappings":"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"}
|
package/lib/traversal/index.js
CHANGED
|
@@ -1,54 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { i as getChildren, o as getContainerChildren, r as getNode, t as getParent, u as isKeyedSegment } from "../get-parent-51Kzgaf9.js";
|
|
2
|
+
import { C as getAncestors, S as hasNode, a as isInline, i as getEnclosingBlock, l as getSibling, o as getBlock, r as comparePoints, s as isBlock, t as getPathSubSchema, y as isObject } from "../get-path-sub-schema--2I4NJbG.js";
|
|
3
|
+
import { _ as getAncestor, a as getTextBlock, c as pathContains, g as isLeafObject, h as getLeaf, i as getFirstChild, l as getSpan, n as getUnionSchema, o as rangeIntersects, r as getLastChild, t as getContainer, u as getText } from "../get-container-BeXYKpoi.js";
|
|
4
|
+
/**
|
|
5
|
+
* Get the annotation at a given path.
|
|
6
|
+
*
|
|
7
|
+
* Annotations live in `markDefs` on a text block, alongside `children`
|
|
8
|
+
* rather than inside it, so they aren't reachable through `getNode`.
|
|
9
|
+
* `getAnnotation` resolves a path of the shape
|
|
10
|
+
* `[..., {_key: block}, 'markDefs', {_key: annotation}, ...]` to the
|
|
11
|
+
* annotation node on the enclosing text block.
|
|
12
|
+
*
|
|
13
|
+
* @beta
|
|
14
|
+
*/
|
|
6
15
|
function getAnnotation(snapshot, path) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
16
|
+
for (let i = 0; i < path.length - 1; i++) {
|
|
17
|
+
if (path[i] !== "markDefs") continue;
|
|
18
|
+
let annotationSegment = path[i + 1];
|
|
19
|
+
if (!isKeyedSegment(annotationSegment)) continue;
|
|
20
|
+
let block = getTextBlock(snapshot, path.slice(0, i));
|
|
21
|
+
if (!block) continue;
|
|
22
|
+
let annotation = block.node.markDefs?.find((markDef) => markDef._key === annotationSegment._key);
|
|
23
|
+
return annotation ? {
|
|
24
|
+
node: annotation,
|
|
25
|
+
path: [
|
|
26
|
+
...block.path,
|
|
27
|
+
"markDefs",
|
|
28
|
+
{ _key: annotation._key }
|
|
29
|
+
]
|
|
30
|
+
} : void 0;
|
|
31
|
+
}
|
|
24
32
|
}
|
|
25
|
-
export {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
getAncestors,
|
|
29
|
-
getAnnotation,
|
|
30
|
-
getBlock,
|
|
31
|
-
getChildren,
|
|
32
|
-
getContainer,
|
|
33
|
-
getContainerChildren,
|
|
34
|
-
getEnclosingBlock,
|
|
35
|
-
getFirstChild,
|
|
36
|
-
getLastChild,
|
|
37
|
-
getLeaf,
|
|
38
|
-
getNode,
|
|
39
|
-
getParent,
|
|
40
|
-
getPathSubSchema,
|
|
41
|
-
getSibling,
|
|
42
|
-
getSpan,
|
|
43
|
-
getText,
|
|
44
|
-
getTextBlock,
|
|
45
|
-
getUnionSchema,
|
|
46
|
-
hasNode,
|
|
47
|
-
isBlock,
|
|
48
|
-
isInline,
|
|
49
|
-
isLeafObject,
|
|
50
|
-
isObject,
|
|
51
|
-
pathContains,
|
|
52
|
-
rangeIntersects
|
|
53
|
-
};
|
|
54
|
-
//# sourceMappingURL=index.js.map
|
|
33
|
+
export { comparePoints, getAncestor, getAncestors, getAnnotation, getBlock, getChildren, getContainer, getContainerChildren, getEnclosingBlock, getFirstChild, getLastChild, getLeaf, getNode, getParent, getPathSubSchema, getSibling, getSpan, getText, getTextBlock, getUnionSchema, hasNode, isBlock, isInline, isLeafObject, isObject, pathContains, rangeIntersects };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/traversal/get-annotation.ts"],"sourcesContent":["import type {PortableTextObject} from '@portabletext/schema'\nimport type {Path} from '../engine/interfaces/path'\nimport {isKeyedSegment} from '../utils/util.is-keyed-segment'\nimport {getTextBlock} from './get-text-block'\nimport type {TraversalSnapshot} from './traversal-snapshot'\n\n/**\n * Get the annotation at a given path.\n *\n * Annotations live in `markDefs` on a text block, alongside `children`\n * rather than inside it, so they aren't reachable through `getNode`.\n * `getAnnotation` resolves a path of the shape\n * `[..., {_key: block}, 'markDefs', {_key: annotation}, ...]` to the\n * annotation node on the enclosing text block.\n *\n * @beta\n */\nexport function getAnnotation(\n snapshot: TraversalSnapshot,\n path: Path,\n): {node: PortableTextObject; path: Path} | undefined {\n // A path may cross multiple `'markDefs'` segments if a consumer\n // registers a container whose array field is named `markDefs`. Try\n // each position and pick the one whose prefix resolves to a text\n // block.\n for (let i = 0; i < path.length - 1; i++) {\n if (path[i] !== 'markDefs') {\n continue\n }\n\n const annotationSegment = path[i + 1]\n\n if (!isKeyedSegment(annotationSegment)) {\n continue\n }\n\n const block = getTextBlock(snapshot, path.slice(0, i))\n\n if (!block) {\n continue\n }\n\n const annotation = block.node.markDefs?.find(\n (markDef) => markDef._key === annotationSegment._key,\n )\n\n if (!annotation) {\n return undefined\n }\n\n return {\n node: annotation,\n path: [...block.path, 'markDefs', {_key: annotation._key}],\n }\n }\n\n return undefined\n}\n"],"
|
|
1
|
+
{"version":3,"file":"index.js","names":["PortableTextObject","Path","isKeyedSegment","getTextBlock","TraversalSnapshot","getAnnotation","snapshot","path","node","i","length","annotationSegment","block","slice","annotation","markDefs","find","markDef","_key","undefined"],"sources":["../../src/traversal/get-annotation.ts"],"sourcesContent":["import type {PortableTextObject} from '@portabletext/schema'\nimport type {Path} from '../engine/interfaces/path'\nimport {isKeyedSegment} from '../utils/util.is-keyed-segment'\nimport {getTextBlock} from './get-text-block'\nimport type {TraversalSnapshot} from './traversal-snapshot'\n\n/**\n * Get the annotation at a given path.\n *\n * Annotations live in `markDefs` on a text block, alongside `children`\n * rather than inside it, so they aren't reachable through `getNode`.\n * `getAnnotation` resolves a path of the shape\n * `[..., {_key: block}, 'markDefs', {_key: annotation}, ...]` to the\n * annotation node on the enclosing text block.\n *\n * @beta\n */\nexport function getAnnotation(\n snapshot: TraversalSnapshot,\n path: Path,\n): {node: PortableTextObject; path: Path} | undefined {\n // A path may cross multiple `'markDefs'` segments if a consumer\n // registers a container whose array field is named `markDefs`. Try\n // each position and pick the one whose prefix resolves to a text\n // block.\n for (let i = 0; i < path.length - 1; i++) {\n if (path[i] !== 'markDefs') {\n continue\n }\n\n const annotationSegment = path[i + 1]\n\n if (!isKeyedSegment(annotationSegment)) {\n continue\n }\n\n const block = getTextBlock(snapshot, path.slice(0, i))\n\n if (!block) {\n continue\n }\n\n const annotation = block.node.markDefs?.find(\n (markDef) => markDef._key === annotationSegment._key,\n )\n\n if (!annotation) {\n return undefined\n }\n\n return {\n node: annotation,\n path: [...block.path, 'markDefs', {_key: annotation._key}],\n }\n }\n\n return undefined\n}\n"],"mappings":";;;;;;;;;;;;;;AAiBA,SAAgBK,cACdC,UACAC,MACoD;CAKpD,KAAK,IAAIE,IAAI,GAAGA,IAAIF,KAAKG,SAAS,GAAGD,KAAK;EACxC,IAAIF,KAAKE,OAAO,YACd;EAGF,IAAME,oBAAoBJ,KAAKE,IAAI;EAEnC,IAAI,CAACP,eAAeS,iBAAiB,GACnC;EAGF,IAAMC,QAAQT,aAAaG,UAAUC,KAAKM,MAAM,GAAGJ,CAAC,CAAC;EAErD,IAAI,CAACG,OACH;EAGF,IAAME,aAAaF,MAAMJ,KAAKO,UAAUC,MACrCC,YAAYA,QAAQC,SAASP,kBAAkBO,IAClD;EAMA,OAJKJ,aAIE;GACLN,MAAMM;GACNP,MAAM;IAAC,GAAGK,MAAML;IAAM;IAAY,EAACW,MAAMJ,WAAWI,KAAI;GAAC;EAC3D,IANE;CAOJ;AAGF"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import React, { createContext } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* As `@portabletext/editor` is declared as a dependency, and may be
|
|
4
|
+
* duplicated, sometimes across major versions it's critical that vital
|
|
5
|
+
* React Contexts are shared even when there is a duplicate.
|
|
6
|
+
*
|
|
7
|
+
* We have to support a Sanity Plugin being able to call hooks like
|
|
8
|
+
* `useEditor`, and then read the context setup by `sanity`, which calls
|
|
9
|
+
* `EditorProvider`, even if the provider and hook are different instances in
|
|
10
|
+
* memory.
|
|
11
|
+
*
|
|
12
|
+
* For this reason it's vital that all changes to globally scoped providers
|
|
13
|
+
* remain fully backwards compatible.
|
|
14
|
+
*/
|
|
15
|
+
function createGloballyScopedContext(key, defaultValue) {
|
|
16
|
+
let symbol = Symbol.for(key);
|
|
17
|
+
/**
|
|
18
|
+
* Prevent errors about re-renders on React SSR on Next.js App Router
|
|
19
|
+
*/
|
|
20
|
+
if (typeof document > "u") return createContext(defaultValue);
|
|
21
|
+
let scope = globalThis;
|
|
22
|
+
return scope[symbol] = scope[symbol] ?? createContext(defaultValue), scope[symbol];
|
|
23
|
+
}
|
|
24
|
+
const EditorContext = createGloballyScopedContext("@portabletext/editor/context/editor", null);
|
|
25
|
+
/**
|
|
26
|
+
* @public
|
|
27
|
+
* Get the current editor context from the `EditorProvider`.
|
|
28
|
+
* Must be used inside the `EditorProvider` component.
|
|
29
|
+
* @returns The current editor object.
|
|
30
|
+
* @example
|
|
31
|
+
* ```tsx
|
|
32
|
+
* import { useEditor } from '@portabletext/editor'
|
|
33
|
+
*
|
|
34
|
+
* function MyComponent() {
|
|
35
|
+
* const editor = useEditor()
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
* @group Hooks
|
|
39
|
+
*/
|
|
40
|
+
function useEditor() {
|
|
41
|
+
let editor = React.useContext(EditorContext);
|
|
42
|
+
if (!editor) throw Error("No Editor set. Use EditorProvider to set one.");
|
|
43
|
+
return editor;
|
|
44
|
+
}
|
|
45
|
+
export { EditorContext as n, useEditor as t };
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=use-editor-CwNeVwVC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-editor-CwNeVwVC.js","names":["createContext","Context","createGloballyScopedContext","ContextType","key","defaultValue","T","symbol","Symbol","for","document","scope","globalThis","Editor","createGloballyScopedContext","EditorContext","React","EditorContext","useEditor","editor","useContext","Error"],"sources":["../src/internal-utils/globally-scoped-context.ts","../src/editor/editor-context.tsx","../src/editor/use-editor.ts"],"sourcesContent":["import {createContext, type Context} from 'react'\n\n/**\n * As `@portabletext/editor` is declared as a dependency, and may be\n * duplicated, sometimes across major versions it's critical that vital\n * React Contexts are shared even when there is a duplicate.\n *\n * We have to support a Sanity Plugin being able to call hooks like\n * `useEditor`, and then read the context setup by `sanity`, which calls\n * `EditorProvider`, even if the provider and hook are different instances in\n * memory.\n *\n * For this reason it's vital that all changes to globally scoped providers\n * remain fully backwards compatible.\n */\nexport function createGloballyScopedContext<\n ContextType,\n const T extends ContextType = ContextType,\n>(\n /**\n * Enforce that all Symbol.for keys used for globally scoped contexts have a predictable prefix\n */\n key: `@portabletext/editor/context/${string}`,\n defaultValue: T,\n): Context<ContextType> {\n const symbol = Symbol.for(key)\n\n /**\n * Prevent errors about re-renders on React SSR on Next.js App Router\n */\n if (typeof document === 'undefined') {\n return createContext<ContextType>(defaultValue)\n }\n\n const scope = globalThis as any\n scope[symbol] = scope[symbol] ?? createContext<T>(defaultValue)\n\n return scope[symbol]\n}\n","import type {Editor} from '../editor'\nimport {createGloballyScopedContext} from '../internal-utils/globally-scoped-context'\n\nexport const EditorContext = createGloballyScopedContext<Editor | null>(\n '@portabletext/editor/context/editor',\n null,\n)\n","import React from 'react'\nimport {EditorContext} from './editor-context'\n\n/**\n * @public\n * Get the current editor context from the `EditorProvider`.\n * Must be used inside the `EditorProvider` component.\n * @returns The current editor object.\n * @example\n * ```tsx\n * import { useEditor } from '@portabletext/editor'\n *\n * function MyComponent() {\n * const editor = useEditor()\n * }\n * ```\n * @group Hooks\n */\nexport function useEditor() {\n const editor = React.useContext(EditorContext)\n\n if (!editor) {\n throw new Error('No Editor set. Use EditorProvider to set one.')\n }\n\n return editor\n}\n"],"mappings":";;;;;;;;;;;;;;AAeA,SAAgBE,4BAOdE,KACAC,cACsB;CACtB,IAAME,SAASC,OAAOC,IAAIL,GAAG;;;;CAK7B,IAAI,OAAOM,WAAa,KACtB,OAAOV,cAA2BK,YAAY;CAGhD,IAAMM,QAAQC;CAGd,OAFAD,MAAMJ,UAAUI,MAAMJ,WAAWP,cAAiBK,YAAY,GAEvDM,MAAMJ;AACf;ACnCA,MAAaQ,gBAAgBD,4BAC3B,uCACA,IACF;;;;;;;;;;;;;;;;ACYA,SAAOI,YAAA;CACL,IAAAC,SAAeH,MAAKI,WAAYH,aAAa;CAE7C,IAAI,CAACE,QACH,MAAUE,MAAM,+CAA+C;CAChE,OAEMF;AAAM"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { g as isEqualSelectionPoints } from "./util.slice-blocks-DQnr9X2s.js";
|
|
2
|
+
import { isSpan, isTextBlock } from "@portabletext/schema";
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
function getTextBlockText(block) {
|
|
7
|
+
return block.children.map((child) => child.text ?? "").join("");
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
function isEmptyTextBlock(context, block) {
|
|
13
|
+
if (!isTextBlock(context, block)) return !1;
|
|
14
|
+
let onlyText = block.children.every((child) => isSpan(context, child)), blockText = getTextBlockText(block);
|
|
15
|
+
return onlyText && blockText === "";
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
function isEqualSelections(a, b) {
|
|
21
|
+
return !a && !b ? !0 : !a || !b ? !1 : isEqualSelectionPoints(a.anchor, b.anchor) && isEqualSelectionPoints(a.focus, b.focus);
|
|
22
|
+
}
|
|
23
|
+
export { isEmptyTextBlock as n, getTextBlockText as r, isEqualSelections as t };
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=util.is-equal-selections-BF4WJtz5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.is-equal-selections-BF4WJtz5.js","names":["PortableTextTextBlock","getTextBlockText","block","children","map","child","text","join","isSpan","isTextBlock","PortableTextBlock","EditorContext","getTextBlockText","isEmptyTextBlock","context","Pick","block","onlyText","children","every","child","blockText","EditorSelection","isEqualSelectionPoints","isEqualSelections","a","b","anchor","focus"],"sources":["../src/utils/util.get-text-block-text.ts","../src/utils/util.is-empty-text-block.ts","../src/utils/util.is-equal-selections.ts"],"sourcesContent":["import type {PortableTextTextBlock} from '@portabletext/schema'\n\n/**\n * @public\n */\nexport function getTextBlockText(block: PortableTextTextBlock) {\n return block.children.map((child) => child.text ?? '').join('')\n}\n","import {isSpan, isTextBlock, type PortableTextBlock} from '@portabletext/schema'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {getTextBlockText} from './util.get-text-block-text'\n\n/**\n * @public\n */\nexport function isEmptyTextBlock(\n context: Pick<EditorContext, 'schema'>,\n block: PortableTextBlock | unknown,\n) {\n if (!isTextBlock(context, block)) {\n return false\n }\n\n const onlyText = block.children.every((child) => isSpan(context, child))\n const blockText = getTextBlockText(block)\n\n return onlyText && blockText === ''\n}\n","import type {EditorSelection} from '../types/editor'\nimport {isEqualSelectionPoints} from './util.is-equal-selection-points'\n\n/**\n * @public\n */\nexport function isEqualSelections(a: EditorSelection, b: EditorSelection) {\n if (!a && !b) {\n return true\n }\n\n if (!a || !b) {\n return false\n }\n\n return (\n isEqualSelectionPoints(a.anchor, b.anchor) &&\n isEqualSelectionPoints(a.focus, b.focus)\n )\n}\n"],"mappings":";;;;;AAKA,SAAgBC,iBAAiBC,OAA8B;CAC7D,OAAOA,MAAMC,SAASC,KAAKC,UAAUA,MAAMC,QAAQ,EAAE,CAAC,CAACC,KAAK,EAAE;AAChE;;;;ACAA,SAAgBM,iBACdC,SACAE,OACA;CACA,IAAI,CAACP,YAAYK,SAASE,KAAK,GAC7B,OAAO;CAGT,IAAMC,WAAWD,MAAME,SAASC,OAAOC,UAAUZ,OAAOM,SAASM,KAAK,CAAC,GACjEC,YAAYT,iBAAiBI,KAAK;CAExC,OAAOC,YAAYI,cAAc;AACnC;;;;ACbA,SAAgBG,kBAAkBC,GAAoBC,GAAoB;CASxE,OARI,CAACD,KAAK,CAACC,IACF,KAGL,CAACD,KAAK,CAACC,IACF,KAIPH,uBAAuBE,EAAEE,QAAQD,EAAEC,MAAM,KACzCJ,uBAAuBE,EAAEG,OAAOF,EAAEE,KAAK;AAE3C"}
|