@portabletext/editor 1.10.0 → 1.10.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/README.md +21 -6
- package/lib/index.d.mts +284 -10
- package/lib/index.d.ts +284 -10
- package/lib/index.esm.js +47 -32
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +47 -32
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +47 -32
- package/lib/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/editor/PortableTextEditor.tsx +25 -15
- package/src/editor/components/Synchronizer.tsx +2 -2
- package/src/editor/editor-machine.ts +16 -4
- package/src/editor/use-editor.ts +3 -0
package/lib/index.esm.js
CHANGED
|
@@ -2957,11 +2957,10 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
2957
2957
|
}
|
|
2958
2958
|
const debug$i = debugWithName("component:PortableTextEditor:Synchronizer"), debugVerbose$3 = debug$i.enabled && !1, FLUSH_PATCHES_THROTTLED_MS = process.env.NODE_ENV === "test" ? 500 : 1e3;
|
|
2959
2959
|
function Synchronizer(props) {
|
|
2960
|
-
const $ = c(35), portableTextEditor = usePortableTextEditor(), readOnly = useSelector(props.editorActor, _temp$1), {
|
|
2960
|
+
const $ = c(35), portableTextEditor = usePortableTextEditor(), readOnly = useSelector(props.editorActor, _temp$1), value = useSelector(props.editorActor, _temp2), {
|
|
2961
2961
|
editorActor,
|
|
2962
2962
|
getValue,
|
|
2963
|
-
onChange
|
|
2964
|
-
value
|
|
2963
|
+
onChange
|
|
2965
2964
|
} = props;
|
|
2966
2965
|
let t0;
|
|
2967
2966
|
$[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = [], $[0] = t0) : t0 = $[0];
|
|
@@ -3013,52 +3012,52 @@ ${JSON.stringify(pendingPatches.current, null, 2)}`);
|
|
|
3013
3012
|
});
|
|
3014
3013
|
debug$i("Subscribing to editor changes");
|
|
3015
3014
|
const sub = editorActor.on("*", (event) => {
|
|
3016
|
-
|
|
3015
|
+
bb22: switch (event.type) {
|
|
3017
3016
|
case "patch": {
|
|
3018
3017
|
IS_PROCESSING_LOCAL_CHANGES.set(slateEditor, !0), pendingPatches.current.push(event.patch), onFlushPendingPatchesThrottled(), handleChange(event);
|
|
3019
|
-
break
|
|
3018
|
+
break bb22;
|
|
3020
3019
|
}
|
|
3021
3020
|
case "loading": {
|
|
3022
3021
|
handleChange({
|
|
3023
3022
|
type: "loading",
|
|
3024
3023
|
isLoading: !0
|
|
3025
3024
|
});
|
|
3026
|
-
break
|
|
3025
|
+
break bb22;
|
|
3027
3026
|
}
|
|
3028
3027
|
case "done loading": {
|
|
3029
3028
|
handleChange({
|
|
3030
3029
|
type: "loading",
|
|
3031
3030
|
isLoading: !1
|
|
3032
3031
|
});
|
|
3033
|
-
break
|
|
3032
|
+
break bb22;
|
|
3034
3033
|
}
|
|
3035
3034
|
case "focused": {
|
|
3036
3035
|
handleChange({
|
|
3037
3036
|
type: "focus",
|
|
3038
3037
|
event: event.event
|
|
3039
3038
|
});
|
|
3040
|
-
break
|
|
3039
|
+
break bb22;
|
|
3041
3040
|
}
|
|
3042
3041
|
case "offline": {
|
|
3043
3042
|
handleChange({
|
|
3044
3043
|
type: "connection",
|
|
3045
3044
|
value: "offline"
|
|
3046
3045
|
});
|
|
3047
|
-
break
|
|
3046
|
+
break bb22;
|
|
3048
3047
|
}
|
|
3049
3048
|
case "online": {
|
|
3050
3049
|
handleChange({
|
|
3051
3050
|
type: "connection",
|
|
3052
3051
|
value: "online"
|
|
3053
3052
|
});
|
|
3054
|
-
break
|
|
3053
|
+
break bb22;
|
|
3055
3054
|
}
|
|
3056
3055
|
case "value changed": {
|
|
3057
3056
|
handleChange({
|
|
3058
3057
|
type: "value",
|
|
3059
3058
|
value: event.value
|
|
3060
3059
|
});
|
|
3061
|
-
break
|
|
3060
|
+
break bb22;
|
|
3062
3061
|
}
|
|
3063
3062
|
case "invalid value": {
|
|
3064
3063
|
handleChange({
|
|
@@ -3066,21 +3065,21 @@ ${JSON.stringify(pendingPatches.current, null, 2)}`);
|
|
|
3066
3065
|
resolution: event.resolution,
|
|
3067
3066
|
value: event.value
|
|
3068
3067
|
});
|
|
3069
|
-
break
|
|
3068
|
+
break bb22;
|
|
3070
3069
|
}
|
|
3071
3070
|
case "error": {
|
|
3072
3071
|
handleChange({
|
|
3073
3072
|
...event,
|
|
3074
3073
|
level: "warning"
|
|
3075
3074
|
});
|
|
3076
|
-
break
|
|
3075
|
+
break bb22;
|
|
3077
3076
|
}
|
|
3078
3077
|
case "annotation.add":
|
|
3079
3078
|
case "annotation.remove":
|
|
3080
3079
|
case "annotation.toggle":
|
|
3081
3080
|
case "focus":
|
|
3082
3081
|
case "patches":
|
|
3083
|
-
break
|
|
3082
|
+
break bb22;
|
|
3084
3083
|
default:
|
|
3085
3084
|
handleChange(event);
|
|
3086
3085
|
}
|
|
@@ -3109,6 +3108,9 @@ ${JSON.stringify(pendingPatches.current, null, 2)}`);
|
|
|
3109
3108
|
}), isInitialValueFromProps.current = !1);
|
|
3110
3109
|
}, t14 = [editorActor, syncValue, value], $[30] = editorActor, $[31] = syncValue, $[32] = value, $[33] = t13, $[34] = t14) : (t13 = $[33], t14 = $[34]), useEffect(t13, t14), null;
|
|
3111
3110
|
}
|
|
3111
|
+
function _temp2(s_0) {
|
|
3112
|
+
return s_0.context.value;
|
|
3113
|
+
}
|
|
3112
3114
|
function _temp$1(s) {
|
|
3113
3115
|
return s.context.readOnly;
|
|
3114
3116
|
}
|
|
@@ -5726,8 +5728,8 @@ const networkLogic = fromCallback(({
|
|
|
5726
5728
|
type: "offline"
|
|
5727
5729
|
});
|
|
5728
5730
|
};
|
|
5729
|
-
return window.addEventListener("online", onlineHandler), window.addEventListener("offline", offlineHandler), () => {
|
|
5730
|
-
window.removeEventListener("online", onlineHandler), window.removeEventListener("offline", offlineHandler);
|
|
5731
|
+
return window && (window.addEventListener("online", onlineHandler), window.addEventListener("offline", offlineHandler)), () => {
|
|
5732
|
+
window && (window.removeEventListener("online", onlineHandler), window.removeEventListener("offline", offlineHandler));
|
|
5731
5733
|
};
|
|
5732
5734
|
}), editorMachine = setup({
|
|
5733
5735
|
types: {
|
|
@@ -5842,7 +5844,8 @@ const networkLogic = fromCallback(({
|
|
|
5842
5844
|
pendingEvents: [],
|
|
5843
5845
|
schema: input.schema,
|
|
5844
5846
|
readOnly: !1,
|
|
5845
|
-
maxBlocks: void 0
|
|
5847
|
+
maxBlocks: void 0,
|
|
5848
|
+
value: input.value
|
|
5846
5849
|
}),
|
|
5847
5850
|
invoke: {
|
|
5848
5851
|
id: "networkLogic",
|
|
@@ -5952,6 +5955,13 @@ const networkLogic = fromCallback(({
|
|
|
5952
5955
|
"update schema": {
|
|
5953
5956
|
actions: "assign schema"
|
|
5954
5957
|
},
|
|
5958
|
+
"update value": {
|
|
5959
|
+
actions: assign({
|
|
5960
|
+
value: ({
|
|
5961
|
+
event
|
|
5962
|
+
}) => event.value
|
|
5963
|
+
})
|
|
5964
|
+
},
|
|
5955
5965
|
"toggle readOnly": {
|
|
5956
5966
|
actions: assign({
|
|
5957
5967
|
readOnly: ({
|
|
@@ -6113,7 +6123,8 @@ class PortableTextEditor extends Component {
|
|
|
6113
6123
|
props.incomingPatches$ && console.warn("The prop 'incomingPatches$' is deprecated and renamed to 'patches$'"), this.schemaTypes = getPortableTextMemberSchemaTypes(props.schemaType.hasOwnProperty("jsonType") ? props.schemaType : compileType(props.schemaType)), this.editorActor = createActor(editorMachine, {
|
|
6114
6124
|
input: {
|
|
6115
6125
|
keyGenerator: props.keyGenerator || defaultKeyGenerator,
|
|
6116
|
-
schema: this.schemaTypes
|
|
6126
|
+
schema: this.schemaTypes,
|
|
6127
|
+
value: props.value
|
|
6117
6128
|
}
|
|
6118
6129
|
}), this.editorActor.start(), this.slateEditor = createSlateEditor({
|
|
6119
6130
|
editorActor: this.editorActor
|
|
@@ -6135,7 +6146,10 @@ class PortableTextEditor extends Component {
|
|
|
6135
6146
|
}), this.props.maxBlocks !== prevProps.maxBlocks && this.editorActor.send({
|
|
6136
6147
|
type: "update maxBlocks",
|
|
6137
6148
|
maxBlocks: this.props.maxBlocks === void 0 ? void 0 : Number.parseInt(this.props.maxBlocks.toString(), 10)
|
|
6138
|
-
})
|
|
6149
|
+
}), this.props.value !== prevProps.value && this.editorActor.send({
|
|
6150
|
+
type: "update value",
|
|
6151
|
+
value: this.props.value
|
|
6152
|
+
}), this.props.editorRef !== prevProps.editorRef && this.props.editorRef && (this.props.editorRef.current = this));
|
|
6139
6153
|
}
|
|
6140
6154
|
setEditable = (editable) => {
|
|
6141
6155
|
this.editable = {
|
|
@@ -6154,7 +6168,7 @@ class PortableTextEditor extends Component {
|
|
|
6154
6168
|
/* @__PURE__ */ jsx(EditorActorContext.Provider, { value: this.editorActor, children: /* @__PURE__ */ jsx(Slate, { editor: this.slateEditor.instance, initialValue: this.slateEditor.initialValue, children: /* @__PURE__ */ jsx(PortableTextEditorContext.Provider, { value: this, children: /* @__PURE__ */ jsxs(PortableTextEditorSelectionProvider, { editorActor: this.editorActor, children: [
|
|
6155
6169
|
/* @__PURE__ */ jsx(Synchronizer, { editorActor: this.editorActor, getValue: this.getValue, onChange: (change) => {
|
|
6156
6170
|
this.props.editor || this.props.onChange(change), this.change$.next(change);
|
|
6157
|
-
}
|
|
6171
|
+
} }),
|
|
6158
6172
|
this.props.children
|
|
6159
6173
|
] }) }) }) })
|
|
6160
6174
|
] });
|
|
@@ -6920,39 +6934,40 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6920
6934
|
});
|
|
6921
6935
|
PortableTextEditable.displayName = "ForwardRef(PortableTextEditable)";
|
|
6922
6936
|
function useEditor(config) {
|
|
6923
|
-
const $ = c(
|
|
6937
|
+
const $ = c(21), t0 = config.keyGenerator ?? defaultKeyGenerator;
|
|
6924
6938
|
let t1;
|
|
6925
6939
|
$[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];
|
|
6926
6940
|
let t2;
|
|
6927
|
-
$[3] !== config.behaviors || $[4] !==
|
|
6941
|
+
$[3] !== config.behaviors || $[4] !== config.initialValue || $[5] !== t0 || $[6] !== t1 ? (t2 = {
|
|
6928
6942
|
input: {
|
|
6929
6943
|
behaviors: config.behaviors,
|
|
6930
6944
|
keyGenerator: t0,
|
|
6931
|
-
schema: t1
|
|
6945
|
+
schema: t1,
|
|
6946
|
+
value: config.initialValue
|
|
6932
6947
|
}
|
|
6933
|
-
}, $[3] = config.behaviors, $[4] =
|
|
6948
|
+
}, $[3] = config.behaviors, $[4] = config.initialValue, $[5] = t0, $[6] = t1, $[7] = t2) : t2 = $[7];
|
|
6934
6949
|
const editorActor = useActorRef(editorMachine, t2);
|
|
6935
6950
|
let t3;
|
|
6936
|
-
$[
|
|
6951
|
+
$[8] !== editorActor ? (t3 = createSlateEditor({
|
|
6937
6952
|
editorActor
|
|
6938
|
-
}), $[
|
|
6953
|
+
}), $[8] = editorActor, $[9] = t3) : t3 = $[9];
|
|
6939
6954
|
const slateEditor = t3, readOnly = useSelector(editorActor, _temp);
|
|
6940
6955
|
let t4, t5;
|
|
6941
|
-
$[
|
|
6956
|
+
$[10] !== editorActor ? (t4 = (event) => {
|
|
6942
6957
|
editorActor.send(event);
|
|
6943
|
-
}, t5 = (event_0, listener) => editorActor.on(event_0, listener), $[
|
|
6958
|
+
}, t5 = (event_0, listener) => editorActor.on(event_0, listener), $[10] = editorActor, $[11] = t4, $[12] = t5) : (t4 = $[11], t5 = $[12]);
|
|
6944
6959
|
let t6;
|
|
6945
|
-
$[
|
|
6960
|
+
$[13] !== editorActor || $[14] !== slateEditor ? (t6 = {
|
|
6946
6961
|
editorActor,
|
|
6947
6962
|
slateEditor
|
|
6948
|
-
}, $[
|
|
6963
|
+
}, $[13] = editorActor, $[14] = slateEditor, $[15] = t6) : t6 = $[15];
|
|
6949
6964
|
let t7;
|
|
6950
|
-
return $[
|
|
6965
|
+
return $[16] !== readOnly || $[17] !== t4 || $[18] !== t5 || $[19] !== t6 ? (t7 = {
|
|
6951
6966
|
send: t4,
|
|
6952
6967
|
on: t5,
|
|
6953
6968
|
readOnly,
|
|
6954
6969
|
_internal: t6
|
|
6955
|
-
}, $[
|
|
6970
|
+
}, $[16] = readOnly, $[17] = t4, $[18] = t5, $[19] = t6, $[20] = t7) : t7 = $[20], t7;
|
|
6956
6971
|
}
|
|
6957
6972
|
function _temp(s) {
|
|
6958
6973
|
return s.context.readOnly;
|