@portabletext/editor 3.2.0 → 3.2.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/index.js
CHANGED
|
@@ -19,7 +19,6 @@ import { setup, fromCallback, assign, and, enqueueActions, emit, assertEvent, ra
|
|
|
19
19
|
import { compileSchemaDefinitionToPortableTextMemberSchemaTypes, createPortableTextMemberSchemaTypes, portableTextMemberSchemaTypesToSchema } from "@portabletext/sanity-bridge";
|
|
20
20
|
import { htmlToBlocks } from "@portabletext/block-tools";
|
|
21
21
|
import { toHTML } from "@portabletext/to-html";
|
|
22
|
-
import { markdownToPortableText, portableTextToMarkdown } from "@portabletext/markdown";
|
|
23
22
|
import { Schema } from "@sanity/schema";
|
|
24
23
|
import flatten from "lodash/flatten.js";
|
|
25
24
|
import { set, applyAll, unset, insert, setIfMissing, diffMatchPatch as diffMatchPatch$1 } from "@portabletext/patches";
|
|
@@ -2735,57 +2734,6 @@ function createConverterTextHtml(legacySchema) {
|
|
|
2735
2734
|
}
|
|
2736
2735
|
};
|
|
2737
2736
|
}
|
|
2738
|
-
const converterTextMarkdown = {
|
|
2739
|
-
mimeType: "text/markdown",
|
|
2740
|
-
serialize: ({
|
|
2741
|
-
snapshot,
|
|
2742
|
-
event
|
|
2743
|
-
}) => {
|
|
2744
|
-
if (!snapshot.context.selection)
|
|
2745
|
-
return {
|
|
2746
|
-
type: "serialization.failure",
|
|
2747
|
-
mimeType: "text/markdown",
|
|
2748
|
-
reason: "No selection",
|
|
2749
|
-
originEvent: event.originEvent
|
|
2750
|
-
};
|
|
2751
|
-
const blocks = getSelectedValue(snapshot);
|
|
2752
|
-
return {
|
|
2753
|
-
type: "serialization.success",
|
|
2754
|
-
data: portableTextToMarkdown(blocks),
|
|
2755
|
-
mimeType: "text/markdown",
|
|
2756
|
-
originEvent: event.originEvent
|
|
2757
|
-
};
|
|
2758
|
-
},
|
|
2759
|
-
deserialize: ({
|
|
2760
|
-
snapshot,
|
|
2761
|
-
event
|
|
2762
|
-
}) => {
|
|
2763
|
-
const parsedBlocks = markdownToPortableText(event.data, {
|
|
2764
|
-
keyGenerator: snapshot.context.keyGenerator,
|
|
2765
|
-
schema: snapshot.context.schema
|
|
2766
|
-
}).flatMap((block) => {
|
|
2767
|
-
const parsedBlock = parseBlock({
|
|
2768
|
-
context: snapshot.context,
|
|
2769
|
-
block,
|
|
2770
|
-
options: {
|
|
2771
|
-
normalize: !1,
|
|
2772
|
-
removeUnusedMarkDefs: !0,
|
|
2773
|
-
validateFields: !1
|
|
2774
|
-
}
|
|
2775
|
-
});
|
|
2776
|
-
return parsedBlock ? [parsedBlock] : [];
|
|
2777
|
-
});
|
|
2778
|
-
return parsedBlocks.length === 0 ? {
|
|
2779
|
-
type: "deserialization.failure",
|
|
2780
|
-
mimeType: "text/markdown",
|
|
2781
|
-
reason: "No blocks deserialized"
|
|
2782
|
-
} : {
|
|
2783
|
-
type: "deserialization.success",
|
|
2784
|
-
data: parsedBlocks,
|
|
2785
|
-
mimeType: "text/markdown"
|
|
2786
|
-
};
|
|
2787
|
-
}
|
|
2788
|
-
};
|
|
2789
2737
|
function createConverterTextPlain(legacySchema) {
|
|
2790
2738
|
return {
|
|
2791
2739
|
mimeType: "text/plain",
|
|
@@ -2849,7 +2797,7 @@ function escapeHtml(str) {
|
|
|
2849
2797
|
return String(str).replace(/[&<>"'`=/]/g, (s) => entityMap[s]);
|
|
2850
2798
|
}
|
|
2851
2799
|
function createCoreConverters(legacySchema) {
|
|
2852
|
-
return [converterJson, converterPortableText,
|
|
2800
|
+
return [converterJson, converterPortableText, createConverterTextHtml(legacySchema), createConverterTextPlain(legacySchema)];
|
|
2853
2801
|
}
|
|
2854
2802
|
function compileType(rawType) {
|
|
2855
2803
|
return Schema.compile({
|
|
@@ -8511,14 +8459,6 @@ const abstractAnnotationBehaviors = [defineBehavior({
|
|
|
8511
8459
|
data: json,
|
|
8512
8460
|
originEvent: event.originEvent
|
|
8513
8461
|
};
|
|
8514
|
-
const markdown = event.originEvent.originEvent.dataTransfer.getData("text/markdown");
|
|
8515
|
-
if (markdown)
|
|
8516
|
-
return {
|
|
8517
|
-
type: "deserialize.data",
|
|
8518
|
-
mimeType: "text/markdown",
|
|
8519
|
-
data: markdown,
|
|
8520
|
-
originEvent: event.originEvent
|
|
8521
|
-
};
|
|
8522
8462
|
const html = event.originEvent.originEvent.dataTransfer.getData("text/html");
|
|
8523
8463
|
if (html)
|
|
8524
8464
|
return {
|
|
@@ -8649,16 +8589,6 @@ const abstractAnnotationBehaviors = [defineBehavior({
|
|
|
8649
8589
|
};
|
|
8650
8590
|
}
|
|
8651
8591
|
if (event.mimeType === "application/json") {
|
|
8652
|
-
const markdown = event.originEvent.originEvent.dataTransfer.getData("text/markdown");
|
|
8653
|
-
if (markdown)
|
|
8654
|
-
return {
|
|
8655
|
-
type: "deserialize.data",
|
|
8656
|
-
mimeType: "text/markdown",
|
|
8657
|
-
data: markdown,
|
|
8658
|
-
originEvent: event.originEvent
|
|
8659
|
-
};
|
|
8660
|
-
}
|
|
8661
|
-
if (event.mimeType === "text/markdown") {
|
|
8662
8592
|
const html = event.originEvent.originEvent.dataTransfer.getData("text/html");
|
|
8663
8593
|
if (html)
|
|
8664
8594
|
return {
|