@portabletext/editor 1.45.3 → 1.46.0
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/behavior.core.cjs +20 -0
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/behavior.markdown.cjs +25 -25
- package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -1
- package/lib/_chunks-cjs/editor-provider.cjs +93 -59
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +20 -0
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/behavior.markdown.js +26 -26
- package/lib/_chunks-es/behavior.markdown.js.map +1 -1
- package/lib/_chunks-es/editor-provider.js +93 -59
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +1 -1
- package/lib/behaviors/index.cjs +37 -53
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +52 -37
- package/lib/behaviors/index.d.ts +52 -37
- package/lib/behaviors/index.js +38 -54
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.d.cts +33 -37
- package/lib/index.d.ts +33 -37
- package/lib/plugins/index.cjs +23 -29
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +33 -37
- package/lib/plugins/index.d.ts +33 -37
- package/lib/plugins/index.js +24 -30
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.d.cts +33 -37
- package/lib/selectors/index.d.ts +33 -37
- package/lib/utils/index.d.cts +33 -37
- package/lib/utils/index.d.ts +33 -37
- package/package.json +1 -1
- package/src/behaviors/behavior.decorator-pair.ts +16 -19
- package/src/behaviors/behavior.emoji-picker.ts +26 -45
- package/src/behaviors/behavior.links.ts +5 -4
- package/src/behaviors/behavior.markdown.ts +37 -34
- package/src/behaviors/behavior.perform-event.ts +67 -18
- package/src/behaviors/behavior.types.action.ts +39 -13
- package/src/behaviors/behavior.types.guard.ts +1 -6
- package/src/behaviors/index.ts +3 -0
- package/src/editor/components/Synchronizer.tsx +6 -3
- package/src/editor/create-editor.ts +1 -1
- package/src/editor/editor-machine.ts +8 -6
- package/src/plugins/plugin.decorator-shortcut.ts +6 -8
- package/src/plugins/plugin.one-line.tsx +4 -4
|
@@ -2038,7 +2038,7 @@ function Synchronizer(props) {
|
|
|
2038
2038
|
const $ = reactCompilerRuntime.c(41), {
|
|
2039
2039
|
editorActor,
|
|
2040
2040
|
slateEditor
|
|
2041
|
-
} = props,
|
|
2041
|
+
} = props, incomingValue = react.useSelector(props.editorActor, _temp), readOnly = react.useSelector(props.editorActor, _temp2);
|
|
2042
2042
|
let t0;
|
|
2043
2043
|
$[0] !== props.editorActor ? (t0 = props.editorActor.getSnapshot(), $[0] = props.editorActor, $[1] = t0) : t0 = $[1];
|
|
2044
2044
|
const t1 = t0.context.keyGenerator;
|
|
@@ -2128,12 +2128,12 @@ function Synchronizer(props) {
|
|
|
2128
2128
|
});
|
|
2129
2129
|
}, t12 = [syncActorRef, readOnly], $[26] = readOnly, $[27] = syncActorRef, $[28] = t11, $[29] = t12) : (t11 = $[28], t12 = $[29]), React.useEffect(t11, t12);
|
|
2130
2130
|
let t13, t14;
|
|
2131
|
-
$[30] !==
|
|
2131
|
+
$[30] !== incomingValue || $[31] !== syncActorRef ? (t13 = () => {
|
|
2132
2132
|
debug$d("Value from props changed, syncing new value"), syncActorRef.send({
|
|
2133
2133
|
type: "update value",
|
|
2134
|
-
value
|
|
2134
|
+
value: incomingValue
|
|
2135
2135
|
});
|
|
2136
|
-
}, t14 = [syncActorRef,
|
|
2136
|
+
}, t14 = [syncActorRef, incomingValue], $[30] = incomingValue, $[31] = syncActorRef, $[32] = t13, $[33] = t14) : (t13 = $[32], t14 = $[33]), React.useEffect(t13, t14);
|
|
2137
2137
|
let t15;
|
|
2138
2138
|
$[34] !== editorActor || $[35] !== mutationActorRef ? (t15 = () => {
|
|
2139
2139
|
debug$d("Subscribing to patch events");
|
|
@@ -2156,7 +2156,7 @@ function _temp2(s_0) {
|
|
|
2156
2156
|
});
|
|
2157
2157
|
}
|
|
2158
2158
|
function _temp(s) {
|
|
2159
|
-
return s.context.
|
|
2159
|
+
return s.context.incomingValue;
|
|
2160
2160
|
}
|
|
2161
2161
|
Synchronizer.displayName = "Synchronizer";
|
|
2162
2162
|
const converterJson = {
|
|
@@ -5967,6 +5967,7 @@ function eventCategory(event) {
|
|
|
5967
5967
|
return isNativeBehaviorEvent(event) ? "native" : isAbstractBehaviorEvent(event) ? "abstract" : isCustomBehaviorEvent(event) ? "custom" : "synthetic";
|
|
5968
5968
|
}
|
|
5969
5969
|
function performEvent({
|
|
5970
|
+
mode,
|
|
5970
5971
|
behaviors,
|
|
5971
5972
|
event,
|
|
5972
5973
|
editor,
|
|
@@ -5980,7 +5981,7 @@ function performEvent({
|
|
|
5980
5981
|
const defaultAction = isCustomBehaviorEvent(event) || isNativeBehaviorEvent(event) || isAbstractBehaviorEvent(event) ? void 0 : {
|
|
5981
5982
|
...event,
|
|
5982
5983
|
editor
|
|
5983
|
-
}, eventBehaviors = behaviors.filter((behavior) => {
|
|
5984
|
+
}, eventBehaviors = (mode === "raise" ? [...behaviors, ...defaultBehaviors] : behaviors).filter((behavior) => {
|
|
5984
5985
|
if (behavior.on === "*")
|
|
5985
5986
|
return !0;
|
|
5986
5987
|
const [listenedNamespace] = behavior.on.includes("*") && behavior.on.includes(".") ? behavior.on.split(".") : [void 0], [eventNamespace] = event.type.includes(".") ? event.type.split(".") : [void 0];
|
|
@@ -6007,65 +6008,97 @@ function performEvent({
|
|
|
6007
6008
|
schema: schema2
|
|
6008
6009
|
},
|
|
6009
6010
|
action: defaultAction
|
|
6010
|
-
});
|
|
6011
|
+
}), editor.onChange();
|
|
6011
6012
|
} catch (error) {
|
|
6012
6013
|
console.error(new Error(`Performing action "${defaultAction.type}" as a result of "${event.type}" failed due to: ${error.message}`));
|
|
6013
6014
|
}
|
|
6014
|
-
})
|
|
6015
|
+
});
|
|
6015
6016
|
return;
|
|
6016
6017
|
}
|
|
6017
|
-
const
|
|
6018
|
+
const guardSnapshot = getSnapshot();
|
|
6018
6019
|
let behaviorOverwritten = !1;
|
|
6019
6020
|
for (const eventBehavior of eventBehaviors) {
|
|
6020
6021
|
const shouldRun = eventBehavior.guard === void 0 || eventBehavior.guard({
|
|
6021
|
-
|
|
6022
|
-
snapshot: editorSnapshot,
|
|
6022
|
+
snapshot: guardSnapshot,
|
|
6023
6023
|
event
|
|
6024
6024
|
});
|
|
6025
|
-
if (
|
|
6026
|
-
|
|
6027
|
-
|
|
6028
|
-
|
|
6029
|
-
|
|
6030
|
-
|
|
6031
|
-
|
|
6032
|
-
|
|
6033
|
-
|
|
6034
|
-
|
|
6035
|
-
|
|
6036
|
-
|
|
6037
|
-
|
|
6038
|
-
|
|
6039
|
-
editor,
|
|
6040
|
-
keyGenerator,
|
|
6041
|
-
schema: schema2,
|
|
6042
|
-
getSnapshot,
|
|
6043
|
-
defaultActionCallback: void 0,
|
|
6044
|
-
nativeEvent: void 0
|
|
6045
|
-
});
|
|
6046
|
-
continue;
|
|
6047
|
-
}
|
|
6048
|
-
const internalAction = {
|
|
6049
|
-
...action,
|
|
6050
|
-
editor
|
|
6051
|
-
};
|
|
6052
|
-
try {
|
|
6053
|
-
performAction({
|
|
6054
|
-
context: {
|
|
6025
|
+
if (shouldRun) {
|
|
6026
|
+
for (const actionSet of eventBehavior.actions) {
|
|
6027
|
+
const actionsSnapshot = getSnapshot(), actions = actionSet({
|
|
6028
|
+
snapshot: actionsSnapshot,
|
|
6029
|
+
event
|
|
6030
|
+
}, shouldRun);
|
|
6031
|
+
actions.length !== 0 && (behaviorOverwritten = behaviorOverwritten || actions.some((action) => action.type !== "effect"), withApplyingBehaviorActionSet(editor, () => {
|
|
6032
|
+
for (const action of actions) {
|
|
6033
|
+
if (action.type === "raise") {
|
|
6034
|
+
performEvent({
|
|
6035
|
+
mode,
|
|
6036
|
+
behaviors: mode === "execute" ? isCustomBehaviorEvent(action.event) ? [...behaviors, ...defaultBehaviors] : defaultBehaviors : [...behaviors, ...defaultBehaviors],
|
|
6037
|
+
event: action.event,
|
|
6038
|
+
editor,
|
|
6055
6039
|
keyGenerator,
|
|
6056
|
-
schema: schema2
|
|
6057
|
-
|
|
6058
|
-
|
|
6059
|
-
|
|
6060
|
-
|
|
6061
|
-
|
|
6062
|
-
|
|
6040
|
+
schema: schema2,
|
|
6041
|
+
getSnapshot,
|
|
6042
|
+
defaultActionCallback: void 0,
|
|
6043
|
+
nativeEvent: void 0
|
|
6044
|
+
});
|
|
6045
|
+
continue;
|
|
6046
|
+
}
|
|
6047
|
+
if (action.type === "execute") {
|
|
6048
|
+
if (isAbstractBehaviorEvent(action.event) || isCustomBehaviorEvent(action.event))
|
|
6049
|
+
performEvent({
|
|
6050
|
+
mode: "execute",
|
|
6051
|
+
behaviors: isCustomBehaviorEvent(action.event) ? [...behaviors, ...defaultBehaviors] : defaultBehaviors,
|
|
6052
|
+
event: action.event,
|
|
6053
|
+
editor,
|
|
6054
|
+
keyGenerator,
|
|
6055
|
+
schema: schema2,
|
|
6056
|
+
getSnapshot,
|
|
6057
|
+
defaultActionCallback: void 0,
|
|
6058
|
+
nativeEvent: void 0
|
|
6059
|
+
});
|
|
6060
|
+
else
|
|
6061
|
+
try {
|
|
6062
|
+
performAction({
|
|
6063
|
+
context: {
|
|
6064
|
+
keyGenerator,
|
|
6065
|
+
schema: schema2
|
|
6066
|
+
},
|
|
6067
|
+
action: {
|
|
6068
|
+
...action.event,
|
|
6069
|
+
editor
|
|
6070
|
+
}
|
|
6071
|
+
});
|
|
6072
|
+
} catch (error) {
|
|
6073
|
+
console.error(new Error(`Performing action "${action.event.type}" as a result of "${event.type}" failed due to: ${error.message}`));
|
|
6074
|
+
break;
|
|
6075
|
+
}
|
|
6076
|
+
continue;
|
|
6077
|
+
}
|
|
6078
|
+
const internalAction = {
|
|
6079
|
+
...action,
|
|
6080
|
+
editor
|
|
6081
|
+
};
|
|
6082
|
+
try {
|
|
6083
|
+
performAction({
|
|
6084
|
+
context: {
|
|
6085
|
+
keyGenerator,
|
|
6086
|
+
schema: schema2
|
|
6087
|
+
},
|
|
6088
|
+
action: internalAction
|
|
6089
|
+
});
|
|
6090
|
+
} catch (error) {
|
|
6091
|
+
console.error(new Error(`Performing action "${internalAction.type}" as a result of "${event.type}" failed due to: ${error.message}`));
|
|
6092
|
+
break;
|
|
6093
|
+
}
|
|
6063
6094
|
}
|
|
6064
|
-
|
|
6065
|
-
|
|
6066
|
-
|
|
6067
|
-
|
|
6068
|
-
|
|
6095
|
+
editor.onChange();
|
|
6096
|
+
}));
|
|
6097
|
+
}
|
|
6098
|
+
if (behaviorOverwritten) {
|
|
6099
|
+
nativeEvent?.preventDefault();
|
|
6100
|
+
break;
|
|
6101
|
+
}
|
|
6069
6102
|
}
|
|
6070
6103
|
}
|
|
6071
6104
|
if (!behaviorOverwritten) {
|
|
@@ -6089,11 +6122,11 @@ function performEvent({
|
|
|
6089
6122
|
schema: schema2
|
|
6090
6123
|
},
|
|
6091
6124
|
action: defaultAction
|
|
6092
|
-
});
|
|
6125
|
+
}), editor.onChange();
|
|
6093
6126
|
} catch (error) {
|
|
6094
6127
|
console.error(new Error(`Performing action "${defaultAction.type}" as a result of "${event.type}" failed due to: ${error.message}`));
|
|
6095
6128
|
}
|
|
6096
|
-
})
|
|
6129
|
+
});
|
|
6097
6130
|
}
|
|
6098
6131
|
}
|
|
6099
6132
|
function slateChildrenToBlocks(schema2, value) {
|
|
@@ -6243,7 +6276,8 @@ const editorMachine = xstate.setup({
|
|
|
6243
6276
|
self
|
|
6244
6277
|
}) => {
|
|
6245
6278
|
xstate.assertEvent(event, ["behavior event"]), performEvent({
|
|
6246
|
-
|
|
6279
|
+
mode: "raise",
|
|
6280
|
+
behaviors: [...context.behaviors.values()],
|
|
6247
6281
|
event: event.behaviorEvent,
|
|
6248
6282
|
editor: event.editor,
|
|
6249
6283
|
keyGenerator: context.keyGenerator,
|
|
@@ -6277,7 +6311,7 @@ const editorMachine = xstate.setup({
|
|
|
6277
6311
|
selection: null,
|
|
6278
6312
|
initialReadOnly: input.readOnly ?? !1,
|
|
6279
6313
|
maxBlocks: input.maxBlocks,
|
|
6280
|
-
|
|
6314
|
+
incomingValue: input.initialValue
|
|
6281
6315
|
}),
|
|
6282
6316
|
on: {
|
|
6283
6317
|
"notify.blurred": {
|
|
@@ -6376,7 +6410,7 @@ const editorMachine = xstate.setup({
|
|
|
6376
6410
|
},
|
|
6377
6411
|
"update value": {
|
|
6378
6412
|
actions: xstate.assign({
|
|
6379
|
-
|
|
6413
|
+
incomingValue: ({
|
|
6380
6414
|
event
|
|
6381
6415
|
}) => event.value
|
|
6382
6416
|
})
|
|
@@ -6985,7 +7019,7 @@ function editorConfigToMachineInput(config) {
|
|
|
6985
7019
|
maxBlocks: config.maxBlocks,
|
|
6986
7020
|
readOnly: config.readOnly,
|
|
6987
7021
|
schema: config.schemaDefinition ? compileSchemaDefinition(config.schemaDefinition) : createEditorSchema(config.schema.hasOwnProperty("jsonType") ? config.schema : compileType(config.schema)),
|
|
6988
|
-
|
|
7022
|
+
initialValue: config.initialValue
|
|
6989
7023
|
};
|
|
6990
7024
|
}
|
|
6991
7025
|
function createInternalEditorFromActor(editorActor) {
|