@portabletext/editor 1.26.3 → 1.27.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.
Files changed (45) hide show
  1. package/lib/_chunks-cjs/behavior.markdown.cjs +327 -0
  2. package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -0
  3. package/lib/_chunks-cjs/plugin.event-listener.cjs +6568 -0
  4. package/lib/_chunks-cjs/plugin.event-listener.cjs.map +1 -0
  5. package/lib/_chunks-es/behavior.markdown.js +332 -0
  6. package/lib/_chunks-es/behavior.markdown.js.map +1 -0
  7. package/lib/_chunks-es/plugin.event-listener.js +6592 -0
  8. package/lib/_chunks-es/plugin.event-listener.js.map +1 -0
  9. package/lib/behaviors/index.cjs +2 -325
  10. package/lib/behaviors/index.cjs.map +1 -1
  11. package/lib/behaviors/index.d.cts +1 -1
  12. package/lib/behaviors/index.d.ts +1 -1
  13. package/lib/behaviors/index.js +2 -326
  14. package/lib/behaviors/index.js.map +1 -1
  15. package/lib/index.cjs +181 -6703
  16. package/lib/index.cjs.map +1 -1
  17. package/lib/index.d.cts +3240 -2149
  18. package/lib/index.d.ts +3240 -2149
  19. package/lib/index.js +143 -6682
  20. package/lib/index.js.map +1 -1
  21. package/lib/plugins/index.cjs +29 -0
  22. package/lib/plugins/index.cjs.map +1 -0
  23. package/lib/plugins/index.d.cts +19411 -0
  24. package/lib/plugins/index.d.ts +19411 -0
  25. package/lib/plugins/index.js +29 -0
  26. package/lib/plugins/index.js.map +1 -0
  27. package/lib/selectors/index.d.cts +1 -1
  28. package/lib/selectors/index.d.ts +1 -1
  29. package/package.json +12 -6
  30. package/src/editor/Editable.tsx +6 -6
  31. package/src/editor/__tests__/PortableTextEditor.test.tsx +0 -1
  32. package/src/editor/components/Synchronizer.tsx +16 -1
  33. package/src/editor/create-editor.ts +8 -48
  34. package/src/editor/editor-machine.ts +118 -131
  35. package/src/editor/plugins/create-with-event-listeners.ts +19 -38
  36. package/src/editor/plugins/createWithPatches.ts +1 -1
  37. package/src/editor/plugins/createWithPortableTextSelections.ts +2 -2
  38. package/src/editor/sync-machine.ts +3 -5
  39. package/src/index.ts +5 -11
  40. package/src/plugins/_exports/index.ts +1 -0
  41. package/src/plugins/index.ts +3 -0
  42. package/src/plugins/plugin.editor-ref.tsx +17 -0
  43. package/src/{editor/editor-event-listener.tsx → plugins/plugin.event-listener.tsx} +7 -6
  44. package/src/plugins/plugin.markdown.tsx +70 -0
  45. package/src/type-utils.ts +12 -2
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: !0 });
3
+ var plugin_eventListener = require("../_chunks-cjs/plugin.event-listener.cjs"), reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), behavior_markdown = require("../_chunks-cjs/behavior.markdown.cjs");
4
+ function _interopDefaultCompat(e) {
5
+ return e && typeof e == "object" && "default" in e ? e : { default: e };
6
+ }
7
+ var React__default = /* @__PURE__ */ _interopDefaultCompat(React);
8
+ const EditorRefPlugin = React__default.default.forwardRef((_, ref) => {
9
+ const $ = reactCompilerRuntime.c(2), editor = plugin_eventListener.useEditor(), portableTextEditorRef = React__default.default.useRef(editor);
10
+ let t0, t1;
11
+ return $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = () => portableTextEditorRef.current, t1 = [], $[0] = t0, $[1] = t1) : (t0 = $[0], t1 = $[1]), React__default.default.useImperativeHandle(ref, t0, t1), null;
12
+ });
13
+ EditorRefPlugin.displayName = "EditorRefPlugin";
14
+ function MarkdownPlugin(props) {
15
+ const editor = plugin_eventListener.useEditor();
16
+ return React.useEffect(() => {
17
+ const unregisterBehaviors = behavior_markdown.createMarkdownBehaviors(props.config).map((behavior) => editor.registerBehavior({
18
+ behavior
19
+ }));
20
+ return () => {
21
+ for (const unregisterBehavior of unregisterBehaviors)
22
+ unregisterBehavior();
23
+ };
24
+ }, [editor, props.config]), null;
25
+ }
26
+ exports.EventListenerPlugin = plugin_eventListener.EventListenerPlugin;
27
+ exports.EditorRefPlugin = EditorRefPlugin;
28
+ exports.MarkdownPlugin = MarkdownPlugin;
29
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../../src/plugins/plugin.editor-ref.tsx","../../src/plugins/plugin.markdown.tsx"],"sourcesContent":["import React from 'react'\nimport type {Editor} from '../editor/create-editor'\nimport {useEditor} from '../editor/editor-provider'\n\n/**\n * @beta\n */\nexport const EditorRefPlugin = React.forwardRef<Editor | null>((_, ref) => {\n const editor = useEditor()\n\n const portableTextEditorRef = React.useRef(editor)\n\n React.useImperativeHandle(ref, () => portableTextEditorRef.current, [])\n\n return null\n})\nEditorRefPlugin.displayName = 'EditorRefPlugin'\n","import {useEffect} from 'react'\nimport {\n createMarkdownBehaviors,\n type MarkdownBehaviorsConfig,\n} from '../behaviors/behavior.markdown'\nimport {useEditor} from '../editor/editor-provider'\n\n/**\n * @beta\n */\nexport type MarkdownPluginConfig = MarkdownBehaviorsConfig\n\n/**\n * @beta\n * Add markdown behaviors for common markdown actions such as converting ### to headings, --- to HRs, and more.\n *\n * @example\n * Configure the bundled markdown behaviors\n * ```ts\n * import {EditorProvider} from '@portabletext/editor'\n * import {MarkdownPlugin} from '@portabletext/editor/plugins'\n *\n * function App() {\n * return (\n * <EditorProvider>\n * <MarkdownPlugin\n * config={{\n * horizontalRuleObject: ({schema}) => {\n * const name = schema.blockObjects.find(\n * (object) => object.name === 'break',\n * )?.name\n * return name ? {name} : undefined\n * },\n * defaultStyle: ({schema}) => schema.styles[0].value,\n * headingStyle: ({schema, level}) =>\n * schema.styles.find((style) => style.value === `h${level}`)\n * ?.value,\n * blockquoteStyle: ({schema}) =>\n * schema.styles.find((style) => style.value === 'blockquote')\n * ?.value,\n * unorderedListStyle: ({schema}) =>\n * schema.lists.find((list) => list.value === 'bullet')?.value,\n * orderedListStyle: ({schema}) =>\n * schema.lists.find((list) => list.value === 'number')?.value,\n * }}\n * />\n * {...}\n * </EditorProvider>\n * )\n * }\n */\nexport function MarkdownPlugin(props: {config: MarkdownPluginConfig}) {\n const editor = useEditor()\n\n useEffect(() => {\n const behaviors = createMarkdownBehaviors(props.config)\n\n const unregisterBehaviors = behaviors.map((behavior) =>\n editor.registerBehavior({behavior}),\n )\n\n return () => {\n for (const unregisterBehavior of unregisterBehaviors) {\n unregisterBehavior()\n }\n }\n }, [editor, props.config])\n\n return null\n}\n"],"names":["EditorRefPlugin","React","forwardRef","_","ref","$","_c","editor","useEditor","portableTextEditorRef","useRef","t0","t1","Symbol","for","current","useImperativeHandle","displayName","MarkdownPlugin","props","useEffect","unregisterBehaviors","createMarkdownBehaviors","config","map","behavior","registerBehavior","unregisterBehavior"],"mappings":";;;;;;;AAOO,MAAMA,kBAAkBC,eAAAA,QAAMC,WAA0B,CAAAC,GAAAC,QAAA;AAAAC,QAAAA,IAAAC,qBAAAA,EAAA,CAAA,GAC7DC,SAAeC,+BAEfC,GAAAA,wBAA8BR,eAAAA,QAAAS,OAAaH,MAAM;AAAC,MAAAI,IAAAC;AAAA,SAAAP,EAAA,CAAA,MAAAQ,OAAAC,IAAA,2BAAA,KAEnBH,KAAAA,MAAMF,sBAAqBM,SAAUH,KAAA,CAAA,GAAEP,OAAAM,IAAAN,OAAAO,OAAAD,KAAAN,EAAA,CAAA,GAAAO,KAAAP,EAAA,CAAA,IAAtEJ,eAAAe,QAAAA,oBAA0BZ,KAAKO,IAAqCC,EAAE,GAAC;AAAA,CAGxE;AACDZ,gBAAgBiB,cAAc;ACmCvB,SAASC,eAAeC,OAAuC;AACpE,QAAMZ,SAASC,qBAAAA,UAAU;AAEzBY,SAAAA,MAAAA,UAAU,MAAM;AAGRC,UAAAA,sBAFYC,0CAAwBH,MAAMI,MAAM,EAEhBC,IAAKC,CAAAA,aACzClB,OAAOmB,iBAAiB;AAAA,MAACD;AAAAA,IAAAA,CAAS,CACpC;AAEA,WAAO,MAAM;AACX,iBAAWE,sBAAsBN;AACZ,2BAAA;AAAA,IAEvB;AAAA,KACC,CAACd,QAAQY,MAAMI,MAAM,CAAC,GAElB;AACT;;;;"}