@lofcz/platejs-utils 53.0.0 → 53.1.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/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _platejs_core0 from "@platejs/core";
2
- import { InsertExitBreakOptions, OverrideEditor, PluginConfig } from "@platejs/core";
2
+ import { InsertExitBreakOptions, OverrideEditor, PluginConfig, SlateEditor } from "@platejs/core";
3
3
  import { Descendant, Path, QueryNodeOptions, TElement, TText } from "@platejs/slate";
4
4
  import { UnknownObject } from "@udecode/utils";
5
5
 
@@ -510,7 +510,19 @@ declare const SingleBlockPlugin: _platejs_core0.SlatePlugin<_platejs_core0.Plugi
510
510
  declare const SingleLinePlugin: _platejs_core0.SlatePlugin<_platejs_core0.PluginConfig<"singleLine", {}, {}, {}, {}>>;
511
511
  //#endregion
512
512
  //#region src/lib/plugins/trailing-block/TrailingBlockPlugin.d.ts
513
+ type TrailingBlockInsertOptions = {
514
+ at: Path;
515
+ insert: () => void;
516
+ type: string;
517
+ };
513
518
  type TrailingBlockConfig = PluginConfig<'trailingBlock', {
519
+ /**
520
+ * Customize how the trailing block is inserted.
521
+ *
522
+ * Useful when another plugin needs to wrap the insertion, such as
523
+ * disabling suggestions during normalization-generated inserts.
524
+ */
525
+ insert?: (editor: SlateEditor, options: TrailingBlockInsertOptions) => void;
514
526
  /** Level where the trailing node should be, the first level being 0. */
515
527
  level?: number;
516
528
  /** Type of the trailing block */
@@ -520,6 +532,13 @@ type TrailingBlockConfig = PluginConfig<'trailingBlock', {
520
532
  declare const TrailingBlockPlugin: _platejs_core0.SlatePlugin<PluginConfig<"trailingBlock", {
521
533
  type: string;
522
534
  } & {
535
+ /**
536
+ * Customize how the trailing block is inserted.
537
+ *
538
+ * Useful when another plugin needs to wrap the insertion, such as
539
+ * disabling suggestions during normalization-generated inserts.
540
+ */
541
+ insert?: (editor: SlateEditor, options: TrailingBlockInsertOptions) => void;
523
542
  /** Level where the trailing node should be, the first level being 0. */
524
543
  level?: number;
525
544
  /** Type of the trailing block */
@@ -533,4 +552,4 @@ declare const TrailingBlockPlugin: _platejs_core0.SlatePlugin<PluginConfig<"trai
533
552
  */
534
553
  declare const withTrailingBlock: OverrideEditor<TrailingBlockConfig>;
535
554
  //#endregion
536
- export { EmptyText, ExitBreakPlugin, KEYS, NODES, NodeKey, NormalizeTypesConfig, NormalizeTypesPlugin, PlainText, PlateKey, STYLE_KEYS, SingleBlockPlugin, SingleLinePlugin, StyleKey, TAudioElement, TBasicMarks, TCalloutElement, TCaptionElement, TCaptionProps, TCodeBlockElement, TCodeSyntaxLeaf, TColumnElement, TColumnGroupElement, TComboboxInputElement, TCommentText, TDateElement, TEquationElement, TFileElement, TFontMarks, TIdElement, TIdProps, TImageElement, TIndentElement, TIndentProps, TInlineSuggestionData, TInsertSuggestionData, TLineHeightProps, TLinkElement, TListElement, TListProps, TMediaElement, TMediaEmbedElement, TMediaProps, TMentionElement, TNodeMap, TPlaceholderElement, TRemoveSuggestionData, TResizableElement, TResizableProps, TSuggestionData, TSuggestionElement, TSuggestionProps, TSuggestionText, TTableCellBorder, TTableCellElement, TTableElement, TTableRowElement, TTagElement, TTagProps, TTextAlignProps, TUpdateSuggestionData, TVideoElement, TrailingBlockConfig, TrailingBlockPlugin, withNormalizeTypes, withTrailingBlock };
555
+ export { EmptyText, ExitBreakPlugin, KEYS, NODES, NodeKey, NormalizeTypesConfig, NormalizeTypesPlugin, PlainText, PlateKey, STYLE_KEYS, SingleBlockPlugin, SingleLinePlugin, StyleKey, TAudioElement, TBasicMarks, TCalloutElement, TCaptionElement, TCaptionProps, TCodeBlockElement, TCodeSyntaxLeaf, TColumnElement, TColumnGroupElement, TComboboxInputElement, TCommentText, TDateElement, TEquationElement, TFileElement, TFontMarks, TIdElement, TIdProps, TImageElement, TIndentElement, TIndentProps, TInlineSuggestionData, TInsertSuggestionData, TLineHeightProps, TLinkElement, TListElement, TListProps, TMediaElement, TMediaEmbedElement, TMediaProps, TMentionElement, TNodeMap, TPlaceholderElement, TRemoveSuggestionData, TResizableElement, TResizableProps, TSuggestionData, TSuggestionElement, TSuggestionProps, TSuggestionText, TTableCellBorder, TTableCellElement, TTableElement, TTableRowElement, TTagElement, TTagProps, TTextAlignProps, TUpdateSuggestionData, TVideoElement, TrailingBlockConfig, TrailingBlockInsertOptions, TrailingBlockPlugin, withNormalizeTypes, withTrailingBlock };
package/dist/index.js CHANGED
@@ -117,13 +117,22 @@ const SingleLinePlugin = createSlatePlugin({
117
117
  * editor has .
118
118
  */
119
119
  const withTrailingBlock = ({ editor, getOptions, tf: { normalizeNode } }) => ({ transforms: { normalizeNode([currentNode, currentPath]) {
120
- const { level, type, ...query } = getOptions();
120
+ const { insert, level, type, ...query } = getOptions();
121
+ const trailingType = type ?? editor.getType(KEYS.p);
121
122
  if (currentPath.length === 0) {
122
123
  const lastChild = editor.api.last([], { level });
123
124
  const lastChildNode = lastChild?.[0];
124
- if (!lastChildNode || lastChildNode.type !== type && queryNode(lastChild, query)) {
125
+ if (!lastChildNode || lastChildNode.type !== trailingType && queryNode(lastChild, query)) {
125
126
  const at = lastChild ? PathApi.next(lastChild[1]) : [0];
126
- editor.tf.insertNodes(editor.api.create.block({ type }, at), { at });
127
+ const insertTrailingBlock = () => {
128
+ editor.tf.insertNodes(editor.api.create.block({ type: trailingType }, at), { at });
129
+ };
130
+ if (insert) insert(editor, {
131
+ at,
132
+ insert: insertTrailingBlock,
133
+ type: trailingType
134
+ });
135
+ else insertTrailingBlock();
127
136
  return;
128
137
  }
129
138
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lofcz/platejs-utils",
3
- "version": "53.0.0",
3
+ "version": "53.1.1",
4
4
  "description": "Plate utils",
5
5
  "keywords": [
6
6
  "plate",
@@ -32,8 +32,8 @@
32
32
  "clsx": "^2.1.1",
33
33
  "lodash": "^4.17.21",
34
34
  "react-compiler-runtime": "^1.0.0",
35
- "@platejs/core": "npm:@lofcz/platejs-core@53.0.0",
36
- "@platejs/slate": "npm:@lofcz/platejs-slate@53.0.0",
35
+ "@platejs/core": "npm:@lofcz/platejs-core@53.1.1",
36
+ "@platejs/slate": "npm:@lofcz/platejs-slate@53.1.1",
37
37
  "@udecode/react-utils": "npm:@lofcz/udecode-react-utils@52.3.4",
38
38
  "@udecode/utils": "npm:@lofcz/udecode-utils@52.3.4"
39
39
  },