@portabletext/editor 1.26.3 → 1.28.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/README.md +5 -5
- package/lib/_chunks-cjs/behavior.markdown.cjs +327 -0
- package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -0
- package/lib/_chunks-cjs/plugin.event-listener.cjs +6827 -0
- package/lib/_chunks-cjs/plugin.event-listener.cjs.map +1 -0
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs +88 -88
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +1 -1
- package/lib/_chunks-es/behavior.markdown.js +332 -0
- package/lib/_chunks-es/behavior.markdown.js.map +1 -0
- package/lib/_chunks-es/plugin.event-listener.js +6851 -0
- package/lib/_chunks-es/plugin.event-listener.js.map +1 -0
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js +88 -88
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -1
- package/lib/behaviors/index.cjs +2 -325
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +1 -1
- package/lib/behaviors/index.d.ts +1 -1
- package/lib/behaviors/index.js +2 -326
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.cjs +261 -6782
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +3509 -2161
- package/lib/index.d.ts +3509 -2161
- package/lib/index.js +223 -6761
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs +29 -0
- package/lib/plugins/index.cjs.map +1 -0
- package/lib/plugins/index.d.cts +19411 -0
- package/lib/plugins/index.d.ts +19411 -0
- package/lib/plugins/index.js +29 -0
- package/lib/plugins/index.js.map +1 -0
- package/lib/selectors/index.cjs +15 -3
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +19 -1
- package/lib/selectors/index.d.ts +19 -1
- package/lib/selectors/index.js +17 -4
- package/lib/selectors/index.js.map +1 -1
- package/package.json +14 -8
- package/src/behavior-actions/behavior.action.insert-break.ts +93 -83
- package/src/editor/Editable.tsx +6 -6
- package/src/editor/PortableTextEditor.tsx +288 -1
- package/src/editor/__tests__/PortableTextEditor.test.tsx +0 -1
- package/src/editor/components/DefaultObject.tsx +21 -0
- package/src/editor/components/Element.tsx +5 -5
- package/src/editor/components/Leaf.tsx +1 -6
- package/src/editor/components/Synchronizer.tsx +16 -1
- package/src/editor/create-editor.ts +8 -48
- package/src/editor/editor-machine.ts +118 -131
- package/src/editor/plugins/create-with-event-listeners.ts +19 -38
- package/src/editor/plugins/createWithPatches.ts +1 -1
- package/src/editor/plugins/createWithPortableTextSelections.ts +2 -2
- package/src/editor/sync-machine.ts +3 -5
- package/src/index.ts +5 -11
- package/src/plugins/_exports/index.ts +1 -0
- package/src/plugins/index.ts +3 -0
- package/src/plugins/plugin.editor-ref.tsx +17 -0
- package/src/{editor/editor-event-listener.tsx → plugins/plugin.event-listener.tsx} +7 -6
- package/src/plugins/plugin.markdown.tsx +70 -0
- package/src/selectors/index.ts +4 -2
- package/src/selectors/selector.get-active-annotations.test.ts +122 -0
- package/src/selectors/selector.get-active-annotations.ts +30 -0
- package/src/selectors/selector.get-selection.ts +8 -0
- package/src/selectors/selector.get-value.ts +11 -0
- package/src/type-utils.ts +12 -2
- package/src/editor/nodes/DefaultAnnotation.tsx +0 -20
- package/src/editor/nodes/DefaultObject.tsx +0 -18
|
@@ -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;;;;"}
|