@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.js
CHANGED
|
@@ -4626,17 +4626,19 @@ function createSlateEditor(config) {
|
|
|
4626
4626
|
KEY_TO_VALUE_ELEMENT.set(instance, {}), KEY_TO_SLATE_ELEMENT.set(instance, {});
|
|
4627
4627
|
for (const subscription of subscriptions)
|
|
4628
4628
|
unsubscriptions.push(subscription());
|
|
4629
|
-
|
|
4630
|
-
|
|
4631
|
-
})], slateEditor = {
|
|
4632
|
-
instance,
|
|
4633
|
-
initialValue,
|
|
4634
|
-
destroy: () => {
|
|
4629
|
+
config.editorActor.subscribe((snapshot) => {
|
|
4630
|
+
if (snapshot.status !== "active") {
|
|
4635
4631
|
debug$7("Destroying Slate editor"), instance.destroy();
|
|
4636
4632
|
for (const unsubscribe of unsubscriptions)
|
|
4637
4633
|
unsubscribe();
|
|
4638
4634
|
subscriptions = [], unsubscriptions = [];
|
|
4639
4635
|
}
|
|
4636
|
+
});
|
|
4637
|
+
const initialValue = [instance.pteCreateTextBlock({
|
|
4638
|
+
decorators: []
|
|
4639
|
+
})], slateEditor = {
|
|
4640
|
+
instance,
|
|
4641
|
+
initialValue
|
|
4640
4642
|
};
|
|
4641
4643
|
return slateEditors.set(config.editorActor, slateEditor), slateEditor;
|
|
4642
4644
|
}
|
|
@@ -5891,7 +5893,7 @@ class PortableTextEditor extends react.Component {
|
|
|
5891
5893
|
constructor(props) {
|
|
5892
5894
|
if (super(props), props.editor) {
|
|
5893
5895
|
const editor = props.editor;
|
|
5894
|
-
this.editorActor = editor._internal.editorActor, this.editorActor.start(), this.schemaTypes = this.editorActor.getSnapshot().context.schema;
|
|
5896
|
+
this.editorActor = editor._internal.editorActor, this.slateEditor = editor._internal.slateEditor, this.editorActor.start(), this.schemaTypes = this.editorActor.getSnapshot().context.schema;
|
|
5895
5897
|
} else {
|
|
5896
5898
|
if (!props.schemaType)
|
|
5897
5899
|
throw new Error('PortableTextEditor: missing "schemaType" property');
|
|
@@ -5900,16 +5902,16 @@ class PortableTextEditor extends react.Component {
|
|
|
5900
5902
|
keyGenerator: props.keyGenerator || defaultKeyGenerator,
|
|
5901
5903
|
schema: this.schemaTypes
|
|
5902
5904
|
}
|
|
5903
|
-
}), this.editorActor.start(),
|
|
5905
|
+
}), this.editorActor.start(), this.slateEditor = createSlateEditor({
|
|
5906
|
+
editorActor: this.editorActor
|
|
5907
|
+
}), props.readOnly && this.editorActor.send({
|
|
5904
5908
|
type: "toggle readOnly"
|
|
5905
5909
|
}), props.maxBlocks && this.editorActor.send({
|
|
5906
5910
|
type: "update maxBlocks",
|
|
5907
5911
|
maxBlocks: props.maxBlocks === void 0 ? void 0 : Number.parseInt(props.maxBlocks.toString(), 10)
|
|
5908
5912
|
});
|
|
5909
5913
|
}
|
|
5910
|
-
this.
|
|
5911
|
-
editorActor: this.editorActor
|
|
5912
|
-
}), this.editable = createEditableAPI(this.slateEditor.instance, this.editorActor);
|
|
5914
|
+
this.editable = createEditableAPI(this.slateEditor.instance, this.editorActor);
|
|
5913
5915
|
}
|
|
5914
5916
|
componentDidUpdate(prevProps) {
|
|
5915
5917
|
!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({
|
|
@@ -5922,9 +5924,6 @@ class PortableTextEditor extends react.Component {
|
|
|
5922
5924
|
maxBlocks: this.props.maxBlocks === void 0 ? void 0 : Number.parseInt(this.props.maxBlocks.toString(), 10)
|
|
5923
5925
|
})), this.props.editorRef !== prevProps.editorRef && this.props.editorRef && (this.props.editorRef.current = this);
|
|
5924
5926
|
}
|
|
5925
|
-
componentWillUnmount() {
|
|
5926
|
-
this.slateEditor.destroy();
|
|
5927
|
-
}
|
|
5928
5927
|
setEditable = (editable) => {
|
|
5929
5928
|
this.editable = {
|
|
5930
5929
|
...this.editable,
|
|
@@ -6711,7 +6710,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6711
6710
|
});
|
|
6712
6711
|
PortableTextEditable.displayName = "ForwardRef(PortableTextEditable)";
|
|
6713
6712
|
function useEditor(config) {
|
|
6714
|
-
const $ = reactCompilerRuntime.c(
|
|
6713
|
+
const $ = reactCompilerRuntime.c(20), t0 = config.keyGenerator ?? defaultKeyGenerator;
|
|
6715
6714
|
let t1;
|
|
6716
6715
|
$[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];
|
|
6717
6716
|
let t2;
|
|
@@ -6722,22 +6721,28 @@ function useEditor(config) {
|
|
|
6722
6721
|
schema: t1
|
|
6723
6722
|
}
|
|
6724
6723
|
}, $[3] = config.behaviors, $[4] = t0, $[5] = t1, $[6] = t2) : t2 = $[6];
|
|
6725
|
-
const editorActor = react$1.useActorRef(editorMachine, t2)
|
|
6726
|
-
let t3
|
|
6727
|
-
$[7] !== editorActor ? (t3 = (
|
|
6728
|
-
editorActor.send(event);
|
|
6729
|
-
}, t4 = (event_0, listener) => editorActor.on(event_0, listener), $[7] = editorActor, $[8] = t3, $[9] = t4) : (t3 = $[8], t4 = $[9]);
|
|
6730
|
-
let t5;
|
|
6731
|
-
$[10] !== editorActor ? (t5 = {
|
|
6724
|
+
const editorActor = react$1.useActorRef(editorMachine, t2);
|
|
6725
|
+
let t3;
|
|
6726
|
+
$[7] !== editorActor ? (t3 = createSlateEditor({
|
|
6732
6727
|
editorActor
|
|
6733
|
-
}, $[
|
|
6728
|
+
}), $[7] = editorActor, $[8] = t3) : t3 = $[8];
|
|
6729
|
+
const slateEditor = t3, readOnly = react$1.useSelector(editorActor, _temp);
|
|
6730
|
+
let t4, t5;
|
|
6731
|
+
$[9] !== editorActor ? (t4 = (event) => {
|
|
6732
|
+
editorActor.send(event);
|
|
6733
|
+
}, t5 = (event_0, listener) => editorActor.on(event_0, listener), $[9] = editorActor, $[10] = t4, $[11] = t5) : (t4 = $[10], t5 = $[11]);
|
|
6734
6734
|
let t6;
|
|
6735
|
-
|
|
6736
|
-
|
|
6737
|
-
|
|
6735
|
+
$[12] !== editorActor || $[13] !== slateEditor ? (t6 = {
|
|
6736
|
+
editorActor,
|
|
6737
|
+
slateEditor
|
|
6738
|
+
}, $[12] = editorActor, $[13] = slateEditor, $[14] = t6) : t6 = $[14];
|
|
6739
|
+
let t7;
|
|
6740
|
+
return $[15] !== readOnly || $[16] !== t4 || $[17] !== t5 || $[18] !== t6 ? (t7 = {
|
|
6741
|
+
send: t4,
|
|
6742
|
+
on: t5,
|
|
6738
6743
|
readOnly,
|
|
6739
|
-
_internal:
|
|
6740
|
-
}, $[
|
|
6744
|
+
_internal: t6
|
|
6745
|
+
}, $[15] = readOnly, $[16] = t4, $[17] = t5, $[18] = t6, $[19] = t7) : t7 = $[19], t7;
|
|
6741
6746
|
}
|
|
6742
6747
|
function _temp(s) {
|
|
6743
6748
|
return s.context.readOnly;
|