@portabletext/editor 1.7.0 → 1.7.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.d.mts +11 -2
- package/lib/index.d.ts +11 -2
- package/lib/index.esm.js +33 -28
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +33 -28
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +33 -28
- package/lib/index.mjs.map +1 -1
- package/package.json +9 -9
- package/src/editor/PortableTextEditor.tsx +5 -7
- package/src/editor/create-slate-editor.tsx +13 -8
- package/src/editor/use-editor.ts +4 -0
- package/src/index.ts +1 -0
package/lib/index.mjs
CHANGED
|
@@ -4647,17 +4647,19 @@ function createSlateEditor(config) {
|
|
|
4647
4647
|
KEY_TO_VALUE_ELEMENT.set(instance, {}), KEY_TO_SLATE_ELEMENT.set(instance, {});
|
|
4648
4648
|
for (const subscription of subscriptions)
|
|
4649
4649
|
unsubscriptions.push(subscription());
|
|
4650
|
-
|
|
4651
|
-
|
|
4652
|
-
})], slateEditor = {
|
|
4653
|
-
instance,
|
|
4654
|
-
initialValue,
|
|
4655
|
-
destroy: () => {
|
|
4650
|
+
config.editorActor.subscribe((snapshot) => {
|
|
4651
|
+
if (snapshot.status !== "active") {
|
|
4656
4652
|
debug$7("Destroying Slate editor"), instance.destroy();
|
|
4657
4653
|
for (const unsubscribe of unsubscriptions)
|
|
4658
4654
|
unsubscribe();
|
|
4659
4655
|
subscriptions = [], unsubscriptions = [];
|
|
4660
4656
|
}
|
|
4657
|
+
});
|
|
4658
|
+
const initialValue = [instance.pteCreateTextBlock({
|
|
4659
|
+
decorators: []
|
|
4660
|
+
})], slateEditor = {
|
|
4661
|
+
instance,
|
|
4662
|
+
initialValue
|
|
4661
4663
|
};
|
|
4662
4664
|
return slateEditors.set(config.editorActor, slateEditor), slateEditor;
|
|
4663
4665
|
}
|
|
@@ -5912,7 +5914,7 @@ class PortableTextEditor extends Component {
|
|
|
5912
5914
|
constructor(props) {
|
|
5913
5915
|
if (super(props), props.editor) {
|
|
5914
5916
|
const editor = props.editor;
|
|
5915
|
-
this.editorActor = editor._internal.editorActor, this.editorActor.start(), this.schemaTypes = this.editorActor.getSnapshot().context.schema;
|
|
5917
|
+
this.editorActor = editor._internal.editorActor, this.slateEditor = editor._internal.slateEditor, this.editorActor.start(), this.schemaTypes = this.editorActor.getSnapshot().context.schema;
|
|
5916
5918
|
} else {
|
|
5917
5919
|
if (!props.schemaType)
|
|
5918
5920
|
throw new Error('PortableTextEditor: missing "schemaType" property');
|
|
@@ -5921,16 +5923,16 @@ class PortableTextEditor extends Component {
|
|
|
5921
5923
|
keyGenerator: props.keyGenerator || defaultKeyGenerator,
|
|
5922
5924
|
schema: this.schemaTypes
|
|
5923
5925
|
}
|
|
5924
|
-
}), this.editorActor.start(),
|
|
5926
|
+
}), this.editorActor.start(), this.slateEditor = createSlateEditor({
|
|
5927
|
+
editorActor: this.editorActor
|
|
5928
|
+
}), props.readOnly && this.editorActor.send({
|
|
5925
5929
|
type: "toggle readOnly"
|
|
5926
5930
|
}), props.maxBlocks && this.editorActor.send({
|
|
5927
5931
|
type: "update maxBlocks",
|
|
5928
5932
|
maxBlocks: props.maxBlocks === void 0 ? void 0 : Number.parseInt(props.maxBlocks.toString(), 10)
|
|
5929
5933
|
});
|
|
5930
5934
|
}
|
|
5931
|
-
this.
|
|
5932
|
-
editorActor: this.editorActor
|
|
5933
|
-
}), this.editable = createEditableAPI(this.slateEditor.instance, this.editorActor);
|
|
5935
|
+
this.editable = createEditableAPI(this.slateEditor.instance, this.editorActor);
|
|
5934
5936
|
}
|
|
5935
5937
|
componentDidUpdate(prevProps) {
|
|
5936
5938
|
!this.props.editor && !prevProps.editor && this.props.schemaType !== prevProps.schemaType && (this.schemaTypes = getPortableTextMemberSchemaTypes(this.props.schemaType.hasOwnProperty("jsonType") ? this.props.schemaType : compileType(this.props.schemaType)), this.editorActor.send({
|
|
@@ -5943,9 +5945,6 @@ class PortableTextEditor extends Component {
|
|
|
5943
5945
|
maxBlocks: this.props.maxBlocks === void 0 ? void 0 : Number.parseInt(this.props.maxBlocks.toString(), 10)
|
|
5944
5946
|
})), this.props.editorRef !== prevProps.editorRef && this.props.editorRef && (this.props.editorRef.current = this);
|
|
5945
5947
|
}
|
|
5946
|
-
componentWillUnmount() {
|
|
5947
|
-
this.slateEditor.destroy();
|
|
5948
|
-
}
|
|
5949
5948
|
setEditable = (editable) => {
|
|
5950
5949
|
this.editable = {
|
|
5951
5950
|
...this.editable,
|
|
@@ -6732,7 +6731,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6732
6731
|
});
|
|
6733
6732
|
PortableTextEditable.displayName = "ForwardRef(PortableTextEditable)";
|
|
6734
6733
|
function useEditor(config) {
|
|
6735
|
-
const $ = c(
|
|
6734
|
+
const $ = c(20), t0 = config.keyGenerator ?? defaultKeyGenerator;
|
|
6736
6735
|
let t1;
|
|
6737
6736
|
$[0] !== config.schema || $[1] !== config.schemaDefinition ? (t1 = config.schemaDefinition ? compileSchemaDefinition(config.schemaDefinition) : getPortableTextMemberSchemaTypes(config.schema.hasOwnProperty("jsonType") ? config.schema : compileType(config.schema)), $[0] = config.schema, $[1] = config.schemaDefinition, $[2] = t1) : t1 = $[2];
|
|
6738
6737
|
let t2;
|
|
@@ -6743,22 +6742,28 @@ function useEditor(config) {
|
|
|
6743
6742
|
schema: t1
|
|
6744
6743
|
}
|
|
6745
6744
|
}, $[3] = config.behaviors, $[4] = t0, $[5] = t1, $[6] = t2) : t2 = $[6];
|
|
6746
|
-
const editorActor = useActorRef(editorMachine, t2)
|
|
6747
|
-
let t3
|
|
6748
|
-
$[7] !== editorActor ? (t3 = (
|
|
6749
|
-
editorActor.send(event);
|
|
6750
|
-
}, t4 = (event_0, listener) => editorActor.on(event_0, listener), $[7] = editorActor, $[8] = t3, $[9] = t4) : (t3 = $[8], t4 = $[9]);
|
|
6751
|
-
let t5;
|
|
6752
|
-
$[10] !== editorActor ? (t5 = {
|
|
6745
|
+
const editorActor = useActorRef(editorMachine, t2);
|
|
6746
|
+
let t3;
|
|
6747
|
+
$[7] !== editorActor ? (t3 = createSlateEditor({
|
|
6753
6748
|
editorActor
|
|
6754
|
-
}, $[
|
|
6749
|
+
}), $[7] = editorActor, $[8] = t3) : t3 = $[8];
|
|
6750
|
+
const slateEditor = t3, readOnly = useSelector(editorActor, _temp);
|
|
6751
|
+
let t4, t5;
|
|
6752
|
+
$[9] !== editorActor ? (t4 = (event) => {
|
|
6753
|
+
editorActor.send(event);
|
|
6754
|
+
}, t5 = (event_0, listener) => editorActor.on(event_0, listener), $[9] = editorActor, $[10] = t4, $[11] = t5) : (t4 = $[10], t5 = $[11]);
|
|
6755
6755
|
let t6;
|
|
6756
|
-
|
|
6757
|
-
|
|
6758
|
-
|
|
6756
|
+
$[12] !== editorActor || $[13] !== slateEditor ? (t6 = {
|
|
6757
|
+
editorActor,
|
|
6758
|
+
slateEditor
|
|
6759
|
+
}, $[12] = editorActor, $[13] = slateEditor, $[14] = t6) : t6 = $[14];
|
|
6760
|
+
let t7;
|
|
6761
|
+
return $[15] !== readOnly || $[16] !== t4 || $[17] !== t5 || $[18] !== t6 ? (t7 = {
|
|
6762
|
+
send: t4,
|
|
6763
|
+
on: t5,
|
|
6759
6764
|
readOnly,
|
|
6760
|
-
_internal:
|
|
6761
|
-
}, $[
|
|
6765
|
+
_internal: t6
|
|
6766
|
+
}, $[15] = readOnly, $[16] = t4, $[17] = t5, $[18] = t6, $[19] = t7) : t7 = $[19], t7;
|
|
6762
6767
|
}
|
|
6763
6768
|
function _temp(s) {
|
|
6764
6769
|
return s.context.readOnly;
|