Skip to content

Commit d642c20

Browse files
committed
fix: handle function values in editor.setOption
1 parent 2008999 commit d642c20

File tree

4 files changed

+58
-60
lines changed

4 files changed

+58
-60
lines changed

.changeset/core-fix-set-option.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@platejs/core': patch
3+
---
4+
5+
- Fixed `editor.setOption` to properly handle function values

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
"slate-react": "0.117.4",
7676
"use-deep-compare": "^1.3.0",
7777
"zustand": "^5.0.5",
78-
"zustand-x": "6.2.0"
78+
"zustand-x": "6.2.1"
7979
},
8080
"peerDependencies": {
8181
"react": ">=18.0.0",

packages/core/src/lib/editor/withSlate.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ export const withSlate = <
272272

273273
return (store.get as any)(key, ...args);
274274
};
275-
editor.setOption = (plugin: any, key: any, value: any) => {
275+
editor.setOption = (plugin: any, key: any, ...args: any) => {
276276
const store = editor.getOptionsStore(plugin);
277277

278278
if (!store) return;
@@ -285,14 +285,7 @@ export const withSlate = <
285285
return;
286286
}
287287

288-
if (typeof value === 'function') {
289-
store.set('state', (draft: any) => {
290-
draft[key] = value;
291-
});
292-
return;
293-
}
294-
295-
store.set(key as any, value);
288+
(store.set as any)(key, ...args);
296289
};
297290
editor.setOptions = (plugin: any, options: any) => {
298291
const store = editor.getOptionsStore(plugin);

0 commit comments

Comments
 (0)