@portabletext/editor 1.48.15 → 1.49.1
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-cjs/editor-provider.cjs +32 -17
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-cjs/util.slice-blocks.cjs +2 -0
- package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
- package/lib/_chunks-es/editor-provider.js +32 -17
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/util.slice-blocks.js +2 -0
- package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
- package/lib/index.cjs +360 -294
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +367 -301
- package/lib/index.js.map +1 -1
- package/package.json +7 -7
- package/src/behaviors/behavior.core.block-element.ts +108 -0
- package/src/converters/converter.portable-text.ts +4 -1
- package/src/converters/converter.text-html.ts +4 -1
- package/src/converters/converter.text-plain.ts +4 -1
- package/src/editor/Editable.tsx +21 -52
- package/src/editor/__tests__/PortableTextEditor.test.tsx +6 -0
- package/src/editor/__tests__/RangeDecorations.test.tsx +2 -2
- package/src/editor/components/render-block-object.tsx +89 -0
- package/src/editor/components/render-default-object.tsx +21 -0
- package/src/editor/components/render-element.tsx +140 -0
- package/src/editor/components/render-inline-object.tsx +90 -0
- package/src/editor/components/render-leaf.tsx +64 -0
- package/src/editor/components/render-span.tsx +260 -0
- package/src/editor/components/render-text-block.tsx +147 -0
- package/src/editor/components/render-text.tsx +18 -0
- package/src/editor/components/use-core-block-element-behaviors.ts +39 -0
- package/src/internal-utils/parse-blocks.ts +2 -2
- package/src/internal-utils/slate-utils.ts +1 -1
- package/src/editor/components/DefaultObject.tsx +0 -21
- package/src/editor/components/Element.tsx +0 -461
- package/src/editor/components/Leaf.tsx +0 -329
|
@@ -2197,7 +2197,8 @@ const converterJson = {
|
|
|
2197
2197
|
snapshot,
|
|
2198
2198
|
event
|
|
2199
2199
|
}) => {
|
|
2200
|
-
|
|
2200
|
+
const selection = snapshot.beta.internalDrag?.origin.selection ?? snapshot.context.selection;
|
|
2201
|
+
if (!selection)
|
|
2201
2202
|
return {
|
|
2202
2203
|
type: "serialization.failure",
|
|
2203
2204
|
mimeType: "application/x-portable-text",
|
|
@@ -2205,7 +2206,10 @@ const converterJson = {
|
|
|
2205
2206
|
reason: "No selection"
|
|
2206
2207
|
};
|
|
2207
2208
|
const blocks = util_sliceBlocks.sliceBlocks({
|
|
2208
|
-
context:
|
|
2209
|
+
context: {
|
|
2210
|
+
selection,
|
|
2211
|
+
schema: snapshot.context.schema
|
|
2212
|
+
},
|
|
2209
2213
|
blocks: snapshot.context.value
|
|
2210
2214
|
});
|
|
2211
2215
|
return blocks.length === 0 ? {
|
|
@@ -2263,7 +2267,8 @@ function createConverterTextHtml(legacySchema) {
|
|
|
2263
2267
|
snapshot,
|
|
2264
2268
|
event
|
|
2265
2269
|
}) => {
|
|
2266
|
-
|
|
2270
|
+
const selection = snapshot.beta.internalDrag?.origin.selection ?? snapshot.context.selection;
|
|
2271
|
+
if (!selection)
|
|
2267
2272
|
return {
|
|
2268
2273
|
type: "serialization.failure",
|
|
2269
2274
|
mimeType: "text/html",
|
|
@@ -2271,7 +2276,10 @@ function createConverterTextHtml(legacySchema) {
|
|
|
2271
2276
|
reason: "No selection"
|
|
2272
2277
|
};
|
|
2273
2278
|
const blocks = util_sliceBlocks.sliceBlocks({
|
|
2274
|
-
context:
|
|
2279
|
+
context: {
|
|
2280
|
+
selection,
|
|
2281
|
+
schema: snapshot.context.schema
|
|
2282
|
+
},
|
|
2275
2283
|
blocks: snapshot.context.value
|
|
2276
2284
|
}), html = toHtml.toHTML(blocks, {
|
|
2277
2285
|
onMissingComponent: !1,
|
|
@@ -2328,21 +2336,27 @@ function createConverterTextPlain(legacySchema) {
|
|
|
2328
2336
|
serialize: ({
|
|
2329
2337
|
snapshot,
|
|
2330
2338
|
event
|
|
2331
|
-
}) =>
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2339
|
+
}) => {
|
|
2340
|
+
const selection = snapshot.beta.internalDrag?.origin.selection ?? snapshot.context.selection;
|
|
2341
|
+
return selection ? {
|
|
2342
|
+
type: "serialization.success",
|
|
2343
|
+
data: util_sliceBlocks.sliceBlocks({
|
|
2344
|
+
context: {
|
|
2345
|
+
selection,
|
|
2346
|
+
schema: snapshot.context.schema
|
|
2347
|
+
},
|
|
2348
|
+
blocks: snapshot.context.value
|
|
2349
|
+
}).map((block) => util_sliceBlocks.isTextBlock(snapshot.context, block) ? block.children.map((child) => child._type === snapshot.context.schema.span.name ? child.text : snapshot.beta.hasTag("dragging internally") ? `[${snapshot.context.schema.inlineObjects.find((inlineObjectType) => inlineObjectType.name === child._type)?.title ?? "Object"}]` : "").join("") : snapshot.beta.hasTag("dragging internally") ? `[${snapshot.context.schema.blockObjects.find((blockObjectType) => blockObjectType.name === block._type)?.title ?? "Object"}]` : "").filter((block) => block !== "").join(`
|
|
2337
2350
|
|
|
2338
2351
|
`),
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2352
|
+
mimeType: "text/plain",
|
|
2353
|
+
originEvent: event.originEvent
|
|
2354
|
+
} : {
|
|
2355
|
+
type: "serialization.failure",
|
|
2356
|
+
mimeType: "text/plain",
|
|
2357
|
+
originEvent: event.originEvent,
|
|
2358
|
+
reason: "No selection"
|
|
2359
|
+
};
|
|
2346
2360
|
},
|
|
2347
2361
|
deserialize: ({
|
|
2348
2362
|
snapshot,
|
|
@@ -8718,6 +8732,7 @@ exports.getEditorSnapshot = getEditorSnapshot;
|
|
|
8718
8732
|
exports.getFirstBlock = getFirstBlock;
|
|
8719
8733
|
exports.getLastBlock = getLastBlock;
|
|
8720
8734
|
exports.getNodeBlock = getNodeBlock;
|
|
8735
|
+
exports.getPointBlock = getPointBlock;
|
|
8721
8736
|
exports.isEqualToEmptyEditor = isEqualToEmptyEditor;
|
|
8722
8737
|
exports.isHotkey = isHotkey;
|
|
8723
8738
|
exports.moveRangeByOperation = moveRangeByOperation;
|