@contentful/field-editor-rich-text 3.3.5 → 3.4.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/CHANGELOG.md +12 -0
- package/dist/ContentfulEditorProvider.d.ts +3 -3
- package/dist/field-editor-rich-text.cjs.development.js +803 -468
- package/dist/field-editor-rich-text.cjs.development.js.map +1 -1
- package/dist/field-editor-rich-text.cjs.production.min.js +1 -1
- package/dist/field-editor-rich-text.cjs.production.min.js.map +1 -1
- package/dist/field-editor-rich-text.esm.js +745 -410
- package/dist/field-editor-rich-text.esm.js.map +1 -1
- package/dist/helpers/editor.d.ts +15 -16
- package/dist/helpers/extractNodes.d.ts +2 -3
- package/dist/helpers/sanitizeIncomingSlateDoc.d.ts +1 -1
- package/dist/helpers/transformers.d.ts +6 -7
- package/dist/internal/constants.d.ts +1 -0
- package/dist/internal/hooks.d.ts +1 -0
- package/dist/internal/index.d.ts +4 -0
- package/dist/internal/misc.d.ts +35 -0
- package/dist/internal/queries.d.ts +78 -0
- package/dist/internal/transforms.d.ts +33 -0
- package/dist/internal/types/editor.d.ts +70 -0
- package/dist/internal/types/index.d.ts +2 -0
- package/dist/internal/types/plugins.d.ts +12 -0
- package/dist/plugins/Break/createExitBreakPlugin.d.ts +2 -2
- package/dist/plugins/Break/createResetNodePlugin.d.ts +2 -2
- package/dist/plugins/Break/createSoftBreakPlugin.d.ts +2 -2
- package/dist/plugins/CommandPalette/components/CommandList.d.ts +2 -2
- package/dist/plugins/CommandPalette/components/CommandList.styles.d.ts +1 -0
- package/dist/plugins/CommandPalette/components/CommandPrompt.d.ts +4 -2
- package/dist/plugins/CommandPalette/createCommandPalettePlugin.d.ts +2 -2
- package/dist/plugins/CommandPalette/onKeyDown.d.ts +2 -3
- package/dist/plugins/CommandPalette/useCommands.d.ts +2 -2
- package/dist/plugins/DragAndDrop/index.d.ts +2 -2
- package/dist/plugins/EmbeddedEntityBlock/LinkedEntityBlock.d.ts +1 -1
- package/dist/plugins/EmbeddedEntityBlock/Util.d.ts +2 -1
- package/dist/plugins/EmbeddedEntityBlock/index.d.ts +3 -3
- package/dist/plugins/EmbeddedEntityInline/index.d.ts +2 -2
- package/dist/plugins/Heading/createHeadingPlugin.d.ts +2 -2
- package/dist/plugins/Hr/index.d.ts +3 -3
- package/dist/plugins/Hyperlink/HyperlinkModal.d.ts +2 -3
- package/dist/plugins/Hyperlink/components/EntityHyperlink.d.ts +1 -1
- package/dist/plugins/Hyperlink/components/UrlHyperlink.d.ts +1 -1
- package/dist/plugins/Hyperlink/createHyperlinkPlugin.d.ts +2 -2
- package/dist/plugins/Hyperlink/utils.d.ts +3 -3
- package/dist/plugins/List/createListPlugin.d.ts +2 -2
- package/dist/plugins/List/insertListBreak.d.ts +2 -2
- package/dist/plugins/List/insertListFragment.d.ts +2 -3
- package/dist/plugins/List/onKeyDownList.d.ts +3 -3
- package/dist/plugins/List/transforms/deleteBackwardList.d.ts +2 -2
- package/dist/plugins/List/transforms/insertListItem.d.ts +2 -2
- package/dist/plugins/List/transforms/moveListItemDown.d.ts +3 -8
- package/dist/plugins/List/transforms/moveListItems.d.ts +2 -6
- package/dist/plugins/List/transforms/toggleList.d.ts +2 -2
- package/dist/plugins/List/transforms/unwrapList.d.ts +2 -3
- package/dist/plugins/List/utils.d.ts +8 -9
- package/dist/plugins/List/withList.d.ts +2 -4
- package/dist/plugins/Marks/Bold.d.ts +3 -4
- package/dist/plugins/Marks/Code.d.ts +3 -4
- package/dist/plugins/Marks/Italic.d.ts +3 -4
- package/dist/plugins/Marks/Subscript.d.ts +3 -4
- package/dist/plugins/Marks/Superscript.d.ts +3 -4
- package/dist/plugins/Marks/Underline.d.ts +3 -4
- package/dist/plugins/Marks/helpers.d.ts +3 -5
- package/dist/plugins/Marks/index.d.ts +2 -2
- package/dist/plugins/Normalizer/createNormalizerPlugin.d.ts +2 -2
- package/dist/plugins/Normalizer/types.d.ts +3 -5
- package/dist/plugins/Normalizer/utils.d.ts +0 -3
- package/dist/plugins/Normalizer/withNormalizer.d.ts +2 -2
- package/dist/plugins/Paragraph/Paragraph.d.ts +1 -1
- package/dist/plugins/Paragraph/createParagraphPlugin.d.ts +2 -2
- package/dist/plugins/PasteHTML/createPasteHTMLPlugin.d.ts +2 -2
- package/dist/plugins/Quote/components/Quote.d.ts +1 -1
- package/dist/plugins/Quote/createQuotePlugin.d.ts +2 -2
- package/dist/plugins/Quote/shouldResetQuote.d.ts +1 -1
- package/dist/plugins/Quote/toggleQuote.d.ts +2 -3
- package/dist/plugins/Quote/withQuote.d.ts +2 -3
- package/dist/plugins/SelectOnBackspace/createSelectOnBackspacePlugin.d.ts +2 -2
- package/dist/plugins/Table/actions/addColumn.d.ts +7 -4
- package/dist/plugins/Table/actions/addRow.d.ts +3 -3
- package/dist/plugins/Table/actions/setHeader.d.ts +2 -2
- package/dist/plugins/Table/components/Cell.d.ts +2 -2
- package/dist/plugins/Table/components/HeaderCell.d.ts +2 -2
- package/dist/plugins/Table/createTablePlugin.d.ts +2 -2
- package/dist/plugins/Table/helpers.d.ts +8 -9
- package/dist/plugins/Table/insertTableFragment.d.ts +3 -3
- package/dist/plugins/Table/onKeyDownTable.d.ts +2 -3
- package/dist/plugins/Table/tableTracking.d.ts +2 -2
- package/dist/plugins/Text/createTextPlugin.d.ts +2 -2
- package/dist/plugins/Tracking/createTrackingPlugin.d.ts +2 -2
- package/dist/plugins/Tracking/utils.d.ts +2 -2
- package/dist/plugins/TrailingParagraph/index.d.ts +2 -2
- package/dist/plugins/Voids/createVoidsPlugin.d.ts +2 -2
- package/dist/plugins/Voids/transformVoid.d.ts +2 -3
- package/dist/plugins/index.d.ts +2 -2
- package/dist/prepareDocument.d.ts +5 -6
- package/dist/test-utils/assertOutput.d.ts +2 -2
- package/dist/test-utils/createEditor.d.ts +22 -4
- package/dist/test-utils/jsx.d.ts +1 -1
- package/dist/test-utils/mockPlugin.d.ts +2 -2
- package/dist/test-utils/setEmptyDataAttribute.d.ts +2 -2
- package/package.json +17 -16
- package/dist/types.d.ts +0 -52
|
@@ -9,7 +9,7 @@ var React__default = _interopDefault(React);
|
|
|
9
9
|
var fieldEditorReference = require('@contentful/field-editor-reference');
|
|
10
10
|
var fieldEditorShared = require('@contentful/field-editor-shared');
|
|
11
11
|
var Contentful = require('@contentful/rich-text-types');
|
|
12
|
-
var
|
|
12
|
+
var p = require('@udecode/plate-core');
|
|
13
13
|
var emotion = require('emotion');
|
|
14
14
|
var areEqual = _interopDefault(require('fast-deep-equal'));
|
|
15
15
|
var noop = _interopDefault(require('lodash/noop'));
|
|
@@ -21,12 +21,12 @@ var f36Components = require('@contentful/f36-components');
|
|
|
21
21
|
var f36Utils = require('@contentful/f36-utils');
|
|
22
22
|
var constate = _interopDefault(require('constate'));
|
|
23
23
|
var isHotkey = _interopDefault(require('is-hotkey'));
|
|
24
|
-
var
|
|
25
|
-
var Slate = require('slate-react');
|
|
24
|
+
var s = require('slate');
|
|
26
25
|
var find = _interopDefault(require('lodash/find'));
|
|
27
26
|
var flow = _interopDefault(require('lodash/flow'));
|
|
28
27
|
var get = _interopDefault(require('lodash/get'));
|
|
29
28
|
var tokens = _interopDefault(require('@contentful/f36-tokens'));
|
|
29
|
+
var Slate = require('slate-react');
|
|
30
30
|
var f36Icons = require('@contentful/f36-icons');
|
|
31
31
|
var plateList = require('@udecode/plate-list');
|
|
32
32
|
var castArray = _interopDefault(require('lodash/castArray'));
|
|
@@ -273,16 +273,53 @@ function useContentfulEditorId(id) {
|
|
|
273
273
|
|
|
274
274
|
function useContentfulEditor(id) {
|
|
275
275
|
var editorId = useContentfulEditorId(id);
|
|
276
|
-
var editor =
|
|
276
|
+
var editor = p.usePlateEditorState(editorId);
|
|
277
277
|
return editor;
|
|
278
278
|
} // This doesn't re-render when the value changes
|
|
279
279
|
|
|
280
280
|
function useContentfulEditorRef(id) {
|
|
281
281
|
var editorId = useContentfulEditorId(id);
|
|
282
|
-
var editor =
|
|
282
|
+
var editor = p.usePlateEditorRef(editorId);
|
|
283
283
|
return editor;
|
|
284
284
|
}
|
|
285
285
|
|
|
286
|
+
var createPlateEditor = function createPlateEditor(options) {
|
|
287
|
+
if (options === void 0) {
|
|
288
|
+
options = {};
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
return p.createPlateEditor(options);
|
|
292
|
+
};
|
|
293
|
+
var withoutNormalizing = function withoutNormalizing(editor, fn) {
|
|
294
|
+
return p.withoutNormalizing(editor, fn);
|
|
295
|
+
};
|
|
296
|
+
var focusEditor = function focusEditor(editor, target) {
|
|
297
|
+
p.focusEditor(editor, target);
|
|
298
|
+
};
|
|
299
|
+
var blurEditor = function blurEditor(editor) {
|
|
300
|
+
p.blurEditor(editor);
|
|
301
|
+
};
|
|
302
|
+
var selectEditor = function selectEditor(editor, opts) {
|
|
303
|
+
p.selectEditor(editor, opts);
|
|
304
|
+
};
|
|
305
|
+
var fromDOMPoint = function fromDOMPoint(editor, domPoint, opts) {
|
|
306
|
+
if (opts === void 0) {
|
|
307
|
+
opts = {
|
|
308
|
+
exactMatch: false,
|
|
309
|
+
suppressThrow: false
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
return p.toSlatePoint(editor, domPoint, opts);
|
|
314
|
+
};
|
|
315
|
+
var mockPlugin = function mockPlugin(plugin) {
|
|
316
|
+
return p.mockPlugin( // TODO check if there is a way around this ugly casting
|
|
317
|
+
plugin);
|
|
318
|
+
};
|
|
319
|
+
var getPlateSelectors = function getPlateSelectors(id) {
|
|
320
|
+
return p.getPlateSelectors(id);
|
|
321
|
+
};
|
|
322
|
+
|
|
286
323
|
var createSoftBreakPlugin = function createSoftBreakPlugin() {
|
|
287
324
|
return plateBreak.createSoftBreakPlugin({
|
|
288
325
|
then: function then(editor) {
|
|
@@ -472,14 +509,280 @@ var useCommandList = function useCommandList(commandItems, container) {
|
|
|
472
509
|
};
|
|
473
510
|
};
|
|
474
511
|
|
|
512
|
+
/**
|
|
513
|
+
* Get text content at location
|
|
514
|
+
*/
|
|
515
|
+
|
|
516
|
+
var getText = function getText(editor, at) {
|
|
517
|
+
return p.getEditorString(editor, at);
|
|
518
|
+
};
|
|
519
|
+
var isText = function isText(value) {
|
|
520
|
+
return p.isText(value);
|
|
521
|
+
};
|
|
522
|
+
var getEndPoint = function getEndPoint(editor, at) {
|
|
523
|
+
return p.getEndPoint(editor, at);
|
|
524
|
+
};
|
|
525
|
+
var getStartPoint = function getStartPoint(editor, at) {
|
|
526
|
+
return p.getStartPoint(editor, at);
|
|
527
|
+
};
|
|
528
|
+
var isNode = function isNode(value) {
|
|
529
|
+
return p.isNode(value);
|
|
530
|
+
};
|
|
531
|
+
var isSelectionAtBlockEnd = function isSelectionAtBlockEnd(editor, options) {
|
|
532
|
+
return p.isSelectionAtBlockEnd(editor, options);
|
|
533
|
+
};
|
|
534
|
+
var isSelectionAtBlockStart = function isSelectionAtBlockStart(editor, options) {
|
|
535
|
+
return p.isSelectionAtBlockStart(editor, options);
|
|
536
|
+
};
|
|
537
|
+
var getBlockAbove = function getBlockAbove(editor, options) {
|
|
538
|
+
return p.getBlockAbove(editor, options);
|
|
539
|
+
};
|
|
540
|
+
var getNodeEntry = function getNodeEntry(editor, at, options) {
|
|
541
|
+
return p.getNodeEntry(editor, at, options);
|
|
542
|
+
};
|
|
543
|
+
var getNodeEntries = function getNodeEntries(editor, options) {
|
|
544
|
+
return p.getNodeEntries(editor, options);
|
|
545
|
+
}; // TODO: Ancestor may not be the correct type for root
|
|
546
|
+
|
|
547
|
+
var getNodeChildren = function getNodeChildren(root, path, options) {
|
|
548
|
+
return p.getNodeChildren(root, path, options);
|
|
549
|
+
};
|
|
550
|
+
var getParentNode = function getParentNode(editor, at, options) {
|
|
551
|
+
return p.getParentNode(editor, at, options);
|
|
552
|
+
};
|
|
553
|
+
var someNode = function someNode(editor, options) {
|
|
554
|
+
return p.someNode(editor, options);
|
|
555
|
+
};
|
|
556
|
+
var getChildren = function getChildren(entry) {
|
|
557
|
+
// Node.children crashes when given a text node
|
|
558
|
+
if (s.Text.isText(entry[0])) {
|
|
559
|
+
return [];
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
return p.getChildren(entry);
|
|
563
|
+
};
|
|
564
|
+
var isFirstChild = function isFirstChild(path) {
|
|
565
|
+
return p.isFirstChild(path);
|
|
566
|
+
};
|
|
567
|
+
var getDescendantNodeByPath = function getDescendantNodeByPath(root, path) {
|
|
568
|
+
// @ts-expect-error
|
|
569
|
+
return s.Node.get(root, path);
|
|
570
|
+
};
|
|
571
|
+
var isRangeCollapsed = function isRangeCollapsed(range) {
|
|
572
|
+
return p.isCollapsed(range);
|
|
573
|
+
}; // TODO: simplify
|
|
574
|
+
|
|
575
|
+
var isRangeAcrossBlocks = function isRangeAcrossBlocks(editor, options) {
|
|
576
|
+
return p.isRangeAcrossBlocks(editor, options);
|
|
577
|
+
};
|
|
578
|
+
var isRangeExpanded = function isRangeExpanded(range) {
|
|
579
|
+
return p.isExpanded(range);
|
|
580
|
+
};
|
|
581
|
+
var getRange = function getRange(editor, at, to) {
|
|
582
|
+
return p.getRange(editor, at, to);
|
|
583
|
+
};
|
|
584
|
+
var getRangeEdges = function getRangeEdges(range) {
|
|
585
|
+
return s.Range.edges(range);
|
|
586
|
+
};
|
|
587
|
+
var getRangeStart = function getRangeStart(range) {
|
|
588
|
+
return s.Range.start(range);
|
|
589
|
+
};
|
|
590
|
+
var getRangeEnd = function getRangeEnd(range) {
|
|
591
|
+
return s.Range.end(range);
|
|
592
|
+
};
|
|
593
|
+
var getAboveNode = function getAboveNode(editor, opts) {
|
|
594
|
+
return p.getAboveNode(editor, opts);
|
|
595
|
+
};
|
|
596
|
+
var getCommonNode = function getCommonNode(root, path, another) {
|
|
597
|
+
return p.getCommonNode(root, path, another);
|
|
598
|
+
};
|
|
599
|
+
var getNodeTexts = function getNodeTexts(root, opts) {
|
|
600
|
+
return p.getNodeTexts(root, opts);
|
|
601
|
+
};
|
|
602
|
+
var findNode = function findNode(editor, options) {
|
|
603
|
+
return p.findNode(editor, options);
|
|
604
|
+
};
|
|
605
|
+
var isMarkActive = function isMarkActive(editor, type) {
|
|
606
|
+
return p.isMarkActive(editor, type);
|
|
607
|
+
};
|
|
608
|
+
var getMarks = function getMarks(editor) {
|
|
609
|
+
return p.getMarks(editor);
|
|
610
|
+
};
|
|
611
|
+
var isEditor = function isEditor(value) {
|
|
612
|
+
return p.isEditor(value);
|
|
613
|
+
};
|
|
614
|
+
var isEditorReadOnly = function isEditorReadOnly(editor) {
|
|
615
|
+
return p.isEditorReadOnly(editor);
|
|
616
|
+
};
|
|
617
|
+
var isElement = function isElement(value) {
|
|
618
|
+
return p.isElement(value);
|
|
619
|
+
};
|
|
620
|
+
var isBlockNode = function isBlockNode(editor, value) {
|
|
621
|
+
return p.isBlock(editor, value);
|
|
622
|
+
};
|
|
623
|
+
var findNodePath = function findNodePath(editor, node) {
|
|
624
|
+
return p.findNodePath(editor, node);
|
|
625
|
+
};
|
|
626
|
+
var isAncestorPath = function isAncestorPath(path, another) {
|
|
627
|
+
return s.Path.isAncestor(path, another);
|
|
628
|
+
};
|
|
629
|
+
var isAncestorEmpty = function isAncestorEmpty(editor, node) {
|
|
630
|
+
return p.isAncestorEmpty(editor, node);
|
|
631
|
+
};
|
|
632
|
+
var getParentPath = function getParentPath(path) {
|
|
633
|
+
return s.Path.parent(path);
|
|
634
|
+
};
|
|
635
|
+
var getNextPath = function getNextPath(path) {
|
|
636
|
+
return s.Path.next(path);
|
|
637
|
+
};
|
|
638
|
+
var getPreviousPath = function getPreviousPath(path) {
|
|
639
|
+
return s.Path.previous(path);
|
|
640
|
+
};
|
|
641
|
+
var getLastChildPath = function getLastChildPath(nodeEntry) {
|
|
642
|
+
return p.getLastChildPath(nodeEntry);
|
|
643
|
+
};
|
|
644
|
+
var getPathLevels = function getPathLevels(path, options) {
|
|
645
|
+
return s.Path.levels(path, options);
|
|
646
|
+
};
|
|
647
|
+
var isFirstChildPath = function isFirstChildPath(path) {
|
|
648
|
+
return p.isFirstChild(path);
|
|
649
|
+
};
|
|
650
|
+
var isLastChildPath = function isLastChildPath(entry, childPath) {
|
|
651
|
+
return p.isLastChild(entry, childPath);
|
|
652
|
+
};
|
|
653
|
+
var matchNode = function matchNode(node, path, fn) {
|
|
654
|
+
return p.match(node, path, fn);
|
|
655
|
+
};
|
|
656
|
+
var someHtmlElement = function someHtmlElement(rootNode, predicate) {
|
|
657
|
+
return p.someHtmlElement(rootNode, predicate);
|
|
658
|
+
};
|
|
659
|
+
var getPointBefore = function getPointBefore(editor, at, options) {
|
|
660
|
+
return p.getPointBefore(editor, at, options);
|
|
661
|
+
};
|
|
662
|
+
var getPointAfter = function getPointAfter(editor, at, options) {
|
|
663
|
+
return p.getPointAfter(editor, at, options);
|
|
664
|
+
};
|
|
665
|
+
var isEndPoint = function isEndPoint(editor, point, at) {
|
|
666
|
+
return p.isEndPoint(editor, point, at);
|
|
667
|
+
};
|
|
668
|
+
var isInline = function isInline(editor, value) {
|
|
669
|
+
return p.isInline(editor, value);
|
|
670
|
+
};
|
|
671
|
+
var queryNode = function queryNode(entry, options) {
|
|
672
|
+
return p.queryNode(entry, options);
|
|
673
|
+
};
|
|
674
|
+
var getPluginType = function getPluginType(editor, key) {
|
|
675
|
+
return p.getPluginType(editor, key);
|
|
676
|
+
};
|
|
677
|
+
var createPathRef = function createPathRef(editor, at) {
|
|
678
|
+
return p.createPathRef(editor, at);
|
|
679
|
+
};
|
|
680
|
+
var match = function match(obj, path, predicate) {
|
|
681
|
+
return p.match(obj, path, predicate);
|
|
682
|
+
};
|
|
683
|
+
var getLastNodeByLevel = function getLastNodeByLevel(editor, level) {
|
|
684
|
+
return p.getLastNodeByLevel(editor, level);
|
|
685
|
+
};
|
|
686
|
+
|
|
687
|
+
/**
|
|
688
|
+
* Apply editor normalization rules
|
|
689
|
+
*/
|
|
690
|
+
|
|
691
|
+
var normalize = function normalize(editor, options) {
|
|
692
|
+
if (options === void 0) {
|
|
693
|
+
options = {
|
|
694
|
+
force: true
|
|
695
|
+
};
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
return p.normalizeEditor(editor, options);
|
|
699
|
+
};
|
|
700
|
+
/**
|
|
701
|
+
* Set the selection to a location
|
|
702
|
+
*/
|
|
703
|
+
|
|
704
|
+
var setSelection = function setSelection(editor, props) {
|
|
705
|
+
return p.setSelection(editor, props);
|
|
706
|
+
};
|
|
707
|
+
var select = function select(editor, location) {
|
|
708
|
+
return p.select(editor, location);
|
|
709
|
+
};
|
|
710
|
+
var moveSelection = function moveSelection(editor, options) {
|
|
711
|
+
return p.moveSelection(editor, options);
|
|
712
|
+
};
|
|
713
|
+
var moveChildren = function moveChildren(editor, options) {
|
|
714
|
+
return p.moveChildren(editor, options);
|
|
715
|
+
};
|
|
716
|
+
var collapseSelection = function collapseSelection(editor, options) {
|
|
717
|
+
return p.collapseSelection(editor, options);
|
|
718
|
+
};
|
|
719
|
+
var setNodes = function setNodes(editor, attrs, opts) {
|
|
720
|
+
p.setNodes(editor, attrs, opts);
|
|
721
|
+
};
|
|
722
|
+
var unsetNodes = function unsetNodes(editor, props, options) {
|
|
723
|
+
p.unsetNodes(editor, props, options);
|
|
724
|
+
};
|
|
725
|
+
var insertNodes = function insertNodes(editor, nodes, opts) {
|
|
726
|
+
return p.insertNodes(editor, nodes, opts);
|
|
727
|
+
};
|
|
728
|
+
var splitNodes = function splitNodes(editor, options) {
|
|
729
|
+
return p.splitNodes(editor, options);
|
|
730
|
+
};
|
|
731
|
+
var liftNodes = function liftNodes(editor, options) {
|
|
732
|
+
return p.liftNodes(editor, options);
|
|
733
|
+
};
|
|
734
|
+
var unwrapNodes = function unwrapNodes(editor, options) {
|
|
735
|
+
return p.unwrapNodes(editor, options);
|
|
736
|
+
};
|
|
737
|
+
var wrapNodes = function wrapNodes(editor, element, options) {
|
|
738
|
+
return p.wrapNodes(editor, element, options);
|
|
739
|
+
};
|
|
740
|
+
var toggleNodeType = function toggleNodeType(editor, options, editorOptions) {
|
|
741
|
+
p.toggleNodeType(editor, options, editorOptions);
|
|
742
|
+
};
|
|
743
|
+
var removeMark = function removeMark(editor, type, at) {
|
|
744
|
+
p.removeMark(editor, {
|
|
745
|
+
key: type,
|
|
746
|
+
at: at
|
|
747
|
+
});
|
|
748
|
+
};
|
|
749
|
+
var unhangRange = function unhangRange(editor, range, options) {
|
|
750
|
+
return p.unhangRange(editor, range, options);
|
|
751
|
+
};
|
|
752
|
+
var toggleMark = function toggleMark(editor, options) {
|
|
753
|
+
return p.toggleMark(editor, options);
|
|
754
|
+
};
|
|
755
|
+
var addMark = function addMark(editor, type, value) {
|
|
756
|
+
if (value === void 0) {
|
|
757
|
+
value = true;
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
p.addMark(editor, type, value);
|
|
761
|
+
};
|
|
762
|
+
var insertText = function insertText(editor, text, options) {
|
|
763
|
+
return p.insertText(editor, text, options);
|
|
764
|
+
};
|
|
765
|
+
var deleteText = function deleteText(editor, opts) {
|
|
766
|
+
p.deleteText(editor, opts);
|
|
767
|
+
};
|
|
768
|
+
var removeNodes = function removeNodes(editor, opts) {
|
|
769
|
+
p.removeNodes(editor, opts);
|
|
770
|
+
};
|
|
771
|
+
var moveNodes = function moveNodes(editor, opts) {
|
|
772
|
+
p.moveNodes(editor, opts);
|
|
773
|
+
};
|
|
774
|
+
var deleteFragment = function deleteFragment(editor, options) {
|
|
775
|
+
return p.deleteFragment(editor, options);
|
|
776
|
+
};
|
|
777
|
+
|
|
475
778
|
var IS_SAFARI = typeof navigator !== 'undefined' && /*#__PURE__*/ /Version\/[\d.]+.*Safari/.test(navigator.userAgent);
|
|
476
779
|
var IS_CHROME = /*#__PURE__*/ /(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9.]+)(:?\s|$)/.test(navigator.userAgent);
|
|
477
780
|
|
|
478
781
|
var LINK_TYPES = [Contentful.INLINES.HYPERLINK, Contentful.INLINES.ENTRY_HYPERLINK, Contentful.INLINES.ASSET_HYPERLINK];
|
|
479
782
|
function isBlockSelected(editor, type) {
|
|
480
|
-
var _Array$from = Array.from(
|
|
783
|
+
var _Array$from = Array.from(getNodeEntries(editor, {
|
|
481
784
|
match: function match(node) {
|
|
482
|
-
return
|
|
785
|
+
return isElement(node) && node.type === type;
|
|
483
786
|
}
|
|
484
787
|
})),
|
|
485
788
|
match = _Array$from[0];
|
|
@@ -497,7 +800,7 @@ function getNodeEntryFromSelection(editor, nodeTypeOrTypes, path) {
|
|
|
497
800
|
var nodeTypes = Array.isArray(nodeTypeOrTypes) ? nodeTypeOrTypes : [nodeTypeOrTypes];
|
|
498
801
|
|
|
499
802
|
for (var i = 0; i < path.length; i++) {
|
|
500
|
-
var nodeEntry =
|
|
803
|
+
var nodeEntry = getNodeEntry(editor, path.slice(0, i + 1));
|
|
501
804
|
if (nodeTypes.includes(nodeEntry[0].type)) return nodeEntry;
|
|
502
805
|
}
|
|
503
806
|
|
|
@@ -512,13 +815,13 @@ function isNodeTypeSelected(editor, nodeType) {
|
|
|
512
815
|
return !!node;
|
|
513
816
|
}
|
|
514
817
|
function moveToTheNextLine(editor) {
|
|
515
|
-
|
|
818
|
+
moveSelection(editor, {
|
|
516
819
|
distance: 1,
|
|
517
820
|
unit: 'line'
|
|
518
821
|
});
|
|
519
822
|
}
|
|
520
823
|
function moveToTheNextChar(editor) {
|
|
521
|
-
|
|
824
|
+
moveSelection(editor, {
|
|
522
825
|
distance: 1,
|
|
523
826
|
unit: 'offset'
|
|
524
827
|
});
|
|
@@ -532,11 +835,11 @@ function insertEmptyParagraph(editor, options) {
|
|
|
532
835
|
data: {},
|
|
533
836
|
isVoid: false
|
|
534
837
|
};
|
|
535
|
-
|
|
838
|
+
insertNodes(editor, emptyParagraph, options);
|
|
536
839
|
}
|
|
537
840
|
function getElementFromCurrentSelection(editor) {
|
|
538
841
|
if (!editor.selection) return [];
|
|
539
|
-
return Array.from(
|
|
842
|
+
return Array.from(getNodeEntries(editor, {
|
|
540
843
|
/**
|
|
541
844
|
* editor.select is a Range, which includes anchor and focus, the beginning and the end of a selection
|
|
542
845
|
* when using only editor.selection.focus, we might get only the end of the selection, or where the text cursor is
|
|
@@ -544,7 +847,7 @@ function getElementFromCurrentSelection(editor) {
|
|
|
544
847
|
**/
|
|
545
848
|
at: editor.selection,
|
|
546
849
|
match: function match(node) {
|
|
547
|
-
return
|
|
850
|
+
return isElement(node);
|
|
548
851
|
}
|
|
549
852
|
})).flat();
|
|
550
853
|
}
|
|
@@ -573,9 +876,9 @@ function isLinkActive(editor) {
|
|
|
573
876
|
return false;
|
|
574
877
|
}
|
|
575
878
|
|
|
576
|
-
var _Array$from2 = Array.from(
|
|
879
|
+
var _Array$from2 = Array.from(getNodeEntries(editor, {
|
|
577
880
|
match: function match(node) {
|
|
578
|
-
return !
|
|
881
|
+
return !isEditor(node) && isElement(node) && LINK_TYPES.includes(node.type);
|
|
579
882
|
}
|
|
580
883
|
})),
|
|
581
884
|
link = _Array$from2[0];
|
|
@@ -584,9 +887,9 @@ function isLinkActive(editor) {
|
|
|
584
887
|
} // TODO: move to hyperlink plugin
|
|
585
888
|
|
|
586
889
|
function unwrapLink(editor) {
|
|
587
|
-
|
|
890
|
+
unwrapNodes(editor, {
|
|
588
891
|
match: function match(node) {
|
|
589
|
-
return !
|
|
892
|
+
return !isEditor(node) && isElement(node) && LINK_TYPES.includes(node.type);
|
|
590
893
|
}
|
|
591
894
|
});
|
|
592
895
|
} // TODO: move to hyperlink plugin
|
|
@@ -603,7 +906,7 @@ function wrapLink(editor, _ref) {
|
|
|
603
906
|
}
|
|
604
907
|
|
|
605
908
|
var selection = editor.selection;
|
|
606
|
-
var isCollapsed = selection &&
|
|
909
|
+
var isCollapsed = selection && isRangeCollapsed(selection);
|
|
607
910
|
var link = {
|
|
608
911
|
type: type,
|
|
609
912
|
data: {},
|
|
@@ -626,41 +929,41 @@ function wrapLink(editor, _ref) {
|
|
|
626
929
|
|
|
627
930
|
|
|
628
931
|
if (path) {
|
|
629
|
-
|
|
932
|
+
setNodes(editor, link, {
|
|
630
933
|
at: path
|
|
631
934
|
});
|
|
632
|
-
|
|
935
|
+
insertText(editor, text, {
|
|
633
936
|
at: path
|
|
634
937
|
});
|
|
635
|
-
|
|
938
|
+
select(editor, path);
|
|
636
939
|
} else if (isCollapsed) {
|
|
637
|
-
|
|
940
|
+
insertNodes(editor, link);
|
|
638
941
|
} else {
|
|
639
|
-
|
|
942
|
+
wrapNodes(editor, link, {
|
|
640
943
|
split: true
|
|
641
944
|
});
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
945
|
+
deleteText(editor);
|
|
946
|
+
insertText(editor, text);
|
|
947
|
+
collapseSelection(editor, {
|
|
645
948
|
edge: 'end'
|
|
646
949
|
});
|
|
647
950
|
}
|
|
648
951
|
}
|
|
649
952
|
function getAncestorPathFromSelection(editor) {
|
|
650
953
|
if (!editor.selection) return undefined;
|
|
651
|
-
return
|
|
954
|
+
return getPathLevels(editor.selection.focus.path).find(function (level) {
|
|
652
955
|
return level.length === 1;
|
|
653
956
|
});
|
|
654
957
|
}
|
|
655
958
|
var INLINE_TYPES = /*#__PURE__*/Object.values(Contentful.INLINES);
|
|
656
959
|
var isInlineOrText = function isInlineOrText(node) {
|
|
657
960
|
// either text or inline elements
|
|
658
|
-
return
|
|
961
|
+
return isText(node) || isElement(node) && INLINE_TYPES.includes(node.type);
|
|
659
962
|
};
|
|
660
963
|
var focus = function focus(editor) {
|
|
661
964
|
var x = window.scrollX;
|
|
662
965
|
var y = window.scrollY;
|
|
663
|
-
|
|
966
|
+
focusEditor(editor); // Safari has issues with `editor.focus({ preventScroll: true })`, it ignores the option `preventScroll`
|
|
664
967
|
|
|
665
968
|
if (IS_SAFARI) {
|
|
666
969
|
setTimeout(function () {
|
|
@@ -669,9 +972,9 @@ var focus = function focus(editor) {
|
|
|
669
972
|
}
|
|
670
973
|
};
|
|
671
974
|
function toggleElement(editor, options, editorOptions) {
|
|
672
|
-
|
|
975
|
+
toggleNodeType(editor, options, editorOptions); // We must reset `data` from one element to another
|
|
673
976
|
|
|
674
|
-
|
|
977
|
+
setNodes(editor, {
|
|
675
978
|
data: {}
|
|
676
979
|
});
|
|
677
980
|
}
|
|
@@ -1577,38 +1880,35 @@ var createNode = function createNode(nodeType, entity) {
|
|
|
1577
1880
|
function insertBlock(editor, nodeType, entity) {
|
|
1578
1881
|
if (!(editor != null && editor.selection)) return;
|
|
1579
1882
|
var linkedEntityBlock = createNode(nodeType, entity);
|
|
1580
|
-
var hasText = editor.selection && !!
|
|
1883
|
+
var hasText = editor.selection && !!getText(editor, editor.selection.focus.path);
|
|
1581
1884
|
|
|
1582
1885
|
if (hasText) {
|
|
1583
|
-
|
|
1886
|
+
insertNodes(editor, linkedEntityBlock);
|
|
1584
1887
|
} else {
|
|
1585
|
-
|
|
1888
|
+
setNodes(editor, linkedEntityBlock);
|
|
1586
1889
|
}
|
|
1587
1890
|
|
|
1588
1891
|
focus(editor);
|
|
1589
1892
|
}
|
|
1590
1893
|
|
|
1591
1894
|
var removeCommand = function removeCommand(editor) {
|
|
1592
|
-
var
|
|
1593
|
-
path =
|
|
1895
|
+
var _getAboveNode = getAboveNode(editor),
|
|
1896
|
+
path = _getAboveNode[1];
|
|
1594
1897
|
|
|
1595
|
-
var range =
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
at: range
|
|
1600
|
-
});
|
|
1601
|
-
slate.Transforms["delete"](editor);
|
|
1898
|
+
var range = getRange(editor, path);
|
|
1899
|
+
select(editor, range.focus.path);
|
|
1900
|
+
removeMark(editor, COMMAND_PROMPT, range);
|
|
1901
|
+
deleteText(editor);
|
|
1602
1902
|
};
|
|
1603
1903
|
|
|
1604
1904
|
var removeQuery = function removeQuery(editor) {
|
|
1605
|
-
var
|
|
1606
|
-
path =
|
|
1905
|
+
var _getAboveNode2 = getAboveNode(editor),
|
|
1906
|
+
path = _getAboveNode2[1];
|
|
1607
1907
|
|
|
1608
|
-
var range =
|
|
1908
|
+
var range = getRange(editor, path);
|
|
1609
1909
|
|
|
1610
1910
|
if (range.focus.offset - range.anchor.offset > 1) {
|
|
1611
|
-
|
|
1911
|
+
deleteText(editor, {
|
|
1612
1912
|
at: range.focus,
|
|
1613
1913
|
distance: range.focus.offset - 1,
|
|
1614
1914
|
reverse: true
|
|
@@ -1649,7 +1949,7 @@ var useCommands = function useCommands(sdk, query, editor) {
|
|
|
1649
1949
|
var selection = editor.selection;
|
|
1650
1950
|
editor.insertSoftBreak();
|
|
1651
1951
|
insertBlock(editor, Contentful.BLOCKS.EMBEDDED_ENTRY, entry.entry);
|
|
1652
|
-
|
|
1952
|
+
select(editor, selection);
|
|
1653
1953
|
editor.tracking.onCommandPaletteAction('insert', {
|
|
1654
1954
|
nodeType: Contentful.BLOCKS.EMBEDDED_ENTRY
|
|
1655
1955
|
});
|
|
@@ -1684,7 +1984,7 @@ var useCommands = function useCommands(sdk, query, editor) {
|
|
|
1684
1984
|
callback: function callback() {
|
|
1685
1985
|
var inlineNode = createInlineEntryNode(entry.id);
|
|
1686
1986
|
removeCommand(editor);
|
|
1687
|
-
|
|
1987
|
+
insertNodes(editor, inlineNode);
|
|
1688
1988
|
editor.insertText('');
|
|
1689
1989
|
editor.tracking.onCommandPaletteAction('insert', {
|
|
1690
1990
|
nodeType: Contentful.INLINES.EMBEDDED_ENTRY
|
|
@@ -1733,7 +2033,7 @@ var useCommands = function useCommands(sdk, query, editor) {
|
|
|
1733
2033
|
var selection = editor.selection;
|
|
1734
2034
|
editor.insertSoftBreak();
|
|
1735
2035
|
insertBlock(editor, Contentful.BLOCKS.EMBEDDED_ASSET, asset.entity);
|
|
1736
|
-
|
|
2036
|
+
select(editor, selection);
|
|
1737
2037
|
editor.tracking.onCommandPaletteAction('insert', {
|
|
1738
2038
|
nodeType: Contentful.BLOCKS.EMBEDDED_ASSET
|
|
1739
2039
|
});
|
|
@@ -1787,6 +2087,9 @@ var styles = {
|
|
|
1787
2087
|
marginLeft: 0
|
|
1788
2088
|
}
|
|
1789
2089
|
}),
|
|
2090
|
+
menuPoper: /*#__PURE__*/emotion.css({
|
|
2091
|
+
zIndex: tokens.zIndexModal
|
|
2092
|
+
}),
|
|
1790
2093
|
menuContent: /*#__PURE__*/emotion.css({
|
|
1791
2094
|
width: '400px',
|
|
1792
2095
|
maxHeight: '300px'
|
|
@@ -1959,6 +2262,7 @@ var CommandList = function CommandList(_ref5) {
|
|
|
1959
2262
|
}, /*#__PURE__*/React.createElement(f36Components.ScreenReaderOnly, null, "Richtext commands. Currently focused item: ", selectedItem, ". Press ", /*#__PURE__*/React.createElement("kbd", null, "enter"), " to select, ", /*#__PURE__*/React.createElement("kbd", null, "arrows"), " to navigate, ", /*#__PURE__*/React.createElement("kbd", null, "escape"), " to close.")), /*#__PURE__*/React.createElement(f36Utils.Portal, null, /*#__PURE__*/React.createElement("div", _extends({
|
|
1960
2263
|
"aria-hidden": true,
|
|
1961
2264
|
ref: popoverContainer,
|
|
2265
|
+
className: styles.menuPoper,
|
|
1962
2266
|
style: popper.styles.popper
|
|
1963
2267
|
}, popper.attributes.popper), /*#__PURE__*/React.createElement(f36Components.Popover, {
|
|
1964
2268
|
isOpen: isOpen,
|
|
@@ -2014,43 +2318,43 @@ var CommandPrompt = function CommandPrompt(props) {
|
|
|
2014
2318
|
var createOnKeyDown = function createOnKeyDown() {
|
|
2015
2319
|
return function (editor) {
|
|
2016
2320
|
return function (event) {
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2321
|
+
// Support for different keyboard layouts:
|
|
2322
|
+
// `isHotKey` uses by default `event.which`, which will never generates a match for all layouts (QWERTY: `/`, QWERTZ: `shift+7`)
|
|
2323
|
+
// with `byKey: true` `isHotKey` uses `event.key` which will return the interpreted key '/'
|
|
2324
|
+
// It would still fail without the the optional `shift?` param, as it first checks the modKeys (`shiftKey` would be true on QWERTZ)
|
|
2325
|
+
if (isHotkey('shift?+/', {
|
|
2326
|
+
byKey: true
|
|
2327
|
+
}, event)) {
|
|
2328
|
+
addMark(editor, COMMAND_PROMPT);
|
|
2021
2329
|
editor.tracking.onCommandPaletteAction('openRichTextCommandPalette');
|
|
2022
2330
|
}
|
|
2023
2331
|
|
|
2024
|
-
var isActive =
|
|
2332
|
+
var isActive = isMarkActive(editor, COMMAND_PROMPT);
|
|
2025
2333
|
|
|
2026
|
-
if (isActive) {
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
} else if (isHotkey('backspace', event)) {
|
|
2030
|
-
var _getAbove = plateCore.getAbove(editor),
|
|
2031
|
-
path = _getAbove[1];
|
|
2334
|
+
if (!isActive) {
|
|
2335
|
+
return;
|
|
2336
|
+
}
|
|
2032
2337
|
|
|
2033
|
-
|
|
2338
|
+
if (isHotkey('enter', event)) {
|
|
2339
|
+
return event.preventDefault();
|
|
2340
|
+
}
|
|
2034
2341
|
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
key: COMMAND_PROMPT,
|
|
2038
|
-
at: range
|
|
2039
|
-
});
|
|
2040
|
-
}
|
|
2041
|
-
} else if (isHotkey('escape', event)) {
|
|
2042
|
-
var _getAbove2 = plateCore.getAbove(editor),
|
|
2043
|
-
_path = _getAbove2[1];
|
|
2342
|
+
var _getAboveNode = getAboveNode(editor),
|
|
2343
|
+
path = _getAboveNode[1];
|
|
2044
2344
|
|
|
2045
|
-
|
|
2345
|
+
var range = getRange(editor, path);
|
|
2046
2346
|
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
editor.tracking.onCommandPaletteAction('cancelRichTextCommandPalette');
|
|
2347
|
+
if (isHotkey('backspace', event)) {
|
|
2348
|
+
// if it is the last character in the command string
|
|
2349
|
+
if (range.focus.offset - range.anchor.offset === 1) {
|
|
2350
|
+
removeMark(editor, COMMAND_PROMPT, range);
|
|
2052
2351
|
}
|
|
2053
2352
|
}
|
|
2353
|
+
|
|
2354
|
+
if (isHotkey('escape', event)) {
|
|
2355
|
+
removeMark(editor, COMMAND_PROMPT, range);
|
|
2356
|
+
editor.tracking.onCommandPaletteAction('cancelRichTextCommandPalette');
|
|
2357
|
+
}
|
|
2054
2358
|
};
|
|
2055
2359
|
};
|
|
2056
2360
|
};
|
|
@@ -2096,9 +2400,9 @@ function createDragAndDropPlugin() {
|
|
|
2096
2400
|
// If true, the next handlers will be skipped.
|
|
2097
2401
|
onDrop: function onDrop(editor) {
|
|
2098
2402
|
return function (event) {
|
|
2099
|
-
var _Array$from = Array.from(
|
|
2403
|
+
var _Array$from = Array.from(getNodeEntries(editor, {
|
|
2100
2404
|
match: function match(node) {
|
|
2101
|
-
return DRAGGABLE_TYPES.includes(node
|
|
2405
|
+
return DRAGGABLE_TYPES.includes(node.type);
|
|
2102
2406
|
}
|
|
2103
2407
|
})),
|
|
2104
2408
|
draggingBlock = _Array$from[0];
|
|
@@ -2142,7 +2446,7 @@ function withLinkTracking(Component) {
|
|
|
2142
2446
|
return function ComponentWithTracking(props) {
|
|
2143
2447
|
var editor = useContentfulEditorRef();
|
|
2144
2448
|
var onEntityFetchComplete = React__default.useCallback(function () {
|
|
2145
|
-
return editor.tracking.onViewportAction('linkRendered');
|
|
2449
|
+
return editor == null ? void 0 : editor.tracking.onViewportAction('linkRendered');
|
|
2146
2450
|
}, [editor]);
|
|
2147
2451
|
return /*#__PURE__*/React__default.createElement(Component, _extends({}, props, {
|
|
2148
2452
|
onEntityFetchComplete: onEntityFetchComplete
|
|
@@ -2312,8 +2616,8 @@ function LinkedEntityBlock(props) {
|
|
|
2312
2616
|
}, [sdk, entityId, entityType]);
|
|
2313
2617
|
var handleRemoveClick = React__default.useCallback(function () {
|
|
2314
2618
|
if (!editor) return;
|
|
2315
|
-
var pathToElement =
|
|
2316
|
-
|
|
2619
|
+
var pathToElement = findNodePath(editor, element);
|
|
2620
|
+
removeNodes(editor, {
|
|
2317
2621
|
at: pathToElement
|
|
2318
2622
|
});
|
|
2319
2623
|
}, [editor, element]);
|
|
@@ -2423,7 +2727,7 @@ function getEntityTypeFromRichTextNode(nodeType) {
|
|
|
2423
2727
|
|
|
2424
2728
|
function selectEntityAndInsert(_x, _x2, _x3, _x4) {
|
|
2425
2729
|
return _selectEntityAndInsert.apply(this, arguments);
|
|
2426
|
-
}
|
|
2730
|
+
} // TODO: incorporate this logic inside the trailingParagraph plugin instead
|
|
2427
2731
|
|
|
2428
2732
|
function _selectEntityAndInsert() {
|
|
2429
2733
|
_selectEntityAndInsert = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(nodeType, sdk, editor, logAction) {
|
|
@@ -2459,7 +2763,7 @@ function _selectEntityAndInsert() {
|
|
|
2459
2763
|
return _context.abrupt("return");
|
|
2460
2764
|
|
|
2461
2765
|
case 12:
|
|
2462
|
-
|
|
2766
|
+
select(editor, selection);
|
|
2463
2767
|
insertBlock$1(editor, nodeType, entity);
|
|
2464
2768
|
ensureFollowingParagraph(editor);
|
|
2465
2769
|
logAction('insert', {
|
|
@@ -2477,37 +2781,25 @@ function _selectEntityAndInsert() {
|
|
|
2477
2781
|
}
|
|
2478
2782
|
|
|
2479
2783
|
function ensureFollowingParagraph(editor) {
|
|
2480
|
-
|
|
2481
|
-
If the new block isn't followed by a sibling paragraph we insert a new empty one
|
|
2482
|
-
*/
|
|
2483
|
-
var next = slate.Editor.next(editor);
|
|
2784
|
+
var _lastNode$0$type;
|
|
2484
2785
|
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
var parent = slate.Editor.above(editor, {
|
|
2490
|
-
voids: false,
|
|
2491
|
-
match: function match(e) {
|
|
2492
|
-
return !slate.Element.isElement(e) || ![Contentful.BLOCKS.EMBEDDED_ASSET, Contentful.BLOCKS.EMBEDDED_ENTRY].includes(e.type);
|
|
2786
|
+
var entityBlock = getAboveNode(editor, {
|
|
2787
|
+
match: {
|
|
2788
|
+
type: [Contentful.BLOCKS.EMBEDDED_ASSET, Contentful.BLOCKS.EMBEDDED_ENTRY]
|
|
2493
2789
|
}
|
|
2494
2790
|
});
|
|
2495
2791
|
|
|
2496
|
-
if (
|
|
2497
|
-
// at level 0, a following paragraph is handled by the tralingParagraph plugin
|
|
2498
|
-
moveToTheNextChar(editor);
|
|
2792
|
+
if (!entityBlock) {
|
|
2499
2793
|
return;
|
|
2500
2794
|
}
|
|
2501
2795
|
|
|
2502
|
-
var
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
}
|
|
2507
|
-
});
|
|
2796
|
+
var level = entityBlock[1].length - 1;
|
|
2797
|
+
var lastNode = getLastNodeByLevel(editor, level);
|
|
2798
|
+
var isTextContainer = Contentful.TEXT_CONTAINERS.includes((_lastNode$0$type = lastNode == null ? void 0 : lastNode[0].type) != null ? _lastNode$0$type : ''); // If the new block isn't followed by a sibling text container (e.g. paragraph)
|
|
2799
|
+
// we insert a new empty one. Level 0 is handled by the trailingParagraph plugin
|
|
2508
2800
|
|
|
2509
|
-
if (
|
|
2510
|
-
|
|
2801
|
+
if (level !== 0 && !isTextContainer) {
|
|
2802
|
+
insertEmptyParagraph(editor);
|
|
2511
2803
|
}
|
|
2512
2804
|
|
|
2513
2805
|
moveToTheNextChar(editor);
|
|
@@ -2536,12 +2828,12 @@ var createNode$1 = function createNode(nodeType, entity) {
|
|
|
2536
2828
|
function insertBlock$1(editor, nodeType, entity) {
|
|
2537
2829
|
if (!(editor != null && editor.selection)) return;
|
|
2538
2830
|
var linkedEntityBlock = createNode$1(nodeType, entity);
|
|
2539
|
-
var hasText = editor.selection && !!
|
|
2831
|
+
var hasText = editor.selection && !!getText(editor, editor.selection.focus.path);
|
|
2540
2832
|
|
|
2541
2833
|
if (hasText) {
|
|
2542
|
-
|
|
2834
|
+
insertNodes(editor, linkedEntityBlock);
|
|
2543
2835
|
} else {
|
|
2544
|
-
|
|
2836
|
+
setNodes(editor, linkedEntityBlock);
|
|
2545
2837
|
}
|
|
2546
2838
|
|
|
2547
2839
|
focus(editor);
|
|
@@ -2566,11 +2858,20 @@ function EmbeddedEntityBlockToolbarIcon(_ref) {
|
|
|
2566
2858
|
switch (_context.prev = _context.next) {
|
|
2567
2859
|
case 0:
|
|
2568
2860
|
event.preventDefault();
|
|
2861
|
+
|
|
2862
|
+
if (editor) {
|
|
2863
|
+
_context.next = 3;
|
|
2864
|
+
break;
|
|
2865
|
+
}
|
|
2866
|
+
|
|
2867
|
+
return _context.abrupt("return");
|
|
2868
|
+
|
|
2869
|
+
case 3:
|
|
2569
2870
|
onClose();
|
|
2570
|
-
_context.next =
|
|
2871
|
+
_context.next = 6;
|
|
2571
2872
|
return selectEntityAndInsert(nodeType, sdk, editor, editor.tracking.onToolbarAction);
|
|
2572
2873
|
|
|
2573
|
-
case
|
|
2874
|
+
case 6:
|
|
2574
2875
|
case "end":
|
|
2575
2876
|
return _context.stop();
|
|
2576
2877
|
}
|
|
@@ -2630,7 +2931,7 @@ function getWithEmbeddedEntityEvents(nodeType, sdk) {
|
|
|
2630
2931
|
|
|
2631
2932
|
if (isDelete || isBackspace) {
|
|
2632
2933
|
event.preventDefault();
|
|
2633
|
-
|
|
2934
|
+
removeNodes(editor, {
|
|
2634
2935
|
at: pathToSelectedElement
|
|
2635
2936
|
});
|
|
2636
2937
|
}
|
|
@@ -2839,8 +3140,8 @@ function EmbeddedEntityInline(props) {
|
|
|
2839
3140
|
|
|
2840
3141
|
function handleRemoveClick() {
|
|
2841
3142
|
if (!editor) return;
|
|
2842
|
-
var pathToElement =
|
|
2843
|
-
|
|
3143
|
+
var pathToElement = findNodePath(editor, props.element);
|
|
3144
|
+
removeNodes(editor, {
|
|
2844
3145
|
at: pathToElement
|
|
2845
3146
|
});
|
|
2846
3147
|
}
|
|
@@ -2909,8 +3210,8 @@ function _selectEntityAndInsert$1() {
|
|
|
2909
3210
|
|
|
2910
3211
|
return _context2.abrupt("return", new Promise(function (resolve) {
|
|
2911
3212
|
setTimeout(function () {
|
|
2912
|
-
|
|
2913
|
-
|
|
3213
|
+
setSelection(editor, selection);
|
|
3214
|
+
insertNodes(editor, inlineEntryNode);
|
|
2914
3215
|
resolve();
|
|
2915
3216
|
}, 0);
|
|
2916
3217
|
}));
|
|
@@ -3121,7 +3422,7 @@ function ToolbarHeadingButton(props) {
|
|
|
3121
3422
|
}
|
|
3122
3423
|
|
|
3123
3424
|
function extractNodes(editor, path, match) {
|
|
3124
|
-
return Array.from(
|
|
3425
|
+
return Array.from(getNodeEntries(editor, {
|
|
3125
3426
|
match: match,
|
|
3126
3427
|
at: path,
|
|
3127
3428
|
mode: 'lowest'
|
|
@@ -3147,7 +3448,7 @@ function extractParagraphs(editor, path) {
|
|
|
3147
3448
|
|
|
3148
3449
|
var transformRemove = function transformRemove(editor, _ref) {
|
|
3149
3450
|
var path = _ref[1];
|
|
3150
|
-
|
|
3451
|
+
removeNodes(editor, {
|
|
3151
3452
|
at: path
|
|
3152
3453
|
});
|
|
3153
3454
|
};
|
|
@@ -3155,20 +3456,20 @@ var transformParagraphs = function transformParagraphs(editor, entry) {
|
|
|
3155
3456
|
var path = entry[1];
|
|
3156
3457
|
var nodes = extractParagraphs(editor, path);
|
|
3157
3458
|
transformRemove(editor, entry);
|
|
3158
|
-
|
|
3459
|
+
insertNodes(editor, nodes, {
|
|
3159
3460
|
at: path
|
|
3160
3461
|
});
|
|
3161
3462
|
};
|
|
3162
3463
|
var transformUnwrap = function transformUnwrap(editor, _ref2) {
|
|
3163
3464
|
var path = _ref2[1];
|
|
3164
|
-
|
|
3465
|
+
unwrapNodes(editor, {
|
|
3165
3466
|
at: path
|
|
3166
3467
|
});
|
|
3167
3468
|
};
|
|
3168
3469
|
var transformWrapIn = function transformWrapIn(type) {
|
|
3169
3470
|
return function (editor, _ref3) {
|
|
3170
3471
|
var path = _ref3[1];
|
|
3171
|
-
|
|
3472
|
+
wrapNodes(editor, {
|
|
3172
3473
|
type: type,
|
|
3173
3474
|
data: {},
|
|
3174
3475
|
children: []
|
|
@@ -3179,7 +3480,7 @@ var transformWrapIn = function transformWrapIn(type) {
|
|
|
3179
3480
|
};
|
|
3180
3481
|
var transformLift = function transformLift(editor, _ref4) {
|
|
3181
3482
|
var path = _ref4[1];
|
|
3182
|
-
|
|
3483
|
+
liftNodes(editor, {
|
|
3183
3484
|
at: path
|
|
3184
3485
|
});
|
|
3185
3486
|
};
|
|
@@ -3258,12 +3559,12 @@ var createHeadingPlugin = function createHeadingPlugin() {
|
|
|
3258
3559
|
// insertBreak implementation
|
|
3259
3560
|
filter: function filter(_ref3) {
|
|
3260
3561
|
var path = _ref3[1];
|
|
3261
|
-
return !
|
|
3562
|
+
return !getAboveNode(editor, {
|
|
3262
3563
|
at: path,
|
|
3263
3564
|
match: {
|
|
3264
3565
|
type: Contentful.BLOCKS.LIST_ITEM
|
|
3265
3566
|
}
|
|
3266
|
-
}) && !
|
|
3567
|
+
}) && !isMarkActive(editor, COMMAND_PROMPT);
|
|
3267
3568
|
}
|
|
3268
3569
|
}
|
|
3269
3570
|
}]
|
|
@@ -3358,7 +3659,7 @@ function withHrEvents(editor) {
|
|
|
3358
3659
|
|
|
3359
3660
|
if (isBackspace || isDelete) {
|
|
3360
3661
|
event.preventDefault();
|
|
3361
|
-
|
|
3662
|
+
removeNodes(editor, {
|
|
3362
3663
|
at: pathToSelectedHr
|
|
3363
3664
|
});
|
|
3364
3665
|
}
|
|
@@ -3378,8 +3679,8 @@ function ToolbarHrButton(props) {
|
|
|
3378
3679
|
}],
|
|
3379
3680
|
isVoid: true
|
|
3380
3681
|
};
|
|
3381
|
-
var hasText = !!
|
|
3382
|
-
hasText ?
|
|
3682
|
+
var hasText = !!getText(editor, editor.selection.focus.path);
|
|
3683
|
+
hasText ? insertNodes(editor, hr) : setNodes(editor, hr); // Move focus to the next paragraph (added by TrailingParagraph plugin)
|
|
3383
3684
|
|
|
3384
3685
|
moveToTheNextLine(editor);
|
|
3385
3686
|
focus(editor);
|
|
@@ -3665,7 +3966,7 @@ function _addOrEditLink() {
|
|
|
3665
3966
|
while (1) {
|
|
3666
3967
|
switch (_context3.prev = _context3.next) {
|
|
3667
3968
|
case 0:
|
|
3668
|
-
isReadOnly =
|
|
3969
|
+
isReadOnly = isEditorReadOnly(editor);
|
|
3669
3970
|
selectionBeforeBlur = editor.selection ? _extends({}, editor.selection) : undefined;
|
|
3670
3971
|
|
|
3671
3972
|
if (!(!targetPath && !selectionBeforeBlur)) {
|
|
@@ -3680,13 +3981,13 @@ function _addOrEditLink() {
|
|
|
3680
3981
|
|
|
3681
3982
|
if (node && path) {
|
|
3682
3983
|
linkType = node.type;
|
|
3683
|
-
linkText =
|
|
3984
|
+
linkText = getText(editor, path);
|
|
3684
3985
|
linkTarget = node.data.uri || '';
|
|
3685
3986
|
linkEntity = node.data.target;
|
|
3686
3987
|
}
|
|
3687
3988
|
|
|
3688
3989
|
selectionAfterFocus = targetPath != null ? targetPath : selectionBeforeBlur;
|
|
3689
|
-
currentLinkText = linkText || (editor.selection ?
|
|
3990
|
+
currentLinkText = linkText || (editor.selection ? getText(editor, editor.selection) : '');
|
|
3690
3991
|
isEditing = Boolean(node && path);
|
|
3691
3992
|
logAction(isEditing ? 'openEditHyperlinkDialog' : 'openCreateHyperlinkDialog');
|
|
3692
3993
|
_context3.next = 12;
|
|
@@ -3711,7 +4012,7 @@ function _addOrEditLink() {
|
|
|
3711
4012
|
|
|
3712
4013
|
case 12:
|
|
3713
4014
|
data = _context3.sent;
|
|
3714
|
-
|
|
4015
|
+
select(editor, selectionAfterFocus);
|
|
3715
4016
|
|
|
3716
4017
|
if (data) {
|
|
3717
4018
|
_context3.next = 18;
|
|
@@ -3724,7 +4025,7 @@ function _addOrEditLink() {
|
|
|
3724
4025
|
|
|
3725
4026
|
case 18:
|
|
3726
4027
|
text = data.linkText, url = data.linkTarget, type = data.linkType, target = data.linkEntity;
|
|
3727
|
-
|
|
4028
|
+
withoutNormalizing(editor, function () {
|
|
3728
4029
|
insertLink(editor, {
|
|
3729
4030
|
text: text,
|
|
3730
4031
|
url: url,
|
|
@@ -3801,8 +4102,9 @@ function ToolbarHyperlinkButton(props) {
|
|
|
3801
4102
|
}
|
|
3802
4103
|
|
|
3803
4104
|
var hasText = function hasText(editor, entry) {
|
|
3804
|
-
var node = entry[0]
|
|
3805
|
-
|
|
4105
|
+
var node = entry[0],
|
|
4106
|
+
path = entry[1];
|
|
4107
|
+
return !p.isAncestorEmpty(editor, node) && getText(editor, path).trim() !== '';
|
|
3806
4108
|
};
|
|
3807
4109
|
|
|
3808
4110
|
function truncate(str, length) {
|
|
@@ -3993,11 +4295,11 @@ function EntityHyperlink(props) {
|
|
|
3993
4295
|
event.preventDefault();
|
|
3994
4296
|
event.stopPropagation();
|
|
3995
4297
|
if (!editor) return;
|
|
3996
|
-
var p =
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4298
|
+
var p = fromDOMPoint(editor, [event.target, 0]);
|
|
4299
|
+
|
|
4300
|
+
if (p) {
|
|
4301
|
+
addOrEditLink(editor, sdk, editor.tracking.onViewportAction, p.path);
|
|
4302
|
+
}
|
|
4001
4303
|
}
|
|
4002
4304
|
|
|
4003
4305
|
return /*#__PURE__*/React.createElement(f36Components.Tooltip, {
|
|
@@ -4023,11 +4325,11 @@ function UrlHyperlink(props) {
|
|
|
4023
4325
|
event.preventDefault();
|
|
4024
4326
|
event.stopPropagation();
|
|
4025
4327
|
if (!editor) return;
|
|
4026
|
-
var p =
|
|
4328
|
+
var p = fromDOMPoint(editor, [event.target, 0], {
|
|
4027
4329
|
exactMatch: false,
|
|
4028
4330
|
suppressThrow: false
|
|
4029
4331
|
});
|
|
4030
|
-
addOrEditLink(editor, sdk, editor.tracking.onViewportAction, p.path);
|
|
4332
|
+
addOrEditLink(editor, sdk, editor.tracking.onViewportAction, p == null ? void 0 : p.path);
|
|
4031
4333
|
}
|
|
4032
4334
|
|
|
4033
4335
|
return /*#__PURE__*/React.createElement(f36Components.Tooltip, {
|
|
@@ -4199,27 +4501,28 @@ var moveListItemDown = function moveListItemDown(editor, _ref) {
|
|
|
4199
4501
|
var previousListItemPath;
|
|
4200
4502
|
|
|
4201
4503
|
try {
|
|
4202
|
-
previousListItemPath =
|
|
4504
|
+
previousListItemPath = getPreviousPath(listItemPath);
|
|
4203
4505
|
} catch (e) {
|
|
4204
4506
|
return;
|
|
4205
4507
|
} // Previous sibling is the new parent
|
|
4206
4508
|
|
|
4207
4509
|
|
|
4208
|
-
var previousSiblingItem =
|
|
4510
|
+
var previousSiblingItem = getNodeEntry(editor, previousListItemPath);
|
|
4209
4511
|
|
|
4210
4512
|
if (previousSiblingItem) {
|
|
4211
4513
|
var previousPath = previousSiblingItem[1];
|
|
4212
|
-
var subList = Array.from(
|
|
4213
|
-
var n = _ref2[0]
|
|
4214
|
-
|
|
4514
|
+
var subList = Array.from(getNodeChildren(editor, previousPath)).find(function (_ref2) {
|
|
4515
|
+
var n = _ref2[0],
|
|
4516
|
+
path = _ref2[1];
|
|
4517
|
+
return match(n, path, {
|
|
4215
4518
|
type: plateList.getListTypes(editor)
|
|
4216
4519
|
});
|
|
4217
4520
|
});
|
|
4218
|
-
var newPath =
|
|
4219
|
-
|
|
4521
|
+
var newPath = getNextPath(getLastChildPath(subList != null ? subList : previousSiblingItem));
|
|
4522
|
+
withoutNormalizing(editor, function () {
|
|
4220
4523
|
if (!subList) {
|
|
4221
4524
|
// Create new sub-list
|
|
4222
|
-
|
|
4525
|
+
wrapNodes(editor, {
|
|
4223
4526
|
type: listNode.type,
|
|
4224
4527
|
children: [],
|
|
4225
4528
|
data: {}
|
|
@@ -4229,7 +4532,7 @@ var moveListItemDown = function moveListItemDown(editor, _ref) {
|
|
|
4229
4532
|
} // Move the current item to the sub-list
|
|
4230
4533
|
|
|
4231
4534
|
|
|
4232
|
-
|
|
4535
|
+
moveNodes(editor, {
|
|
4233
4536
|
at: listItemPath,
|
|
4234
4537
|
to: newPath
|
|
4235
4538
|
});
|
|
@@ -4250,10 +4553,10 @@ var moveListItems = function moveListItems(editor, _temp) {
|
|
|
4250
4553
|
_ref$at = _ref.at,
|
|
4251
4554
|
at = _ref$at === void 0 ? (_editor$selection = editor.selection) != null ? _editor$selection : undefined : _ref$at;
|
|
4252
4555
|
|
|
4253
|
-
var _nodes =
|
|
4556
|
+
var _nodes = getNodeEntries(editor, {
|
|
4254
4557
|
at: at,
|
|
4255
4558
|
match: {
|
|
4256
|
-
type:
|
|
4559
|
+
type: getPluginType(editor, plateList.ELEMENT_LIC)
|
|
4257
4560
|
}
|
|
4258
4561
|
}); // Get the selected lic
|
|
4259
4562
|
|
|
@@ -4265,19 +4568,19 @@ var moveListItems = function moveListItems(editor, _temp) {
|
|
|
4265
4568
|
|
|
4266
4569
|
lics.forEach(function (lic) {
|
|
4267
4570
|
var licPath = lic[1];
|
|
4268
|
-
var liPath =
|
|
4571
|
+
var liPath = getParentPath(licPath);
|
|
4269
4572
|
var isAncestor = highestLicPaths.some(function (path) {
|
|
4270
|
-
var highestLiPath =
|
|
4271
|
-
return
|
|
4573
|
+
var highestLiPath = getParentPath(path);
|
|
4574
|
+
return isAncestorPath(highestLiPath, liPath);
|
|
4272
4575
|
});
|
|
4273
4576
|
|
|
4274
4577
|
if (!isAncestor) {
|
|
4275
4578
|
highestLicPaths.push(licPath);
|
|
4276
|
-
highestLicPathRefs.push(
|
|
4579
|
+
highestLicPathRefs.push(createPathRef(editor, licPath));
|
|
4277
4580
|
}
|
|
4278
4581
|
});
|
|
4279
4582
|
var licPathRefsToMove = increase ? highestLicPathRefs : highestLicPathRefs.reverse();
|
|
4280
|
-
|
|
4583
|
+
withoutNormalizing(editor, function () {
|
|
4281
4584
|
licPathRefsToMove.forEach(function (licPathRef) {
|
|
4282
4585
|
var licPath = licPathRef.unref();
|
|
4283
4586
|
if (!licPath) return;
|
|
@@ -4298,16 +4601,18 @@ var moveListItems = function moveListItems(editor, _temp) {
|
|
|
4298
4601
|
});
|
|
4299
4602
|
};
|
|
4300
4603
|
|
|
4604
|
+
var ELEMENT_DEFAULT = p.ELEMENT_DEFAULT;
|
|
4605
|
+
|
|
4301
4606
|
/**
|
|
4302
4607
|
* Credit: Modified version of Plate's list plugin
|
|
4303
4608
|
* See: https://github.com/udecode/plate/blob/main/packages/nodes/list
|
|
4304
4609
|
*/
|
|
4305
4610
|
|
|
4306
4611
|
function hasUnliftedListItems(editor, at) {
|
|
4307
|
-
return
|
|
4612
|
+
return getNodeEntries(editor, {
|
|
4308
4613
|
at: at,
|
|
4309
4614
|
match: function match(node, path) {
|
|
4310
|
-
return
|
|
4615
|
+
return isElement(node) && node.type === Contentful.BLOCKS.LIST_ITEM && path.length >= 2;
|
|
4311
4616
|
}
|
|
4312
4617
|
}).next().done;
|
|
4313
4618
|
}
|
|
@@ -4316,20 +4621,20 @@ var unwrapList = function unwrapList(editor, _temp) {
|
|
|
4316
4621
|
var _ref = _temp === void 0 ? {} : _temp,
|
|
4317
4622
|
at = _ref.at;
|
|
4318
4623
|
|
|
4319
|
-
|
|
4624
|
+
withoutNormalizing(editor, function () {
|
|
4320
4625
|
do {
|
|
4321
4626
|
// lift list items to the root level
|
|
4322
|
-
|
|
4627
|
+
liftNodes(editor, {
|
|
4323
4628
|
at: at,
|
|
4324
4629
|
match: function match(node) {
|
|
4325
|
-
return
|
|
4630
|
+
return isElement(node) && node.type === Contentful.BLOCKS.LIST_ITEM;
|
|
4326
4631
|
},
|
|
4327
4632
|
mode: 'lowest'
|
|
4328
4633
|
});
|
|
4329
4634
|
} while (!hasUnliftedListItems(editor, at)); // finally unwrap all lifted items
|
|
4330
4635
|
|
|
4331
4636
|
|
|
4332
|
-
|
|
4637
|
+
unwrapNodes(editor, {
|
|
4333
4638
|
at: at,
|
|
4334
4639
|
match: {
|
|
4335
4640
|
type: Contentful.BLOCKS.LIST_ITEM
|
|
@@ -4342,12 +4647,12 @@ var unwrapList = function unwrapList(editor, _temp) {
|
|
|
4342
4647
|
var listTypes = [Contentful.BLOCKS.UL_LIST, Contentful.BLOCKS.OL_LIST];
|
|
4343
4648
|
var toggleList = function toggleList(editor, _ref) {
|
|
4344
4649
|
var type = _ref.type;
|
|
4345
|
-
return
|
|
4650
|
+
return withoutNormalizing(editor, function () {
|
|
4346
4651
|
if (!editor.selection) {
|
|
4347
4652
|
return;
|
|
4348
4653
|
}
|
|
4349
4654
|
|
|
4350
|
-
if (
|
|
4655
|
+
if (isRangeCollapsed(editor.selection) || !isRangeAcrossBlocks(editor)) {
|
|
4351
4656
|
// selection is collapsed
|
|
4352
4657
|
var res = plateList.getListItemEntry(editor);
|
|
4353
4658
|
|
|
@@ -4355,7 +4660,7 @@ var toggleList = function toggleList(editor, _ref) {
|
|
|
4355
4660
|
var list = res.list;
|
|
4356
4661
|
|
|
4357
4662
|
if (list[0].type !== type) {
|
|
4358
|
-
|
|
4663
|
+
setNodes(editor, {
|
|
4359
4664
|
type: type
|
|
4360
4665
|
}, {
|
|
4361
4666
|
at: editor.selection,
|
|
@@ -4373,10 +4678,10 @@ var toggleList = function toggleList(editor, _ref) {
|
|
|
4373
4678
|
children: [],
|
|
4374
4679
|
data: {}
|
|
4375
4680
|
};
|
|
4376
|
-
|
|
4377
|
-
var nodes = [].concat(
|
|
4681
|
+
wrapNodes(editor, _list);
|
|
4682
|
+
var nodes = [].concat(getNodeEntries(editor, {
|
|
4378
4683
|
match: {
|
|
4379
|
-
type:
|
|
4684
|
+
type: getPluginType(editor, ELEMENT_DEFAULT)
|
|
4380
4685
|
}
|
|
4381
4686
|
}));
|
|
4382
4687
|
var listItem = {
|
|
@@ -4388,36 +4693,38 @@ var toggleList = function toggleList(editor, _ref) {
|
|
|
4388
4693
|
for (var _iterator = _createForOfIteratorHelperLoose(nodes), _step; !(_step = _iterator()).done;) {
|
|
4389
4694
|
var _step$value = _step.value,
|
|
4390
4695
|
path = _step$value[1];
|
|
4391
|
-
|
|
4696
|
+
wrapNodes(editor, listItem, {
|
|
4392
4697
|
at: path
|
|
4393
4698
|
});
|
|
4394
4699
|
}
|
|
4395
4700
|
}
|
|
4396
4701
|
} else {
|
|
4397
4702
|
// selection is a range
|
|
4398
|
-
var
|
|
4399
|
-
startPoint =
|
|
4400
|
-
endPoint =
|
|
4703
|
+
var _getRangeEdges = getRangeEdges(editor.selection),
|
|
4704
|
+
startPoint = _getRangeEdges[0],
|
|
4705
|
+
endPoint = _getRangeEdges[1];
|
|
4401
4706
|
|
|
4402
|
-
var commonEntry =
|
|
4707
|
+
var commonEntry = getCommonNode(editor, startPoint.path, endPoint.path);
|
|
4403
4708
|
|
|
4404
4709
|
if (listTypes.includes(commonEntry[0].type) || commonEntry[0].type === Contentful.BLOCKS.LIST_ITEM) {
|
|
4405
4710
|
var listType = commonEntry[0].type;
|
|
4406
4711
|
|
|
4407
4712
|
if (commonEntry[0].type === Contentful.BLOCKS.LIST_ITEM) {
|
|
4408
|
-
|
|
4713
|
+
var _getParentNode, _getParentNode$;
|
|
4714
|
+
|
|
4715
|
+
listType = (_getParentNode = getParentNode(editor, commonEntry[1])) == null ? void 0 : (_getParentNode$ = _getParentNode[0]) == null ? void 0 : _getParentNode$.type;
|
|
4409
4716
|
}
|
|
4410
4717
|
|
|
4411
4718
|
if (listType !== type) {
|
|
4412
|
-
var startList =
|
|
4413
|
-
at:
|
|
4719
|
+
var startList = findNode(editor, {
|
|
4720
|
+
at: getRangeStart(editor.selection),
|
|
4414
4721
|
match: {
|
|
4415
4722
|
type: listTypes
|
|
4416
4723
|
},
|
|
4417
4724
|
mode: 'lowest'
|
|
4418
4725
|
});
|
|
4419
|
-
var endList =
|
|
4420
|
-
at:
|
|
4726
|
+
var endList = findNode(editor, {
|
|
4727
|
+
at: getRangeEnd(editor.selection),
|
|
4421
4728
|
match: {
|
|
4422
4729
|
type: listTypes
|
|
4423
4730
|
},
|
|
@@ -4429,7 +4736,7 @@ var toggleList = function toggleList(editor, _ref) {
|
|
|
4429
4736
|
}
|
|
4430
4737
|
|
|
4431
4738
|
var rangeLength = Math.min(startList[1].length, endList[1].length);
|
|
4432
|
-
|
|
4739
|
+
setNodes(editor, {
|
|
4433
4740
|
type: type
|
|
4434
4741
|
}, {
|
|
4435
4742
|
at: editor.selection,
|
|
@@ -4444,7 +4751,7 @@ var toggleList = function toggleList(editor, _ref) {
|
|
|
4444
4751
|
} else {
|
|
4445
4752
|
var rootPathLength = commonEntry[1].length;
|
|
4446
4753
|
|
|
4447
|
-
var _nodes = Array.from(
|
|
4754
|
+
var _nodes = Array.from(getNodeEntries(editor, {
|
|
4448
4755
|
mode: 'all'
|
|
4449
4756
|
})).filter(function (_ref2) {
|
|
4450
4757
|
var path = _ref2[1];
|
|
@@ -4453,14 +4760,14 @@ var toggleList = function toggleList(editor, _ref) {
|
|
|
4453
4760
|
|
|
4454
4761
|
_nodes.forEach(function (n) {
|
|
4455
4762
|
if (listTypes.includes(n[0].type)) {
|
|
4456
|
-
|
|
4763
|
+
setNodes(editor, {
|
|
4457
4764
|
type: type
|
|
4458
4765
|
}, {
|
|
4459
4766
|
at: n[1]
|
|
4460
4767
|
});
|
|
4461
4768
|
} else {
|
|
4462
|
-
|
|
4463
|
-
type:
|
|
4769
|
+
setNodes(editor, {
|
|
4770
|
+
type: getPluginType(editor, plateList.ELEMENT_LIC)
|
|
4464
4771
|
}, {
|
|
4465
4772
|
at: n[1]
|
|
4466
4773
|
});
|
|
@@ -4469,7 +4776,7 @@ var toggleList = function toggleList(editor, _ref) {
|
|
|
4469
4776
|
children: [],
|
|
4470
4777
|
data: {}
|
|
4471
4778
|
};
|
|
4472
|
-
|
|
4779
|
+
wrapNodes(editor, _listItem, {
|
|
4473
4780
|
at: n[1]
|
|
4474
4781
|
});
|
|
4475
4782
|
var _list2 = {
|
|
@@ -4477,7 +4784,7 @@ var toggleList = function toggleList(editor, _ref) {
|
|
|
4477
4784
|
children: [],
|
|
4478
4785
|
data: {}
|
|
4479
4786
|
};
|
|
4480
|
-
|
|
4787
|
+
wrapNodes(editor, _list2, {
|
|
4481
4788
|
at: n[1]
|
|
4482
4789
|
});
|
|
4483
4790
|
}
|
|
@@ -4492,7 +4799,7 @@ var onKeyDownList = function onKeyDownList(editor, _ref) {
|
|
|
4492
4799
|
hotkey = _ref.options.hotkey;
|
|
4493
4800
|
return function (e) {
|
|
4494
4801
|
if (e.key === 'Tab' && editor.selection) {
|
|
4495
|
-
var listSelected =
|
|
4802
|
+
var listSelected = getAboveNode(editor, {
|
|
4496
4803
|
at: editor.selection,
|
|
4497
4804
|
match: {
|
|
4498
4805
|
type: type
|
|
@@ -4530,14 +4837,14 @@ var isList = function isList(node) {
|
|
|
4530
4837
|
var hasListAsDirectParent = function hasListAsDirectParent(editor, _ref) {
|
|
4531
4838
|
var path = _ref[1];
|
|
4532
4839
|
|
|
4533
|
-
var _ref2 =
|
|
4840
|
+
var _ref2 = p.getParentNode(editor, path) || [],
|
|
4534
4841
|
parentNode = _ref2[0];
|
|
4535
4842
|
|
|
4536
4843
|
return isList(parentNode);
|
|
4537
4844
|
};
|
|
4538
4845
|
|
|
4539
4846
|
var getNearestListAncestor = function getNearestListAncestor(editor, path) {
|
|
4540
|
-
return
|
|
4847
|
+
return p.getAboveNode(editor, {
|
|
4541
4848
|
at: path,
|
|
4542
4849
|
mode: 'lowest',
|
|
4543
4850
|
match: isList
|
|
@@ -4557,7 +4864,7 @@ var normalizeOrphanedListItem = function normalizeOrphanedListItem(editor, _ref3
|
|
|
4557
4864
|
parentList = _getNearestListAncest[0];
|
|
4558
4865
|
|
|
4559
4866
|
var parentListType = parentList == null ? void 0 : parentList.type;
|
|
4560
|
-
|
|
4867
|
+
wrapNodes(editor, {
|
|
4561
4868
|
type: parentListType || Contentful.BLOCKS.UL_LIST,
|
|
4562
4869
|
children: [],
|
|
4563
4870
|
data: {}
|
|
@@ -4565,24 +4872,23 @@ var normalizeOrphanedListItem = function normalizeOrphanedListItem(editor, _ref3
|
|
|
4565
4872
|
at: path
|
|
4566
4873
|
});
|
|
4567
4874
|
};
|
|
4568
|
-
var isNonEmptyListItem = function isNonEmptyListItem(
|
|
4569
|
-
var
|
|
4570
|
-
var listItemChildren = Array.from(slate.Node.children(editor, path));
|
|
4875
|
+
var isNonEmptyListItem = function isNonEmptyListItem(_, entry) {
|
|
4876
|
+
var listItemChildren = getChildren(entry);
|
|
4571
4877
|
return listItemChildren.length !== 0;
|
|
4572
4878
|
};
|
|
4573
|
-
var firstNodeIsNotList = function firstNodeIsNotList(_editor,
|
|
4574
|
-
var node =
|
|
4879
|
+
var firstNodeIsNotList = function firstNodeIsNotList(_editor, _ref4) {
|
|
4880
|
+
var node = _ref4[0];
|
|
4575
4881
|
|
|
4576
4882
|
if (node.children.length === 1) {
|
|
4577
4883
|
var firstNode = node.children[0];
|
|
4578
|
-
return !
|
|
4884
|
+
return !isText(firstNode) && !isList(firstNode);
|
|
4579
4885
|
}
|
|
4580
4886
|
|
|
4581
4887
|
return true;
|
|
4582
4888
|
};
|
|
4583
|
-
var insertParagraphAsChild = function insertParagraphAsChild(editor,
|
|
4584
|
-
var path =
|
|
4585
|
-
|
|
4889
|
+
var insertParagraphAsChild = function insertParagraphAsChild(editor, _ref5) {
|
|
4890
|
+
var path = _ref5[1];
|
|
4891
|
+
insertNodes(editor, [{
|
|
4586
4892
|
type: Contentful.BLOCKS.PARAGRAPH,
|
|
4587
4893
|
data: {},
|
|
4588
4894
|
children: [{
|
|
@@ -4595,10 +4901,10 @@ var insertParagraphAsChild = function insertParagraphAsChild(editor, _ref6) {
|
|
|
4595
4901
|
var replaceNodeWithListItems = function replaceNodeWithListItems(editor, entry) {
|
|
4596
4902
|
var node = entry[0],
|
|
4597
4903
|
path = entry[1];
|
|
4598
|
-
|
|
4904
|
+
removeNodes(editor, {
|
|
4599
4905
|
at: path
|
|
4600
4906
|
});
|
|
4601
|
-
|
|
4907
|
+
insertNodes(editor, node.children[0].children, {
|
|
4602
4908
|
at: path
|
|
4603
4909
|
});
|
|
4604
4910
|
};
|
|
@@ -4609,12 +4915,12 @@ var isListTypeActive = function isListTypeActive(editor, type) {
|
|
|
4609
4915
|
return false;
|
|
4610
4916
|
}
|
|
4611
4917
|
|
|
4612
|
-
if (
|
|
4613
|
-
var
|
|
4614
|
-
start =
|
|
4615
|
-
end =
|
|
4918
|
+
if (isRangeExpanded(selection)) {
|
|
4919
|
+
var _getRangeEdges = getRangeEdges(selection),
|
|
4920
|
+
start = _getRangeEdges[0],
|
|
4921
|
+
end = _getRangeEdges[1];
|
|
4616
4922
|
|
|
4617
|
-
var node =
|
|
4923
|
+
var node = getCommonNode(editor, start.path, end.path);
|
|
4618
4924
|
|
|
4619
4925
|
if (node[0].type === type) {
|
|
4620
4926
|
return true;
|
|
@@ -4622,7 +4928,7 @@ var isListTypeActive = function isListTypeActive(editor, type) {
|
|
|
4622
4928
|
} // Lists can be nested. Here, we take the list type at the lowest level
|
|
4623
4929
|
|
|
4624
4930
|
|
|
4625
|
-
var listNode =
|
|
4931
|
+
var listNode = p.getBlockAbove(editor, {
|
|
4626
4932
|
match: {
|
|
4627
4933
|
type: [Contentful.BLOCKS.OL_LIST, Contentful.BLOCKS.UL_LIST]
|
|
4628
4934
|
},
|
|
@@ -4643,7 +4949,7 @@ var emptyListItemNode = function emptyListItemNode(editor, withChildren) {
|
|
|
4643
4949
|
var children = [];
|
|
4644
4950
|
|
|
4645
4951
|
if (withChildren) {
|
|
4646
|
-
var marks =
|
|
4952
|
+
var marks = getMarks(editor) || {};
|
|
4647
4953
|
children = [{
|
|
4648
4954
|
type: Contentful.BLOCKS.PARAGRAPH,
|
|
4649
4955
|
data: {},
|
|
@@ -4670,7 +4976,7 @@ var insertListItem = function insertListItem(editor) {
|
|
|
4670
4976
|
} // Naming it paragraph for simplicity but can be a heading as well
|
|
4671
4977
|
|
|
4672
4978
|
|
|
4673
|
-
var paragraph =
|
|
4979
|
+
var paragraph = getAboveNode(editor, {
|
|
4674
4980
|
match: {
|
|
4675
4981
|
type: Contentful.TEXT_CONTAINERS
|
|
4676
4982
|
}
|
|
@@ -4681,7 +4987,7 @@ var insertListItem = function insertListItem(editor) {
|
|
|
4681
4987
|
}
|
|
4682
4988
|
|
|
4683
4989
|
var paragraphPath = paragraph[1];
|
|
4684
|
-
var listItem =
|
|
4990
|
+
var listItem = getParentNode(editor, paragraphPath);
|
|
4685
4991
|
|
|
4686
4992
|
if (!listItem) {
|
|
4687
4993
|
return false;
|
|
@@ -4695,30 +5001,30 @@ var insertListItem = function insertListItem(editor) {
|
|
|
4695
5001
|
} // We are in a li>p (or heading)
|
|
4696
5002
|
|
|
4697
5003
|
|
|
4698
|
-
|
|
5004
|
+
withoutNormalizing(editor, function () {
|
|
4699
5005
|
if (!editor.selection) {
|
|
4700
5006
|
return;
|
|
4701
5007
|
} // Check the cursor position in the current paragraph
|
|
4702
5008
|
|
|
4703
5009
|
|
|
4704
|
-
var isAtStart =
|
|
4705
|
-
var isAtEnd =
|
|
4706
|
-
var isAtStartOfListItem = isAtStart &&
|
|
5010
|
+
var isAtStart = isSelectionAtBlockStart(editor);
|
|
5011
|
+
var isAtEnd = isSelectionAtBlockEnd(editor);
|
|
5012
|
+
var isAtStartOfListItem = isAtStart && isFirstChildPath(paragraphPath);
|
|
4707
5013
|
var shouldSplit = !isAtStart && !isAtEnd; // Split the current paragraph content if necessary
|
|
4708
5014
|
|
|
4709
5015
|
if (shouldSplit) {
|
|
4710
|
-
|
|
5016
|
+
splitNodes(editor);
|
|
4711
5017
|
} // Insert the new li
|
|
4712
5018
|
|
|
4713
5019
|
|
|
4714
|
-
var newListItemPath = isAtStartOfListItem ? listItemPath :
|
|
4715
|
-
|
|
5020
|
+
var newListItemPath = isAtStartOfListItem ? listItemPath : getNextPath(listItemPath);
|
|
5021
|
+
insertNodes(editor, // Add an empty paragraph to the new li if We will not move some
|
|
4716
5022
|
// paragraphs over there.
|
|
4717
5023
|
emptyListItemNode(editor, !shouldSplit), {
|
|
4718
5024
|
at: newListItemPath
|
|
4719
5025
|
}); // Move children *after* selection to the new li
|
|
4720
5026
|
|
|
4721
|
-
var fromPath = isAtStart ? paragraphPath :
|
|
5027
|
+
var fromPath = isAtStart ? paragraphPath : getNextPath(paragraphPath);
|
|
4722
5028
|
var fromStartIndex = fromPath[fromPath.length - 1] || 0; // On split we don't add paragraph to the new li so we move
|
|
4723
5029
|
// content to the very beginning. Otherwise, account for the empty
|
|
4724
5030
|
// paragraph at the beginning by moving the content after
|
|
@@ -4726,7 +5032,7 @@ var insertListItem = function insertListItem(editor) {
|
|
|
4726
5032
|
var toPath = newListItemPath.concat([shouldSplit ? 0 : 1]);
|
|
4727
5033
|
|
|
4728
5034
|
if (!isAtStartOfListItem) {
|
|
4729
|
-
|
|
5035
|
+
moveChildren(editor, {
|
|
4730
5036
|
at: listItemPath,
|
|
4731
5037
|
to: toPath,
|
|
4732
5038
|
fromStartIndex: fromStartIndex
|
|
@@ -4734,8 +5040,8 @@ var insertListItem = function insertListItem(editor) {
|
|
|
4734
5040
|
} // Move cursor to the start of the new li
|
|
4735
5041
|
|
|
4736
5042
|
|
|
4737
|
-
|
|
4738
|
-
|
|
5043
|
+
select(editor, newListItemPath);
|
|
5044
|
+
collapseSelection(editor, {
|
|
4739
5045
|
edge: 'start'
|
|
4740
5046
|
});
|
|
4741
5047
|
}); // Returning True skips processing other editor.insertBreak handlers
|
|
@@ -4760,7 +5066,7 @@ var listBreak = function listBreak(editor) {
|
|
|
4760
5066
|
listItem = res.listItem;
|
|
4761
5067
|
var childNode = listItem[0].children[0]; // If selected li is empty, move it up.
|
|
4762
5068
|
|
|
4763
|
-
if (
|
|
5069
|
+
if (p.isBlockAboveEmpty(editor) && listItem[0].children.length === 1 && Contentful.TEXT_CONTAINERS.includes(childNode.type)) {
|
|
4764
5070
|
moved = plateList.moveListItemUp(editor, {
|
|
4765
5071
|
list: list,
|
|
4766
5072
|
listItem: listItem
|
|
@@ -4769,13 +5075,13 @@ var listBreak = function listBreak(editor) {
|
|
|
4769
5075
|
}
|
|
4770
5076
|
}
|
|
4771
5077
|
|
|
4772
|
-
var didReset = plateResetNode.onKeyDownResetNode(editor,
|
|
5078
|
+
var didReset = plateResetNode.onKeyDownResetNode(editor, p.mockPlugin({
|
|
4773
5079
|
options: {
|
|
4774
5080
|
rules: [{
|
|
4775
|
-
types: [
|
|
4776
|
-
defaultType:
|
|
5081
|
+
types: [p.getPluginType(editor, plateList.ELEMENT_LI)],
|
|
5082
|
+
defaultType: p.getPluginType(editor, p.ELEMENT_DEFAULT),
|
|
4777
5083
|
predicate: function predicate() {
|
|
4778
|
-
return !moved &&
|
|
5084
|
+
return !moved && p.isBlockAboveEmpty(editor);
|
|
4779
5085
|
},
|
|
4780
5086
|
onReset: function onReset(_editor) {
|
|
4781
5087
|
return plateList.unwrapList(_editor);
|
|
@@ -4814,13 +5120,13 @@ var insertListBreak = function insertListBreak(editor) {
|
|
|
4814
5120
|
*/
|
|
4815
5121
|
|
|
4816
5122
|
var getFirstAncestorOfType = function getFirstAncestorOfType(root, entry) {
|
|
4817
|
-
var ancestor =
|
|
5123
|
+
var ancestor = getParentPath(entry[1]);
|
|
4818
5124
|
|
|
4819
|
-
while (
|
|
4820
|
-
ancestor =
|
|
5125
|
+
while (getDescendantNodeByPath(root, ancestor).type !== Contentful.BLOCKS.LIST_ITEM) {
|
|
5126
|
+
ancestor = getParentPath(ancestor);
|
|
4821
5127
|
}
|
|
4822
5128
|
|
|
4823
|
-
return [
|
|
5129
|
+
return [getDescendantNodeByPath(root, ancestor), ancestor];
|
|
4824
5130
|
};
|
|
4825
5131
|
|
|
4826
5132
|
var isListRoot = function isListRoot(node) {
|
|
@@ -4838,9 +5144,9 @@ var trimList = function trimList(listRoot) {
|
|
|
4838
5144
|
return [listRoot];
|
|
4839
5145
|
}
|
|
4840
5146
|
|
|
4841
|
-
var textEntries = Array.from(
|
|
5147
|
+
var textEntries = Array.from(getNodeTexts(listRoot));
|
|
4842
5148
|
var commonAncestorEntry = textEntries.reduce(function (commonAncestor, textEntry) {
|
|
4843
|
-
return
|
|
5149
|
+
return isAncestorPath(commonAncestor[1], textEntry[1]) ? commonAncestor : getCommonNode(listRoot, textEntry[1], commonAncestor[1]);
|
|
4844
5150
|
}, // any list item would do, we grab the first one
|
|
4845
5151
|
getFirstAncestorOfType(listRoot, textEntries[0]));
|
|
4846
5152
|
return isListRoot(commonAncestorEntry[0]) ? commonAncestorEntry[0].children : [commonAncestorEntry[0]];
|
|
@@ -4881,7 +5187,7 @@ var insertListFragment = function insertListFragment(editor) {
|
|
|
4881
5187
|
return;
|
|
4882
5188
|
}
|
|
4883
5189
|
|
|
4884
|
-
var liEntry =
|
|
5190
|
+
var liEntry = p.findNode(editor, {
|
|
4885
5191
|
match: {
|
|
4886
5192
|
type: Contentful.BLOCKS.LIST_ITEM
|
|
4887
5193
|
},
|
|
@@ -4893,7 +5199,7 @@ var insertListFragment = function insertListFragment(editor) {
|
|
|
4893
5199
|
return trimList(node);
|
|
4894
5200
|
})));
|
|
4895
5201
|
var firstBlockIndex = nodes.findIndex(function (node) {
|
|
4896
|
-
return
|
|
5202
|
+
return isBlockNode(editor, node);
|
|
4897
5203
|
});
|
|
4898
5204
|
|
|
4899
5205
|
if (firstBlockIndex < 0) {
|
|
@@ -4905,11 +5211,11 @@ var insertListFragment = function insertListFragment(editor) {
|
|
|
4905
5211
|
// after a text or inline element occurrence will be unwrapped for
|
|
4906
5212
|
// some reason.
|
|
4907
5213
|
|
|
4908
|
-
|
|
5214
|
+
insertNodes(editor, inlines, {
|
|
4909
5215
|
at: editor.selection,
|
|
4910
5216
|
select: true
|
|
4911
5217
|
});
|
|
4912
|
-
return
|
|
5218
|
+
return insertNodes(editor, blocks, {
|
|
4913
5219
|
at: editor.selection,
|
|
4914
5220
|
select: true
|
|
4915
5221
|
});
|
|
@@ -4934,12 +5240,12 @@ var deleteBackwardList = function deleteBackwardList(editor, unit) {
|
|
|
4934
5240
|
var list = res.list,
|
|
4935
5241
|
listItem = res.listItem;
|
|
4936
5242
|
|
|
4937
|
-
if (
|
|
5243
|
+
if (isSelectionAtBlockStart(editor, {
|
|
4938
5244
|
match: function match(node) {
|
|
4939
5245
|
return node.type === Contentful.BLOCKS.LIST_ITEM;
|
|
4940
5246
|
}
|
|
4941
5247
|
})) {
|
|
4942
|
-
|
|
5248
|
+
withoutNormalizing(editor, function () {
|
|
4943
5249
|
moved = plateList.removeFirstListItem(editor, {
|
|
4944
5250
|
list: list,
|
|
4945
5251
|
listItem: listItem
|
|
@@ -4951,15 +5257,17 @@ var deleteBackwardList = function deleteBackwardList(editor, unit) {
|
|
|
4951
5257
|
});
|
|
4952
5258
|
if (moved) return;
|
|
4953
5259
|
|
|
4954
|
-
if (
|
|
4955
|
-
plateResetNode.onKeyDownResetNode(editor,
|
|
5260
|
+
if (isFirstChild(listItem[1]) && !plateList.isListNested(editor, list[1])) {
|
|
5261
|
+
plateResetNode.onKeyDownResetNode(editor, // TODO look into this
|
|
5262
|
+
// @ts-expect-error
|
|
5263
|
+
mockPlugin({
|
|
4956
5264
|
options: {
|
|
4957
5265
|
rules: [{
|
|
4958
5266
|
types: [Contentful.BLOCKS.LIST_ITEM],
|
|
4959
5267
|
defaultType: Contentful.BLOCKS.PARAGRAPH,
|
|
4960
5268
|
hotkey: 'backspace',
|
|
4961
5269
|
predicate: function predicate() {
|
|
4962
|
-
return
|
|
5270
|
+
return isSelectionAtBlockStart(editor);
|
|
4963
5271
|
},
|
|
4964
5272
|
onReset: function onReset(e) {
|
|
4965
5273
|
return unwrapList(e);
|
|
@@ -4971,7 +5279,9 @@ var deleteBackwardList = function deleteBackwardList(editor, unit) {
|
|
|
4971
5279
|
return;
|
|
4972
5280
|
}
|
|
4973
5281
|
|
|
4974
|
-
|
|
5282
|
+
deleteFragment(editor, {
|
|
5283
|
+
// FIXME: see if we can remove unit
|
|
5284
|
+
// @ts-expect-error
|
|
4975
5285
|
unit: unit,
|
|
4976
5286
|
reverse: true
|
|
4977
5287
|
});
|
|
@@ -5009,7 +5319,7 @@ var withList = function withList(editor) {
|
|
|
5009
5319
|
};
|
|
5010
5320
|
|
|
5011
5321
|
editor.insertBreak = insertListBreak(editor);
|
|
5012
|
-
editor.insertFragment = insertListFragment(editor); // TODO: replace with Normalizer rules
|
|
5322
|
+
editor.insertFragment = insertListFragment(editor); // TODO: replace with our own Normalizer rules
|
|
5013
5323
|
|
|
5014
5324
|
editor.normalizeNode = plateList.normalizeList(editor, {
|
|
5015
5325
|
validLiChildrenTypes: validLiChildrenTypes
|
|
@@ -5099,7 +5409,7 @@ function ToolbarListButton(props) {
|
|
|
5099
5409
|
var toggleMarkAndDeactivateConflictingMarks = function toggleMarkAndDeactivateConflictingMarks(editor, mark) {
|
|
5100
5410
|
var subs = [Contentful.MARKS.SUPERSCRIPT, Contentful.MARKS.SUBSCRIPT];
|
|
5101
5411
|
var clear = subs.includes(mark) ? subs : [];
|
|
5102
|
-
|
|
5412
|
+
toggleMark(editor, {
|
|
5103
5413
|
key: mark,
|
|
5104
5414
|
clear: clear
|
|
5105
5415
|
});
|
|
@@ -5110,7 +5420,7 @@ var buildMarkEventHandler = function buildMarkEventHandler(type) {
|
|
|
5110
5420
|
return function (event) {
|
|
5111
5421
|
if (editor.selection && hotkey && isHotkey(hotkey, event)) {
|
|
5112
5422
|
event.preventDefault();
|
|
5113
|
-
var isActive =
|
|
5423
|
+
var isActive = isMarkActive(editor, type);
|
|
5114
5424
|
editor.tracking.onShortcutAction(isActive ? 'unmark' : 'mark', {
|
|
5115
5425
|
markType: type
|
|
5116
5426
|
});
|
|
@@ -5136,7 +5446,7 @@ var createMarkToolbarButton = function createMarkToolbarButton(_ref) {
|
|
|
5136
5446
|
var editor = useContentfulEditor();
|
|
5137
5447
|
var handleClick = React.useCallback(function () {
|
|
5138
5448
|
if (!(editor != null && editor.selection)) return;
|
|
5139
|
-
var isActive =
|
|
5449
|
+
var isActive = isMarkActive(editor, mark);
|
|
5140
5450
|
editor.tracking.onToolbarAction(isActive ? 'unmark' : 'mark', {
|
|
5141
5451
|
markType: mark
|
|
5142
5452
|
});
|
|
@@ -5151,7 +5461,7 @@ var createMarkToolbarButton = function createMarkToolbarButton(_ref) {
|
|
|
5151
5461
|
return /*#__PURE__*/React.createElement(f36Components.Menu.Item, {
|
|
5152
5462
|
onClick: handleClick,
|
|
5153
5463
|
disabled: isDisabled,
|
|
5154
|
-
className: emotion.cx((_cx = {}, _cx[styles$c.isActive] =
|
|
5464
|
+
className: emotion.cx((_cx = {}, _cx[styles$c.isActive] = isMarkActive(editor, mark), _cx)),
|
|
5155
5465
|
testId: mark + "-toolbar-button"
|
|
5156
5466
|
}, title);
|
|
5157
5467
|
}
|
|
@@ -5160,7 +5470,7 @@ var createMarkToolbarButton = function createMarkToolbarButton(_ref) {
|
|
|
5160
5470
|
title: title,
|
|
5161
5471
|
testId: mark + "-toolbar-button",
|
|
5162
5472
|
onClick: handleClick,
|
|
5163
|
-
isActive:
|
|
5473
|
+
isActive: isMarkActive(editor, mark),
|
|
5164
5474
|
isDisabled: isDisabled
|
|
5165
5475
|
}, icon);
|
|
5166
5476
|
};
|
|
@@ -5208,7 +5518,7 @@ var createBoldPlugin = function createBoldPlugin() {
|
|
|
5208
5518
|
}
|
|
5209
5519
|
}],
|
|
5210
5520
|
query: function query(el) {
|
|
5211
|
-
return !isGoogleBoldWrapper(el) && !
|
|
5521
|
+
return !isGoogleBoldWrapper(el) && !someHtmlElement(el, function (node) {
|
|
5212
5522
|
return node.style.fontWeight === 'normal';
|
|
5213
5523
|
});
|
|
5214
5524
|
}
|
|
@@ -5241,7 +5551,13 @@ var createCodePlugin = function createCodePlugin() {
|
|
|
5241
5551
|
type: Contentful.MARKS.CODE,
|
|
5242
5552
|
component: Code,
|
|
5243
5553
|
options: {
|
|
5244
|
-
|
|
5554
|
+
// We need to define multiple hotkeys here,
|
|
5555
|
+
// - mod+/ -> QWERTY keyboard layout
|
|
5556
|
+
// - mod+shift+7 -> QWERTZ keyboard layout
|
|
5557
|
+
// The workaround like in packages/rich-text/src/plugins/CommandPalette/onKeyDown.ts is sadly not working here,
|
|
5558
|
+
// as `shift+7` is not interpreted as `/` with the `mod` key by the OS.
|
|
5559
|
+
// TODO: there are a lot more different keyboard layouts out there
|
|
5560
|
+
hotkey: ['mod+/', 'mod+shift+7']
|
|
5245
5561
|
},
|
|
5246
5562
|
handlers: {
|
|
5247
5563
|
onKeyDown: buildMarkEventHandler(Contentful.MARKS.CODE)
|
|
@@ -5292,7 +5608,7 @@ var createItalicPlugin = function createItalicPlugin() {
|
|
|
5292
5608
|
}
|
|
5293
5609
|
}],
|
|
5294
5610
|
query: function query(el) {
|
|
5295
|
-
return !
|
|
5611
|
+
return !someHtmlElement(el, function (node) {
|
|
5296
5612
|
return node.style.fontStyle === 'normal';
|
|
5297
5613
|
});
|
|
5298
5614
|
}
|
|
@@ -5300,42 +5616,44 @@ var createItalicPlugin = function createItalicPlugin() {
|
|
|
5300
5616
|
});
|
|
5301
5617
|
};
|
|
5302
5618
|
|
|
5303
|
-
var
|
|
5304
|
-
|
|
5305
|
-
|
|
5306
|
-
|
|
5619
|
+
var styles$g = {
|
|
5620
|
+
subscript: /*#__PURE__*/emotion.css({
|
|
5621
|
+
verticalAlign: 'sub',
|
|
5622
|
+
fontSize: 'smaller'
|
|
5623
|
+
})
|
|
5624
|
+
};
|
|
5625
|
+
var ToolbarSubscriptButton = /*#__PURE__*/createMarkToolbarButton({
|
|
5626
|
+
title: 'Subscript',
|
|
5627
|
+
mark: Contentful.MARKS.SUBSCRIPT,
|
|
5628
|
+
icon: /*#__PURE__*/React.createElement(f36Icons.SubscriptIcon, {
|
|
5629
|
+
viewBox: "0 0 23 18"
|
|
5630
|
+
})
|
|
5307
5631
|
});
|
|
5308
|
-
|
|
5309
|
-
|
|
5632
|
+
var ToolbarDropdownSubscriptButton = /*#__PURE__*/createMarkToolbarButton({
|
|
5633
|
+
title: 'Subscript',
|
|
5634
|
+
mark: Contentful.MARKS.SUBSCRIPT
|
|
5635
|
+
});
|
|
5636
|
+
function Subscript(props) {
|
|
5637
|
+
return /*#__PURE__*/React.createElement("sub", _extends({}, props.attributes, {
|
|
5638
|
+
className: styles$g.subscript
|
|
5639
|
+
}), props.children);
|
|
5310
5640
|
}
|
|
5311
|
-
var
|
|
5312
|
-
return plateBasicMarks.
|
|
5313
|
-
type: Contentful.MARKS.
|
|
5314
|
-
component:
|
|
5315
|
-
options: {
|
|
5316
|
-
hotkey: ['mod+u']
|
|
5317
|
-
},
|
|
5641
|
+
var createSubscriptPlugin = function createSubscriptPlugin() {
|
|
5642
|
+
return plateBasicMarks.createSubscriptPlugin({
|
|
5643
|
+
type: Contentful.MARKS.SUBSCRIPT,
|
|
5644
|
+
component: Subscript,
|
|
5318
5645
|
handlers: {
|
|
5319
|
-
onKeyDown: buildMarkEventHandler(Contentful.MARKS.
|
|
5646
|
+
onKeyDown: buildMarkEventHandler(Contentful.MARKS.SUBSCRIPT)
|
|
5320
5647
|
},
|
|
5321
5648
|
deserializeHtml: {
|
|
5322
5649
|
rules: [{
|
|
5323
|
-
validNodeName: ['
|
|
5324
|
-
}
|
|
5325
|
-
validStyle: {
|
|
5326
|
-
textDecoration: ['underline']
|
|
5327
|
-
}
|
|
5328
|
-
}],
|
|
5329
|
-
query: function query(el) {
|
|
5330
|
-
return !plateCore.someHtmlElement(el, function (node) {
|
|
5331
|
-
return node.style.textDecoration === 'none';
|
|
5332
|
-
});
|
|
5333
|
-
}
|
|
5650
|
+
validNodeName: ['SUB']
|
|
5651
|
+
}]
|
|
5334
5652
|
}
|
|
5335
5653
|
});
|
|
5336
5654
|
};
|
|
5337
5655
|
|
|
5338
|
-
var styles$
|
|
5656
|
+
var styles$h = {
|
|
5339
5657
|
superscript: /*#__PURE__*/emotion.css({
|
|
5340
5658
|
verticalAlign: 'super',
|
|
5341
5659
|
fontSize: 'smaller'
|
|
@@ -5352,7 +5670,7 @@ var ToolbarDropdownSuperscriptButton = /*#__PURE__*/createMarkToolbarButton({
|
|
|
5352
5670
|
});
|
|
5353
5671
|
function Superscript(props) {
|
|
5354
5672
|
return /*#__PURE__*/React.createElement("sup", _extends({}, props.attributes, {
|
|
5355
|
-
className: styles$
|
|
5673
|
+
className: styles$h.superscript
|
|
5356
5674
|
}), props.children);
|
|
5357
5675
|
}
|
|
5358
5676
|
var createSuperscriptPlugin = function createSuperscriptPlugin() {
|
|
@@ -5370,39 +5688,37 @@ var createSuperscriptPlugin = function createSuperscriptPlugin() {
|
|
|
5370
5688
|
});
|
|
5371
5689
|
};
|
|
5372
5690
|
|
|
5373
|
-
var
|
|
5374
|
-
|
|
5375
|
-
|
|
5376
|
-
|
|
5377
|
-
})
|
|
5378
|
-
};
|
|
5379
|
-
var ToolbarSubscriptButton = /*#__PURE__*/createMarkToolbarButton({
|
|
5380
|
-
title: 'Subscript',
|
|
5381
|
-
mark: Contentful.MARKS.SUBSCRIPT,
|
|
5382
|
-
icon: /*#__PURE__*/React.createElement(f36Icons.SubscriptIcon, {
|
|
5383
|
-
viewBox: "0 0 23 18"
|
|
5384
|
-
})
|
|
5385
|
-
});
|
|
5386
|
-
var ToolbarDropdownSubscriptButton = /*#__PURE__*/createMarkToolbarButton({
|
|
5387
|
-
title: 'Subscript',
|
|
5388
|
-
mark: Contentful.MARKS.SUBSCRIPT
|
|
5691
|
+
var ToolbarUnderlineButton = /*#__PURE__*/createMarkToolbarButton({
|
|
5692
|
+
title: 'Underline',
|
|
5693
|
+
mark: Contentful.MARKS.UNDERLINE,
|
|
5694
|
+
icon: /*#__PURE__*/React.createElement(f36Icons.FormatUnderlinedIcon, null)
|
|
5389
5695
|
});
|
|
5390
|
-
function
|
|
5391
|
-
return /*#__PURE__*/React.createElement("
|
|
5392
|
-
className: styles$h.subscript
|
|
5393
|
-
}), props.children);
|
|
5696
|
+
function Underline(props) {
|
|
5697
|
+
return /*#__PURE__*/React.createElement("u", _extends({}, props.attributes), props.children);
|
|
5394
5698
|
}
|
|
5395
|
-
var
|
|
5396
|
-
return plateBasicMarks.
|
|
5397
|
-
type: Contentful.MARKS.
|
|
5398
|
-
component:
|
|
5699
|
+
var createUnderlinePlugin = function createUnderlinePlugin() {
|
|
5700
|
+
return plateBasicMarks.createUnderlinePlugin({
|
|
5701
|
+
type: Contentful.MARKS.UNDERLINE,
|
|
5702
|
+
component: Underline,
|
|
5703
|
+
options: {
|
|
5704
|
+
hotkey: ['mod+u']
|
|
5705
|
+
},
|
|
5399
5706
|
handlers: {
|
|
5400
|
-
onKeyDown: buildMarkEventHandler(Contentful.MARKS.
|
|
5707
|
+
onKeyDown: buildMarkEventHandler(Contentful.MARKS.UNDERLINE)
|
|
5401
5708
|
},
|
|
5402
5709
|
deserializeHtml: {
|
|
5403
5710
|
rules: [{
|
|
5404
|
-
validNodeName: ['
|
|
5405
|
-
}
|
|
5711
|
+
validNodeName: ['U']
|
|
5712
|
+
}, {
|
|
5713
|
+
validStyle: {
|
|
5714
|
+
textDecoration: ['underline']
|
|
5715
|
+
}
|
|
5716
|
+
}],
|
|
5717
|
+
query: function query(el) {
|
|
5718
|
+
return !someHtmlElement(el, function (node) {
|
|
5719
|
+
return node.style.textDecoration === 'none';
|
|
5720
|
+
});
|
|
5721
|
+
}
|
|
5406
5722
|
}
|
|
5407
5723
|
});
|
|
5408
5724
|
};
|
|
@@ -5414,7 +5730,7 @@ var createMarksPlugin = function createMarksPlugin() {
|
|
|
5414
5730
|
};
|
|
5415
5731
|
};
|
|
5416
5732
|
|
|
5417
|
-
var isInline = function isInline(node) {
|
|
5733
|
+
var isInline$1 = function isInline(node) {
|
|
5418
5734
|
return INLINE_TYPES.includes(node.type);
|
|
5419
5735
|
};
|
|
5420
5736
|
|
|
@@ -5426,13 +5742,13 @@ var isTextContainer = function isTextContainer(node) {
|
|
|
5426
5742
|
|
|
5427
5743
|
var baseRules = [{
|
|
5428
5744
|
// Wrap orphaned text nodes in a paragraph
|
|
5429
|
-
match:
|
|
5745
|
+
match: isText,
|
|
5430
5746
|
validNode: function validNode(editor, _ref) {
|
|
5431
|
-
var
|
|
5747
|
+
var _getParentNode;
|
|
5432
5748
|
|
|
5433
5749
|
var path = _ref[1];
|
|
5434
|
-
var parent = (
|
|
5435
|
-
return !!parent && (isTextContainer(parent) || isInline(parent) || editor.isVoid(parent));
|
|
5750
|
+
var parent = (_getParentNode = getParentNode(editor, path)) == null ? void 0 : _getParentNode[0];
|
|
5751
|
+
return !!parent && (isTextContainer(parent) || isInline$1(parent) || editor.isVoid(parent));
|
|
5436
5752
|
},
|
|
5437
5753
|
transform: function transform(editor, entry) {
|
|
5438
5754
|
return transformWrapIn(Contentful.BLOCKS.PARAGRAPH)(editor, entry);
|
|
@@ -5443,10 +5759,10 @@ var baseRules = [{
|
|
|
5443
5759
|
type: INLINE_TYPES
|
|
5444
5760
|
},
|
|
5445
5761
|
validNode: function validNode(editor, _ref2) {
|
|
5446
|
-
var
|
|
5762
|
+
var _getParentNode2;
|
|
5447
5763
|
|
|
5448
5764
|
var path = _ref2[1];
|
|
5449
|
-
var parent = (
|
|
5765
|
+
var parent = (_getParentNode2 = getParentNode(editor, path)) == null ? void 0 : _getParentNode2[0];
|
|
5450
5766
|
return !!parent && isTextContainer(parent);
|
|
5451
5767
|
},
|
|
5452
5768
|
transform: /*#__PURE__*/transformWrapIn(Contentful.BLOCKS.PARAGRAPH)
|
|
@@ -5464,19 +5780,9 @@ var NormalizerError = /*#__PURE__*/function (_Error) {
|
|
|
5464
5780
|
var createValidatorFromTypes = function createValidatorFromTypes(types) {
|
|
5465
5781
|
return function (_, _ref) {
|
|
5466
5782
|
var node = _ref[0];
|
|
5467
|
-
return
|
|
5783
|
+
return isElement(node) && types.includes(node.type);
|
|
5468
5784
|
};
|
|
5469
5785
|
};
|
|
5470
|
-
var getChildren = function getChildren(editor, _ref2) {
|
|
5471
|
-
var node = _ref2[0],
|
|
5472
|
-
path = _ref2[1];
|
|
5473
|
-
|
|
5474
|
-
if (slate.Text.isText(node)) {
|
|
5475
|
-
return [];
|
|
5476
|
-
}
|
|
5477
|
-
|
|
5478
|
-
return Array.from(slate.Node.children(editor, path));
|
|
5479
|
-
};
|
|
5480
5786
|
var createTransformerFromObject = function createTransformerFromObject(transforms) {
|
|
5481
5787
|
// A default transformer must always be provided
|
|
5482
5788
|
var fallback = transforms['default'];
|
|
@@ -5487,7 +5793,7 @@ var createTransformerFromObject = function createTransformerFromObject(transform
|
|
|
5487
5793
|
|
|
5488
5794
|
return function (editor, entry) {
|
|
5489
5795
|
var node = entry[0];
|
|
5490
|
-
var key =
|
|
5796
|
+
var key = isElement(node) ? node.type : 'default';
|
|
5491
5797
|
var transformer = transforms[key] || fallback;
|
|
5492
5798
|
return transformer(editor, entry);
|
|
5493
5799
|
};
|
|
@@ -5497,8 +5803,8 @@ var withNormalizer = function withNormalizer(editor) {
|
|
|
5497
5803
|
var rules = baseRules; // Derive normalization rules from other plugin's configurations
|
|
5498
5804
|
|
|
5499
5805
|
for (var _iterator = _createForOfIteratorHelperLoose(editor.plugins), _step; !(_step = _iterator()).done;) {
|
|
5500
|
-
var p = _step.value;
|
|
5501
|
-
var _rules = p.normalizer;
|
|
5806
|
+
var p$1 = _step.value;
|
|
5807
|
+
var _rules = p$1.normalizer;
|
|
5502
5808
|
|
|
5503
5809
|
if (!_rules) {
|
|
5504
5810
|
continue;
|
|
@@ -5510,14 +5816,14 @@ var withNormalizer = function withNormalizer(editor) {
|
|
|
5510
5816
|
// Clone to avoid mutation bugs
|
|
5511
5817
|
var rule = _extends({}, _rule);
|
|
5512
5818
|
|
|
5513
|
-
if (!rule.match && !p.isElement) {
|
|
5819
|
+
if (!rule.match && !p$1.isElement) {
|
|
5514
5820
|
throw new NormalizerError('rule.match MUST be defined in a non-element plugin');
|
|
5515
5821
|
} // By default we filter elements with given plugin type
|
|
5516
5822
|
|
|
5517
5823
|
|
|
5518
5824
|
if (!rule.match) {
|
|
5519
5825
|
rule.match = {
|
|
5520
|
-
type:
|
|
5826
|
+
type: p.getPluginType(editor, p$1.key)
|
|
5521
5827
|
};
|
|
5522
5828
|
} // Conditional transformation e.g.
|
|
5523
5829
|
// {
|
|
@@ -5555,22 +5861,23 @@ var withNormalizer = function withNormalizer(editor) {
|
|
|
5555
5861
|
|
|
5556
5862
|
|
|
5557
5863
|
var _transform = function _transform(tr, entry) {
|
|
5558
|
-
|
|
5864
|
+
withoutNormalizing(editor, function () {
|
|
5559
5865
|
tr(editor, entry);
|
|
5560
5866
|
});
|
|
5561
5867
|
};
|
|
5562
5868
|
|
|
5563
|
-
var normalizeNode = editor.normalizeNode;
|
|
5869
|
+
var normalizeNode = editor.normalizeNode; // @ts-expect-error
|
|
5564
5870
|
|
|
5565
5871
|
editor.normalizeNode = function (entry) {
|
|
5566
|
-
var node = entry[0]
|
|
5567
|
-
|
|
5872
|
+
var node = entry[0],
|
|
5873
|
+
path = entry[1];
|
|
5874
|
+
var children = getChildren(entry); // The order of validNode rules Vs validChildren doesn't matter. Slate
|
|
5568
5875
|
// will always perform normalization in a depth-first fashion.
|
|
5569
5876
|
|
|
5570
5877
|
for (var _iterator2 = _createForOfIteratorHelperLoose(rules), _step2; !(_step2 = _iterator2()).done;) {
|
|
5571
5878
|
var rule = _step2.value;
|
|
5572
5879
|
|
|
5573
|
-
if (!
|
|
5880
|
+
if (!matchNode(node, path, rule.match)) {
|
|
5574
5881
|
continue;
|
|
5575
5882
|
} // Normalize node
|
|
5576
5883
|
|
|
@@ -5612,7 +5919,6 @@ var withNormalizer = function withNormalizer(editor) {
|
|
|
5612
5919
|
var createNormalizerPlugin = function createNormalizerPlugin() {
|
|
5613
5920
|
return {
|
|
5614
5921
|
key: 'NormalizerPlugin',
|
|
5615
|
-
// @ts-expect-error
|
|
5616
5922
|
withOverrides: withNormalizer
|
|
5617
5923
|
};
|
|
5618
5924
|
};
|
|
@@ -5820,7 +6126,7 @@ var createPasteHTMLPlugin = function createPasteHTMLPlugin() {
|
|
|
5820
6126
|
return editor;
|
|
5821
6127
|
},
|
|
5822
6128
|
inject: {
|
|
5823
|
-
pluginsByKey: (_pluginsByKey = {}, _pluginsByKey[
|
|
6129
|
+
pluginsByKey: (_pluginsByKey = {}, _pluginsByKey[p.KEY_DESERIALIZE_HTML] = {
|
|
5824
6130
|
editor: {
|
|
5825
6131
|
insertData: {
|
|
5826
6132
|
format: 'text/html',
|
|
@@ -5853,7 +6159,7 @@ function Quote(props) {
|
|
|
5853
6159
|
*/
|
|
5854
6160
|
|
|
5855
6161
|
var shouldResetQuoteOnBackspace = function shouldResetQuoteOnBackspace(editor) {
|
|
5856
|
-
var container =
|
|
6162
|
+
var container = getAboveNode(editor, {
|
|
5857
6163
|
match: {
|
|
5858
6164
|
type: Contentful.TEXT_CONTAINERS
|
|
5859
6165
|
},
|
|
@@ -5864,11 +6170,11 @@ var shouldResetQuoteOnBackspace = function shouldResetQuoteOnBackspace(editor) {
|
|
|
5864
6170
|
return false;
|
|
5865
6171
|
}
|
|
5866
6172
|
|
|
5867
|
-
if (!
|
|
6173
|
+
if (!isAncestorEmpty(editor, container[0])) {
|
|
5868
6174
|
return false;
|
|
5869
6175
|
}
|
|
5870
6176
|
|
|
5871
|
-
var quote =
|
|
6177
|
+
var quote = getBlockAbove(editor, {
|
|
5872
6178
|
match: {
|
|
5873
6179
|
type: Contentful.BLOCKS.QUOTE
|
|
5874
6180
|
},
|
|
@@ -5879,7 +6185,7 @@ var shouldResetQuoteOnBackspace = function shouldResetQuoteOnBackspace(editor) {
|
|
|
5879
6185
|
return false;
|
|
5880
6186
|
}
|
|
5881
6187
|
|
|
5882
|
-
if (
|
|
6188
|
+
if (p.hasSingleChild(quote[0]) && p.isLastChild(quote, container[1])) {
|
|
5883
6189
|
return true;
|
|
5884
6190
|
}
|
|
5885
6191
|
|
|
@@ -5892,11 +6198,11 @@ function toggleQuote(editor, logAction) {
|
|
|
5892
6198
|
logAction == null ? void 0 : logAction(isActive ? 'remove' : 'insert', {
|
|
5893
6199
|
nodeType: Contentful.BLOCKS.QUOTE
|
|
5894
6200
|
});
|
|
5895
|
-
|
|
6201
|
+
withoutNormalizing(editor, function () {
|
|
5896
6202
|
if (!editor.selection) return;
|
|
5897
|
-
|
|
6203
|
+
unwrapNodes(editor, {
|
|
5898
6204
|
match: function match(node) {
|
|
5899
|
-
return
|
|
6205
|
+
return isElement(node) && node.type === Contentful.BLOCKS.QUOTE;
|
|
5900
6206
|
},
|
|
5901
6207
|
split: true
|
|
5902
6208
|
});
|
|
@@ -5907,7 +6213,7 @@ function toggleQuote(editor, logAction) {
|
|
|
5907
6213
|
data: {},
|
|
5908
6214
|
children: []
|
|
5909
6215
|
};
|
|
5910
|
-
|
|
6216
|
+
wrapNodes(editor, quote);
|
|
5911
6217
|
}
|
|
5912
6218
|
});
|
|
5913
6219
|
}
|
|
@@ -5927,39 +6233,39 @@ var withQuote = function withQuote(editor) {
|
|
|
5927
6233
|
|
|
5928
6234
|
editor.insertFragment = function (fragment) {
|
|
5929
6235
|
var startingNode = fragment.length && fragment[0];
|
|
5930
|
-
var startsWithBlockquote =
|
|
5931
|
-
var containerEntry =
|
|
6236
|
+
var startsWithBlockquote = s.Element.isElement(startingNode) && startingNode.type === Contentful.BLOCKS.QUOTE;
|
|
6237
|
+
var containerEntry = getAboveNode(editor, {
|
|
5932
6238
|
match: {
|
|
5933
6239
|
type: Contentful.TEXT_CONTAINERS
|
|
5934
6240
|
}
|
|
5935
6241
|
});
|
|
5936
|
-
var containerIsNotEmpty = containerEntry &&
|
|
6242
|
+
var containerIsNotEmpty = containerEntry && getText(editor, containerEntry[1]) !== '';
|
|
5937
6243
|
|
|
5938
6244
|
if (startsWithBlockquote && containerIsNotEmpty) {
|
|
5939
6245
|
var selection = editor.selection;
|
|
5940
6246
|
|
|
5941
6247
|
var isContentSelected = function isContentSelected(selection) {
|
|
5942
|
-
return !!selection &&
|
|
6248
|
+
return !!selection && s.Point.compare(selection.anchor, selection.focus) !== 0;
|
|
5943
6249
|
}; // if something is selected (highlighted) we replace the selection
|
|
5944
6250
|
|
|
5945
6251
|
|
|
5946
6252
|
if (isContentSelected(selection)) {
|
|
5947
|
-
|
|
6253
|
+
deleteText(editor, {
|
|
5948
6254
|
at: selection
|
|
5949
6255
|
});
|
|
5950
6256
|
} // get the cursor entry again, it may be different after deletion
|
|
5951
6257
|
|
|
5952
6258
|
|
|
5953
|
-
var _containerEntry =
|
|
6259
|
+
var _containerEntry = getAboveNode(editor, {
|
|
5954
6260
|
match: {
|
|
5955
6261
|
type: Contentful.TEXT_CONTAINERS
|
|
5956
6262
|
}
|
|
5957
6263
|
});
|
|
5958
6264
|
|
|
5959
|
-
var _containerIsNotEmpty = _containerEntry &&
|
|
6265
|
+
var _containerIsNotEmpty = _containerEntry && getText(editor, _containerEntry[1]) !== '';
|
|
5960
6266
|
|
|
5961
6267
|
if (_containerIsNotEmpty) {
|
|
5962
|
-
|
|
6268
|
+
insertNodes(editor, fragment);
|
|
5963
6269
|
return;
|
|
5964
6270
|
}
|
|
5965
6271
|
}
|
|
@@ -6034,15 +6340,17 @@ var createSelectOnBackspacePlugin = function createSelectOnBackspacePlugin() {
|
|
|
6034
6340
|
});
|
|
6035
6341
|
};
|
|
6036
6342
|
|
|
6343
|
+
var useReadOnly = Slate.useReadOnly;
|
|
6344
|
+
|
|
6037
6345
|
var addRow = function addRow(editor, getNextRowPath) {
|
|
6038
|
-
if (
|
|
6346
|
+
if (someNode(editor, {
|
|
6039
6347
|
match: {
|
|
6040
|
-
type:
|
|
6348
|
+
type: Contentful.BLOCKS.TABLE
|
|
6041
6349
|
}
|
|
6042
6350
|
})) {
|
|
6043
|
-
var currentRowItem =
|
|
6351
|
+
var currentRowItem = getAboveNode(editor, {
|
|
6044
6352
|
match: {
|
|
6045
|
-
type:
|
|
6353
|
+
type: Contentful.BLOCKS.TABLE_ROW
|
|
6046
6354
|
}
|
|
6047
6355
|
});
|
|
6048
6356
|
|
|
@@ -6050,8 +6358,7 @@ var addRow = function addRow(editor, getNextRowPath) {
|
|
|
6050
6358
|
var currentRowElem = currentRowItem[0],
|
|
6051
6359
|
currentRowPath = currentRowItem[1];
|
|
6052
6360
|
var nextRowPath = getNextRowPath(currentRowPath);
|
|
6053
|
-
|
|
6054
|
-
plateTable.getEmptyRowNode(editor, {
|
|
6361
|
+
insertNodes(editor, plateTable.getEmptyRowNode(editor, {
|
|
6055
6362
|
header: false,
|
|
6056
6363
|
colCount: currentRowElem.children.length
|
|
6057
6364
|
}), {
|
|
@@ -6060,14 +6367,14 @@ var addRow = function addRow(editor, getNextRowPath) {
|
|
|
6060
6367
|
select: true
|
|
6061
6368
|
}); // Select the first cell in the current row
|
|
6062
6369
|
|
|
6063
|
-
|
|
6370
|
+
select(editor, getStartPoint(editor, nextRowPath));
|
|
6064
6371
|
}
|
|
6065
6372
|
}
|
|
6066
6373
|
};
|
|
6067
6374
|
|
|
6068
6375
|
var addRowBelow = function addRowBelow(editor) {
|
|
6069
6376
|
addRow(editor, function (currentRowPath) {
|
|
6070
|
-
return
|
|
6377
|
+
return getNextPath(currentRowPath);
|
|
6071
6378
|
});
|
|
6072
6379
|
};
|
|
6073
6380
|
var addRowAbove = function addRowAbove(editor) {
|
|
@@ -6080,19 +6387,19 @@ var addRowAbove = function addRowAbove(editor) {
|
|
|
6080
6387
|
var addColumn = function addColumn(editor, _ref, getNextCellPath) {
|
|
6081
6388
|
var header = _ref.header;
|
|
6082
6389
|
|
|
6083
|
-
if (
|
|
6390
|
+
if (someNode(editor, {
|
|
6084
6391
|
match: {
|
|
6085
|
-
type:
|
|
6392
|
+
type: Contentful.BLOCKS.TABLE
|
|
6086
6393
|
}
|
|
6087
6394
|
})) {
|
|
6088
|
-
var currentCellItem =
|
|
6395
|
+
var currentCellItem = getAboveNode(editor, {
|
|
6089
6396
|
match: {
|
|
6090
|
-
type: [
|
|
6397
|
+
type: [Contentful.BLOCKS.TABLE_HEADER_CELL, Contentful.BLOCKS.TABLE_CELL]
|
|
6091
6398
|
}
|
|
6092
6399
|
});
|
|
6093
|
-
var currentTableItem =
|
|
6400
|
+
var currentTableItem = getAboveNode(editor, {
|
|
6094
6401
|
match: {
|
|
6095
|
-
type:
|
|
6402
|
+
type: Contentful.BLOCKS.TABLE
|
|
6096
6403
|
}
|
|
6097
6404
|
});
|
|
6098
6405
|
|
|
@@ -6102,8 +6409,7 @@ var addColumn = function addColumn(editor, _ref, getNextCellPath) {
|
|
|
6102
6409
|
var replacePathPos = newCellPath.length - 2;
|
|
6103
6410
|
currentTableItem[0].children.forEach(function (_, rowIdx) {
|
|
6104
6411
|
newCellPath[replacePathPos] = rowIdx;
|
|
6105
|
-
|
|
6106
|
-
plateTable.getEmptyCellNode(editor, {
|
|
6412
|
+
insertNodes(editor, plateTable.getEmptyCellNode(editor, {
|
|
6107
6413
|
header: header && rowIdx === 0
|
|
6108
6414
|
}), {
|
|
6109
6415
|
at: newCellPath,
|
|
@@ -6117,7 +6423,7 @@ var addColumn = function addColumn(editor, _ref, getNextCellPath) {
|
|
|
6117
6423
|
|
|
6118
6424
|
var addColumnRight = function addColumnRight(editor, options) {
|
|
6119
6425
|
addColumn(editor, options, function (currentCellPath) {
|
|
6120
|
-
return
|
|
6426
|
+
return getNextPath(currentCellPath);
|
|
6121
6427
|
});
|
|
6122
6428
|
};
|
|
6123
6429
|
var addColumnLeft = function addColumnLeft(editor, options) {
|
|
@@ -6127,7 +6433,7 @@ var addColumnLeft = function addColumnLeft(editor, options) {
|
|
|
6127
6433
|
};
|
|
6128
6434
|
|
|
6129
6435
|
var setHeader = function setHeader(editor, enable) {
|
|
6130
|
-
var tableItem =
|
|
6436
|
+
var tableItem = getAboveNode(editor, {
|
|
6131
6437
|
match: {
|
|
6132
6438
|
type: Contentful.BLOCKS.TABLE
|
|
6133
6439
|
}
|
|
@@ -6137,15 +6443,15 @@ var setHeader = function setHeader(editor, enable) {
|
|
|
6137
6443
|
return;
|
|
6138
6444
|
}
|
|
6139
6445
|
|
|
6140
|
-
var firstRow =
|
|
6446
|
+
var firstRow = getChildren(tableItem)[0];
|
|
6141
6447
|
|
|
6142
6448
|
if (!firstRow) {
|
|
6143
6449
|
return;
|
|
6144
6450
|
}
|
|
6145
6451
|
|
|
6146
|
-
|
|
6452
|
+
getChildren(firstRow).forEach(function (_ref) {
|
|
6147
6453
|
var path = _ref[1];
|
|
6148
|
-
|
|
6454
|
+
setNodes(editor, {
|
|
6149
6455
|
type: enable ? Contentful.BLOCKS.TABLE_HEADER_CELL : Contentful.BLOCKS.TABLE_CELL
|
|
6150
6456
|
}, {
|
|
6151
6457
|
at: path
|
|
@@ -6154,9 +6460,30 @@ var setHeader = function setHeader(editor, enable) {
|
|
|
6154
6460
|
};
|
|
6155
6461
|
|
|
6156
6462
|
function insertTableAndFocusFirstCell(editor) {
|
|
6157
|
-
|
|
6158
|
-
|
|
6159
|
-
|
|
6463
|
+
var table = {
|
|
6464
|
+
type: Contentful.BLOCKS.TABLE,
|
|
6465
|
+
data: {},
|
|
6466
|
+
children: [plateTable.getEmptyRowNode(editor, {
|
|
6467
|
+
colCount: 2,
|
|
6468
|
+
header: true
|
|
6469
|
+
}), plateTable.getEmptyRowNode(editor, {
|
|
6470
|
+
colCount: 2
|
|
6471
|
+
})]
|
|
6472
|
+
};
|
|
6473
|
+
insertNodes(editor, table);
|
|
6474
|
+
|
|
6475
|
+
if (editor.selection) {
|
|
6476
|
+
var tableEntry = getBlockAbove(editor, {
|
|
6477
|
+
match: {
|
|
6478
|
+
type: Contentful.BLOCKS.TABLE
|
|
6479
|
+
}
|
|
6480
|
+
});
|
|
6481
|
+
if (!tableEntry) return;
|
|
6482
|
+
selectEditor(editor, {
|
|
6483
|
+
at: getStartPoint(editor, tableEntry[1])
|
|
6484
|
+
});
|
|
6485
|
+
}
|
|
6486
|
+
|
|
6160
6487
|
replaceEmptyParagraphWithTable(editor);
|
|
6161
6488
|
}
|
|
6162
6489
|
function isTableActive(editor) {
|
|
@@ -6166,7 +6493,7 @@ function isTableActive(editor) {
|
|
|
6166
6493
|
});
|
|
6167
6494
|
}
|
|
6168
6495
|
function isTableHeaderEnabled(editor) {
|
|
6169
|
-
var tableItem =
|
|
6496
|
+
var tableItem = getAboveNode(editor, {
|
|
6170
6497
|
match: {
|
|
6171
6498
|
type: Contentful.BLOCKS.TABLE
|
|
6172
6499
|
}
|
|
@@ -6176,43 +6503,43 @@ function isTableHeaderEnabled(editor) {
|
|
|
6176
6503
|
return false;
|
|
6177
6504
|
}
|
|
6178
6505
|
|
|
6179
|
-
var firstRow =
|
|
6506
|
+
var firstRow = getChildren(tableItem)[0];
|
|
6180
6507
|
|
|
6181
6508
|
if (!firstRow) {
|
|
6182
6509
|
return false;
|
|
6183
6510
|
}
|
|
6184
6511
|
|
|
6185
|
-
return
|
|
6512
|
+
return getChildren(firstRow).every(function (_ref) {
|
|
6186
6513
|
var node = _ref[0];
|
|
6187
6514
|
return node.type === Contentful.BLOCKS.TABLE_HEADER_CELL;
|
|
6188
6515
|
});
|
|
6189
6516
|
}
|
|
6190
6517
|
function replaceEmptyParagraphWithTable(editor) {
|
|
6191
6518
|
var tablePath = getAncestorPathFromSelection(editor);
|
|
6192
|
-
if (!tablePath ||
|
|
6193
|
-
var previousPath =
|
|
6519
|
+
if (!tablePath || isFirstChildPath(tablePath)) return;
|
|
6520
|
+
var previousPath = getPreviousPath(tablePath);
|
|
6194
6521
|
if (!previousPath) return;
|
|
6195
6522
|
|
|
6196
|
-
var
|
|
6523
|
+
var _getNodeEntries = getNodeEntries(editor, {
|
|
6197
6524
|
at: previousPath,
|
|
6198
6525
|
match: function match(node) {
|
|
6199
6526
|
return node.type === Contentful.BLOCKS.PARAGRAPH;
|
|
6200
6527
|
}
|
|
6201
6528
|
}),
|
|
6202
|
-
nodes =
|
|
6529
|
+
nodes = _getNodeEntries[0];
|
|
6203
6530
|
|
|
6204
6531
|
if (!nodes) return;
|
|
6205
6532
|
var previousNode = nodes[0];
|
|
6206
|
-
var isPreviousNodeTextEmpty =
|
|
6533
|
+
var isPreviousNodeTextEmpty = isAncestorEmpty(editor, previousNode);
|
|
6207
6534
|
|
|
6208
6535
|
if (isPreviousNodeTextEmpty) {
|
|
6209
6536
|
// Switch table with previous empty paragraph
|
|
6210
|
-
|
|
6537
|
+
moveNodes(editor, {
|
|
6211
6538
|
at: tablePath,
|
|
6212
6539
|
to: previousPath
|
|
6213
6540
|
}); // Remove previous paragraph that now is under the table
|
|
6214
6541
|
|
|
6215
|
-
|
|
6542
|
+
removeNodes(editor, {
|
|
6216
6543
|
at: tablePath
|
|
6217
6544
|
});
|
|
6218
6545
|
}
|
|
@@ -6224,21 +6551,19 @@ function replaceEmptyParagraphWithTable(editor) {
|
|
|
6224
6551
|
* normalization cycles.
|
|
6225
6552
|
*/
|
|
6226
6553
|
|
|
6227
|
-
var getNoOfMissingTableCellsInRow = function getNoOfMissingTableCellsInRow(editor,
|
|
6228
|
-
var rowPath =
|
|
6229
|
-
var parent =
|
|
6554
|
+
var getNoOfMissingTableCellsInRow = function getNoOfMissingTableCellsInRow(editor, rowEntry) {
|
|
6555
|
+
var rowPath = rowEntry[1];
|
|
6556
|
+
var parent = getParentNode(editor, rowPath); // This is ensured by normalization. The error is here just in case
|
|
6230
6557
|
|
|
6231
6558
|
if (!parent) {
|
|
6232
6559
|
throw new Error('table rows must be wrapped in a table node');
|
|
6233
|
-
}
|
|
6560
|
+
} // The longest table row determines its width
|
|
6234
6561
|
|
|
6235
|
-
var tablePath = parent[1]; // The longest table row determines its width
|
|
6236
6562
|
|
|
6237
|
-
var tableWidth = Math.max.apply(Math,
|
|
6238
|
-
|
|
6239
|
-
return Array.from(slate.Node.children(editor, path)).length;
|
|
6563
|
+
var tableWidth = Math.max.apply(Math, getChildren(parent).map(function (entry) {
|
|
6564
|
+
return getChildren(entry).length;
|
|
6240
6565
|
}));
|
|
6241
|
-
var rowWidth =
|
|
6566
|
+
var rowWidth = getChildren(rowEntry).length;
|
|
6242
6567
|
return tableWidth - rowWidth;
|
|
6243
6568
|
};
|
|
6244
6569
|
var createEmptyTableCells = function createEmptyTableCells(count) {
|
|
@@ -6255,12 +6580,11 @@ var createEmptyTableCells = function createEmptyTableCells(count) {
|
|
|
6255
6580
|
};
|
|
6256
6581
|
return new Array(count).fill(emptyTableCell);
|
|
6257
6582
|
};
|
|
6258
|
-
var isNotEmpty = function isNotEmpty(
|
|
6259
|
-
|
|
6260
|
-
return Array.from(slate.Node.children(editor, path)).length !== 0;
|
|
6583
|
+
var isNotEmpty = function isNotEmpty(_, entry) {
|
|
6584
|
+
return getChildren(entry).length !== 0;
|
|
6261
6585
|
};
|
|
6262
6586
|
var isTable = function isTable(node) {
|
|
6263
|
-
return
|
|
6587
|
+
return isElement(node) && node.type === Contentful.BLOCKS.TABLE;
|
|
6264
6588
|
};
|
|
6265
6589
|
|
|
6266
6590
|
var styles$j = {
|
|
@@ -6280,7 +6604,7 @@ var getCurrentTableSize = function getCurrentTableSize(editor) {
|
|
|
6280
6604
|
|
|
6281
6605
|
var TableActions = function TableActions() {
|
|
6282
6606
|
var editor = useContentfulEditor();
|
|
6283
|
-
var isDisabled =
|
|
6607
|
+
var isDisabled = useReadOnly();
|
|
6284
6608
|
|
|
6285
6609
|
var _React$useState = React__default.useState(false),
|
|
6286
6610
|
isOpen = _React$useState[0],
|
|
@@ -6301,7 +6625,7 @@ var TableActions = function TableActions() {
|
|
|
6301
6625
|
return false;
|
|
6302
6626
|
}
|
|
6303
6627
|
|
|
6304
|
-
var headerCell =
|
|
6628
|
+
var headerCell = getAboveNode(editor, {
|
|
6305
6629
|
match: {
|
|
6306
6630
|
type: Contentful.BLOCKS.TABLE_HEADER_CELL
|
|
6307
6631
|
}
|
|
@@ -6324,7 +6648,7 @@ var TableActions = function TableActions() {
|
|
|
6324
6648
|
if (!(editor != null && editor.selection)) return;
|
|
6325
6649
|
close();
|
|
6326
6650
|
var tableSize = getCurrentTableSize(editor);
|
|
6327
|
-
|
|
6651
|
+
withoutNormalizing(editor, function () {
|
|
6328
6652
|
cb(editor, {
|
|
6329
6653
|
header: isHeaderEnabled
|
|
6330
6654
|
});
|
|
@@ -6426,7 +6750,7 @@ var Table = function Table(props) {
|
|
|
6426
6750
|
var trimUnnecessaryTableWrapper = function trimUnnecessaryTableWrapper(node) {
|
|
6427
6751
|
var _node$children, _row$children;
|
|
6428
6752
|
|
|
6429
|
-
if (!
|
|
6753
|
+
if (!isElement(node)) {
|
|
6430
6754
|
return [node];
|
|
6431
6755
|
} // must be a table with a single row
|
|
6432
6756
|
|
|
@@ -6463,7 +6787,7 @@ var insertTableFragment = function insertTableFragment(editor) {
|
|
|
6463
6787
|
var isTableFirstFragment = fragments.findIndex(function (fragment) {
|
|
6464
6788
|
return isTable(fragment);
|
|
6465
6789
|
}) === 0;
|
|
6466
|
-
var currentLineHasText =
|
|
6790
|
+
var currentLineHasText = getText(editor, (_editor$selection = editor.selection) == null ? void 0 : _editor$selection.focus.path) !== '';
|
|
6467
6791
|
|
|
6468
6792
|
if (isInsertingTable && isTableFirstFragment && currentLineHasText) {
|
|
6469
6793
|
insertEmptyParagraph(editor);
|
|
@@ -6476,20 +6800,21 @@ var insertTableFragment = function insertTableFragment(editor) {
|
|
|
6476
6800
|
var onKeyDownTable = function onKeyDownTable(editor, plugin) {
|
|
6477
6801
|
var defaultHandler = plateTable.onKeyDownTable(editor, plugin);
|
|
6478
6802
|
return function (event) {
|
|
6479
|
-
// This fixes `Cannot resolve a Slate point from DOM point:
|
|
6803
|
+
// This fixes `Cannot resolve a Slate point from DOM point:
|
|
6804
|
+
// [object HTMLDivElement]` when typing while the cursor is before table
|
|
6480
6805
|
var windowSelection = window.getSelection();
|
|
6481
6806
|
|
|
6482
6807
|
if (windowSelection) {
|
|
6483
6808
|
var _windowSelection$anch, _windowSelection$anch2;
|
|
6484
6809
|
|
|
6485
6810
|
// @ts-expect-error
|
|
6486
|
-
|
|
6487
|
-
|
|
6811
|
+
// this attribute comes from `plugins/Table/components/Table.tsx`
|
|
6812
|
+
var blockType = (_windowSelection$anch = windowSelection.anchorNode.attributes) == null ? void 0 : (_windowSelection$anch2 = _windowSelection$anch['data-block-type']) == null ? void 0 : _windowSelection$anch2.value;
|
|
6488
6813
|
var isBeforeTable = blockType === Contentful.BLOCKS.TABLE;
|
|
6489
6814
|
|
|
6490
6815
|
if (isBeforeTable) {
|
|
6491
6816
|
if (event.key === 'Enter') {
|
|
6492
|
-
var above =
|
|
6817
|
+
var above = getAboveNode(editor, {
|
|
6493
6818
|
match: {
|
|
6494
6819
|
type: Contentful.BLOCKS.TABLE
|
|
6495
6820
|
}
|
|
@@ -6511,15 +6836,15 @@ var onKeyDownTable = function onKeyDownTable(editor, plugin) {
|
|
|
6511
6836
|
|
|
6512
6837
|
|
|
6513
6838
|
if (event.key === 'Tab' && !event.shiftKey) {
|
|
6514
|
-
|
|
6839
|
+
event.preventDefault();
|
|
6840
|
+
var entry = plateTable.getTableEntries(editor, {});
|
|
6515
6841
|
|
|
6516
|
-
if (
|
|
6517
|
-
|
|
6518
|
-
|
|
6519
|
-
|
|
6520
|
-
|
|
6521
|
-
var
|
|
6522
|
-
var isLastRow = plateCore.isLastChild(tableElement, tableRow[1]);
|
|
6842
|
+
if (entry) {
|
|
6843
|
+
var table = entry.table,
|
|
6844
|
+
row = entry.row,
|
|
6845
|
+
cell = entry.cell;
|
|
6846
|
+
var isLastCell = isLastChildPath(row, cell[1]);
|
|
6847
|
+
var isLastRow = isLastChildPath(table, row[1]);
|
|
6523
6848
|
|
|
6524
6849
|
if (isLastRow && isLastCell) {
|
|
6525
6850
|
addRowBelow(editor); // skip default handler
|
|
@@ -6532,7 +6857,7 @@ var onKeyDownTable = function onKeyDownTable(editor, plugin) {
|
|
|
6532
6857
|
}
|
|
6533
6858
|
|
|
6534
6859
|
if (event.key === 'Escape') {
|
|
6535
|
-
|
|
6860
|
+
blurEditor(editor);
|
|
6536
6861
|
}
|
|
6537
6862
|
};
|
|
6538
6863
|
};
|
|
@@ -6815,7 +7140,7 @@ var withInvalidCellChildrenTracking = function withInvalidCellChildrenTracking(t
|
|
|
6815
7140
|
return function (editor, childEntry) {
|
|
6816
7141
|
var node = childEntry[0];
|
|
6817
7142
|
|
|
6818
|
-
if (
|
|
7143
|
+
if (isElement(node)) {
|
|
6819
7144
|
var _editor$tracking;
|
|
6820
7145
|
|
|
6821
7146
|
(_editor$tracking = editor.tracking) == null ? void 0 : _editor$tracking.onViewportAction('invalidTablePaste', {
|
|
@@ -6833,11 +7158,16 @@ var createTablePlugin = function createTablePlugin() {
|
|
|
6833
7158
|
return plateTable.createTablePlugin({
|
|
6834
7159
|
type: Contentful.BLOCKS.TABLE,
|
|
6835
7160
|
handlers: {
|
|
7161
|
+
// @ts-expect-error
|
|
6836
7162
|
onKeyDown: onKeyDownTable
|
|
6837
7163
|
},
|
|
6838
7164
|
withOverrides: function withOverrides(editor, plugin) {
|
|
6839
|
-
// injects important fixes from plate's original table plugin
|
|
6840
|
-
|
|
7165
|
+
var normalizeNode = editor.normalizeNode; // injects important fixes from plate's original table plugin
|
|
7166
|
+
|
|
7167
|
+
plateTable.withTable(editor, plugin); // Resets all normalization rules added by @udecode/plate-table as
|
|
7168
|
+
// they conflict with our own
|
|
7169
|
+
|
|
7170
|
+
editor.normalizeNode = normalizeNode;
|
|
6841
7171
|
addTableTrackingEvents(editor);
|
|
6842
7172
|
editor.insertFragment = insertTableFragment(editor);
|
|
6843
7173
|
return editor;
|
|
@@ -6851,7 +7181,9 @@ var createTablePlugin = function createTablePlugin() {
|
|
|
6851
7181
|
// Move to root level unless nested
|
|
6852
7182
|
validNode: function validNode(editor, _ref) {
|
|
6853
7183
|
var path = _ref[1];
|
|
6854
|
-
|
|
7184
|
+
// Nested tables are handled by another normalization
|
|
7185
|
+
// rule in a the table cell level
|
|
7186
|
+
var isNestedTable = !!getBlockAbove(editor, {
|
|
6855
7187
|
at: path,
|
|
6856
7188
|
match: {
|
|
6857
7189
|
type: [Contentful.BLOCKS.TABLE_CELL, Contentful.BLOCKS.TABLE_HEADER_CELL]
|
|
@@ -6875,10 +7207,10 @@ var createTablePlugin = function createTablePlugin() {
|
|
|
6875
7207
|
}, {
|
|
6876
7208
|
// Parent must be a table
|
|
6877
7209
|
validNode: function validNode(editor, _ref2) {
|
|
6878
|
-
var
|
|
7210
|
+
var _getParentNode;
|
|
6879
7211
|
|
|
6880
7212
|
var path = _ref2[1];
|
|
6881
|
-
var parent = (
|
|
7213
|
+
var parent = (_getParentNode = getParentNode(editor, path)) == null ? void 0 : _getParentNode[0];
|
|
6882
7214
|
return parent && parent.type === Contentful.BLOCKS.TABLE;
|
|
6883
7215
|
},
|
|
6884
7216
|
transform: transformWrapIn(Contentful.BLOCKS.TABLE)
|
|
@@ -6889,8 +7221,8 @@ var createTablePlugin = function createTablePlugin() {
|
|
|
6889
7221
|
},
|
|
6890
7222
|
transform: function transform(editor, entry) {
|
|
6891
7223
|
var howMany = getNoOfMissingTableCellsInRow(editor, entry);
|
|
6892
|
-
var at =
|
|
6893
|
-
|
|
7224
|
+
var at = getNextPath(getLastChildPath(entry));
|
|
7225
|
+
insertNodes(editor, createEmptyTableCells(howMany), {
|
|
6894
7226
|
at: at
|
|
6895
7227
|
});
|
|
6896
7228
|
}
|
|
@@ -6955,7 +7287,7 @@ function ToolbarTableButton(props) {
|
|
|
6955
7287
|
testId: "table-toolbar-button",
|
|
6956
7288
|
onClick: handleClick,
|
|
6957
7289
|
// TODO: active state looks off since the button will be disabled. Do we still need it?
|
|
6958
|
-
isActive: isActive,
|
|
7290
|
+
isActive: !!isActive,
|
|
6959
7291
|
isDisabled: props.isDisabled
|
|
6960
7292
|
}, /*#__PURE__*/React.createElement(f36Icons.TableIcon, null));
|
|
6961
7293
|
}
|
|
@@ -6977,7 +7309,7 @@ function createTextPlugin(restrictedMarks) {
|
|
|
6977
7309
|
return;
|
|
6978
7310
|
}
|
|
6979
7311
|
|
|
6980
|
-
|
|
7312
|
+
setSelection(editor, unhangRange(editor, editor.selection));
|
|
6981
7313
|
};
|
|
6982
7314
|
}
|
|
6983
7315
|
},
|
|
@@ -6993,19 +7325,19 @@ function createTextPlugin(restrictedMarks) {
|
|
|
6993
7325
|
var selection = editor.selection; // If the cursor is at the end of an inline, move it outside
|
|
6994
7326
|
// before inserting
|
|
6995
7327
|
|
|
6996
|
-
if (selection &&
|
|
6997
|
-
var
|
|
7328
|
+
if (selection && isRangeCollapsed(selection)) {
|
|
7329
|
+
var _getAboveNode;
|
|
6998
7330
|
|
|
6999
|
-
var inlinePath = (
|
|
7331
|
+
var inlinePath = (_getAboveNode = getAboveNode(editor, {
|
|
7000
7332
|
match: function match(n) {
|
|
7001
|
-
return
|
|
7333
|
+
return isInline(editor, n);
|
|
7002
7334
|
},
|
|
7003
7335
|
mode: 'highest'
|
|
7004
|
-
})) == null ? void 0 :
|
|
7336
|
+
})) == null ? void 0 : _getAboveNode[1];
|
|
7005
7337
|
|
|
7006
|
-
if (inlinePath &&
|
|
7007
|
-
var point =
|
|
7008
|
-
|
|
7338
|
+
if (inlinePath && isEndPoint(editor, selection.anchor, inlinePath)) {
|
|
7339
|
+
var point = getPointAfter(editor, inlinePath);
|
|
7340
|
+
setSelection(editor, {
|
|
7009
7341
|
anchor: point,
|
|
7010
7342
|
focus: point
|
|
7011
7343
|
});
|
|
@@ -7031,10 +7363,10 @@ function createTextPlugin(restrictedMarks) {
|
|
|
7031
7363
|
return editor;
|
|
7032
7364
|
},
|
|
7033
7365
|
normalizer: [{
|
|
7034
|
-
match:
|
|
7366
|
+
match: isText,
|
|
7035
7367
|
transform: function transform(editor, _ref) {
|
|
7036
7368
|
var path = _ref[1];
|
|
7037
|
-
|
|
7369
|
+
unsetNodes(editor, restrictedMarks, {
|
|
7038
7370
|
at: path
|
|
7039
7371
|
});
|
|
7040
7372
|
},
|
|
@@ -7049,7 +7381,7 @@ function createTextPlugin(restrictedMarks) {
|
|
|
7049
7381
|
}
|
|
7050
7382
|
|
|
7051
7383
|
function deleteEmptyParagraph(unit, editor, deleteFunction) {
|
|
7052
|
-
var entry =
|
|
7384
|
+
var entry = getAboveNode(editor, {
|
|
7053
7385
|
match: {
|
|
7054
7386
|
type: Contentful.TEXT_CONTAINERS
|
|
7055
7387
|
}
|
|
@@ -7058,32 +7390,32 @@ function deleteEmptyParagraph(unit, editor, deleteFunction) {
|
|
|
7058
7390
|
if (entry) {
|
|
7059
7391
|
var paragraphOrHeading = entry[0],
|
|
7060
7392
|
path = entry[1];
|
|
7061
|
-
var isTextEmpty =
|
|
7393
|
+
var isTextEmpty = isAncestorEmpty(editor, paragraphOrHeading); // We ignore paragraphs/headings that are children of ul, ol, blockquote, tables, etc
|
|
7062
7394
|
|
|
7063
7395
|
var isRootLevel = path.length === 1;
|
|
7064
7396
|
var hasSiblings = editor.children.length > 1; // prevent editor from losing focus
|
|
7065
7397
|
|
|
7066
7398
|
if (isTextEmpty && isRootLevel && hasSiblings) {
|
|
7067
|
-
|
|
7399
|
+
removeNodes(editor, {
|
|
7068
7400
|
at: path
|
|
7069
7401
|
});
|
|
7070
|
-
var prevNode =
|
|
7402
|
+
var prevNode = getPointBefore(editor, editor.selection, {
|
|
7071
7403
|
unit: unit
|
|
7072
7404
|
});
|
|
7073
7405
|
|
|
7074
7406
|
if (prevNode) {
|
|
7075
|
-
var
|
|
7407
|
+
var _getNodeEntries = getNodeEntries(editor, {
|
|
7076
7408
|
match: function match(node) {
|
|
7077
|
-
return
|
|
7409
|
+
return queryNode([node, prevNode.path], {
|
|
7078
7410
|
allow: [Contentful.BLOCKS.EMBEDDED_ASSET, Contentful.BLOCKS.EMBEDDED_ENTRY, Contentful.BLOCKS.HR]
|
|
7079
7411
|
});
|
|
7080
7412
|
},
|
|
7081
7413
|
at: prevNode
|
|
7082
7414
|
}),
|
|
7083
|
-
prevCell =
|
|
7415
|
+
prevCell = _getNodeEntries[0];
|
|
7084
7416
|
|
|
7085
7417
|
if (prevCell) {
|
|
7086
|
-
|
|
7418
|
+
select(editor, prevNode);
|
|
7087
7419
|
}
|
|
7088
7420
|
}
|
|
7089
7421
|
} else {
|
|
@@ -7120,7 +7452,7 @@ function fixPasteAsPlainText(editor) {
|
|
|
7120
7452
|
}
|
|
7121
7453
|
|
|
7122
7454
|
if (split) {
|
|
7123
|
-
|
|
7455
|
+
splitNodes(editor, {
|
|
7124
7456
|
always: true
|
|
7125
7457
|
});
|
|
7126
7458
|
}
|
|
@@ -7154,7 +7486,7 @@ var createVoidsPlugin = function createVoidsPlugin() {
|
|
|
7154
7486
|
filter: function filter(_ref) {
|
|
7155
7487
|
var node = _ref[0],
|
|
7156
7488
|
path = _ref[1];
|
|
7157
|
-
return isRootLevel(path) &&
|
|
7489
|
+
return isRootLevel(path) && isFirstChildPath(path) && !!node.isVoid;
|
|
7158
7490
|
}
|
|
7159
7491
|
}
|
|
7160
7492
|
}, {
|
|
@@ -7167,7 +7499,7 @@ var createVoidsPlugin = function createVoidsPlugin() {
|
|
|
7167
7499
|
filter: function filter(_ref2) {
|
|
7168
7500
|
var node = _ref2[0],
|
|
7169
7501
|
path = _ref2[1];
|
|
7170
|
-
return !(isRootLevel(path) &&
|
|
7502
|
+
return !(isRootLevel(path) && isFirstChildPath(path)) && !!node.isVoid;
|
|
7171
7503
|
}
|
|
7172
7504
|
}
|
|
7173
7505
|
}]
|
|
@@ -7176,7 +7508,7 @@ var createVoidsPlugin = function createVoidsPlugin() {
|
|
|
7176
7508
|
|
|
7177
7509
|
var getPlugins = function getPlugins(sdk, onAction, restrictedMarks) {
|
|
7178
7510
|
return [// AST must come after the HTML deserializer
|
|
7179
|
-
|
|
7511
|
+
p.createDeserializeHtmlPlugin(), p.createDeserializeAstPlugin(), plateSerializerDocx.createDeserializeDocxPlugin(), // Tracking - This should come first so all plugins below will have access to `editor.tracking`
|
|
7180
7512
|
createTrackingPlugin(onAction), // Global / Global shortcuts
|
|
7181
7513
|
createDragAndDropPlugin(), createCommandPalettePlugin(), // Block Elements
|
|
7182
7514
|
createParagraphPlugin(), createListPlugin(), createHrPlugin(), createHeadingPlugin(), createQuotePlugin(), createTablePlugin(), createEmbeddedEntryBlockPlugin(sdk), createEmbeddedAssetBlockPlugin(sdk), // Inline elements
|
|
@@ -7254,7 +7586,7 @@ var hasContent = function hasContent(doc) {
|
|
|
7254
7586
|
|
|
7255
7587
|
var setEditorContent = function setEditorContent(editor, nodes) {
|
|
7256
7588
|
// Replaces editor content while keeping change history
|
|
7257
|
-
|
|
7589
|
+
withoutNormalizing(editor, function () {
|
|
7258
7590
|
var children = [].concat(editor.children);
|
|
7259
7591
|
children.forEach(function (node) {
|
|
7260
7592
|
return editor.apply({
|
|
@@ -7265,9 +7597,9 @@ var setEditorContent = function setEditorContent(editor, nodes) {
|
|
|
7265
7597
|
});
|
|
7266
7598
|
|
|
7267
7599
|
if (nodes) {
|
|
7268
|
-
var nodesArray =
|
|
7600
|
+
var nodesArray = isNode(nodes) ? [nodes] : nodes;
|
|
7269
7601
|
nodesArray.forEach(function (node, i) {
|
|
7270
|
-
|
|
7602
|
+
editor.apply({
|
|
7271
7603
|
type: 'insert_node',
|
|
7272
7604
|
path: [i],
|
|
7273
7605
|
node: node
|
|
@@ -7275,10 +7607,10 @@ var setEditorContent = function setEditorContent(editor, nodes) {
|
|
|
7275
7607
|
});
|
|
7276
7608
|
}
|
|
7277
7609
|
|
|
7278
|
-
var point =
|
|
7610
|
+
var point = getEndPoint(editor, []);
|
|
7279
7611
|
|
|
7280
7612
|
if (point) {
|
|
7281
|
-
|
|
7613
|
+
select(editor, point);
|
|
7282
7614
|
}
|
|
7283
7615
|
});
|
|
7284
7616
|
};
|
|
@@ -7296,9 +7628,9 @@ var documentToEditorValue = function documentToEditorValue(doc) {
|
|
|
7296
7628
|
return sanitizeIncomingSlateDoc(slateDoc);
|
|
7297
7629
|
};
|
|
7298
7630
|
var normalizeEditorValue = function normalizeEditorValue(value, options) {
|
|
7299
|
-
var editor =
|
|
7631
|
+
var editor = createPlateEditor(options);
|
|
7300
7632
|
editor.children = value;
|
|
7301
|
-
|
|
7633
|
+
normalize(editor, {
|
|
7302
7634
|
force: true
|
|
7303
7635
|
});
|
|
7304
7636
|
return editor.children;
|
|
@@ -7406,7 +7738,7 @@ var EmbedEntityWidget = function EmbedEntityWidget(_ref) {
|
|
|
7406
7738
|
nodeType: Contentful.BLOCKS.EMBEDDED_ENTRY,
|
|
7407
7739
|
onClose: onCloseEntityDropdown
|
|
7408
7740
|
}), inlineEntryEmbedEnabled && /*#__PURE__*/React__default.createElement(ToolbarEmbeddedEntityInlineButton, {
|
|
7409
|
-
isDisabled: !!isDisabled || isLinkActive(editor),
|
|
7741
|
+
isDisabled: !!isDisabled || Boolean(isLinkActive(editor)),
|
|
7410
7742
|
onClose: onCloseEntityDropdown
|
|
7411
7743
|
}), blockAssetEmbedEnabled && /*#__PURE__*/React__default.createElement(EmbeddedEntityBlockToolbarIcon, {
|
|
7412
7744
|
isDisabled: !!isDisabled,
|
|
@@ -7464,7 +7796,7 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
7464
7796
|
var sdk = _ref.sdk,
|
|
7465
7797
|
isDisabled = _ref.isDisabled;
|
|
7466
7798
|
var editor = useContentfulEditor();
|
|
7467
|
-
var isActive =
|
|
7799
|
+
var isActive = editor && (isMarkActive(editor, Contentful.MARKS.SUPERSCRIPT) || isMarkActive(editor, Contentful.MARKS.SUBSCRIPT) || isMarkActive(editor, Contentful.MARKS.CODE));
|
|
7468
7800
|
return /*#__PURE__*/React__default.createElement(f36Components.Menu, null, /*#__PURE__*/React__default.createElement(f36Components.Menu.Trigger, null, /*#__PURE__*/React__default.createElement("span", null, /*#__PURE__*/React__default.createElement(f36Components.IconButton, {
|
|
7469
7801
|
size: "small",
|
|
7470
7802
|
className: styles$l.toolbarBtn,
|
|
@@ -7618,7 +7950,7 @@ var useOnValueChanged = function useOnValueChanged(_ref) {
|
|
|
7618
7950
|
}, 500);
|
|
7619
7951
|
}, [handler]);
|
|
7620
7952
|
return React.useCallback(function (value) {
|
|
7621
|
-
var editor =
|
|
7953
|
+
var editor = p.getPlateSelectors(editorId).editor();
|
|
7622
7954
|
|
|
7623
7955
|
if (!editor) {
|
|
7624
7956
|
throw new Error('Editor change callback called but editor not defined. Editor id: ' + editorId);
|
|
@@ -7674,7 +8006,7 @@ var ConnectedRichTextEditor = function ConnectedRichTextEditor(props) {
|
|
|
7674
8006
|
the change listener isn't invoked
|
|
7675
8007
|
*/
|
|
7676
8008
|
setIsFirstRender(false);
|
|
7677
|
-
var editor =
|
|
8009
|
+
var editor = getPlateSelectors(id).editor();
|
|
7678
8010
|
|
|
7679
8011
|
if (!editor) {
|
|
7680
8012
|
return;
|
|
@@ -7691,7 +8023,9 @@ var ConnectedRichTextEditor = function ConnectedRichTextEditor(props) {
|
|
|
7691
8023
|
return;
|
|
7692
8024
|
}
|
|
7693
8025
|
|
|
7694
|
-
|
|
8026
|
+
p.getPlateActions(id).value( // FIXME: fix types here
|
|
8027
|
+
// @ts-expect-error
|
|
8028
|
+
normalizeEditorValue(documentToEditorValue(props.value), {
|
|
7695
8029
|
plugins: plugins,
|
|
7696
8030
|
disableCorePlugins: disableCorePlugins
|
|
7697
8031
|
}));
|
|
@@ -7703,7 +8037,7 @@ var ConnectedRichTextEditor = function ConnectedRichTextEditor(props) {
|
|
|
7703
8037
|
}, /*#__PURE__*/React__default.createElement("div", {
|
|
7704
8038
|
className: styles$k.root,
|
|
7705
8039
|
"data-test-id": "rich-text-editor"
|
|
7706
|
-
}, /*#__PURE__*/React__default.createElement(
|
|
8040
|
+
}, /*#__PURE__*/React__default.createElement(p.Plate, {
|
|
7707
8041
|
id: id,
|
|
7708
8042
|
plugins: plugins,
|
|
7709
8043
|
disableCorePlugins: disableCorePlugins,
|
|
@@ -7711,12 +8045,13 @@ var ConnectedRichTextEditor = function ConnectedRichTextEditor(props) {
|
|
|
7711
8045
|
className: classNames,
|
|
7712
8046
|
readOnly: props.isDisabled
|
|
7713
8047
|
},
|
|
7714
|
-
onChange: onValueChanged
|
|
7715
|
-
|
|
7716
|
-
|
|
7717
|
-
|
|
7718
|
-
|
|
7719
|
-
|
|
8048
|
+
onChange: onValueChanged,
|
|
8049
|
+
firstChildren: !props.isToolbarHidden && /*#__PURE__*/React__default.createElement(StickyToolbarWrapper, {
|
|
8050
|
+
isDisabled: props.isDisabled
|
|
8051
|
+
}, /*#__PURE__*/React__default.createElement(Toolbar, {
|
|
8052
|
+
isDisabled: props.isDisabled
|
|
8053
|
+
}))
|
|
8054
|
+
}))));
|
|
7720
8055
|
};
|
|
7721
8056
|
|
|
7722
8057
|
var RichTextEditor = function RichTextEditor(props) {
|