@contentful/field-editor-rich-text 2.0.0-next.18 → 2.0.0-next.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/field-editor-rich-text.cjs.development.js +112 -30
- 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 +112 -30
- package/dist/field-editor-rich-text.esm.js.map +1 -1
- package/dist/helpers/editor.d.ts +2 -0
- package/dist/test-utils/jsx.d.ts +1 -1
- package/package.json +1 -1
|
@@ -425,6 +425,23 @@ function moveToTheNextLine(editor) {
|
|
|
425
425
|
unit: 'line'
|
|
426
426
|
});
|
|
427
427
|
}
|
|
428
|
+
function moveToTheNextChar(editor) {
|
|
429
|
+
slate.Transforms.move(editor, {
|
|
430
|
+
distance: 1,
|
|
431
|
+
unit: 'character'
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
function insertEmptyParagraph(editor) {
|
|
435
|
+
var emptyParagraph = {
|
|
436
|
+
type: Contentful.BLOCKS.PARAGRAPH,
|
|
437
|
+
children: [{
|
|
438
|
+
text: ''
|
|
439
|
+
}],
|
|
440
|
+
data: {},
|
|
441
|
+
isVoid: false
|
|
442
|
+
};
|
|
443
|
+
slate.Transforms.insertNodes(editor, emptyParagraph);
|
|
444
|
+
}
|
|
428
445
|
function getElementFromCurrentSelection(editor) {
|
|
429
446
|
if (!editor.selection) return [];
|
|
430
447
|
return Array.from(slate.Editor.nodes(editor, {
|
|
@@ -1943,11 +1960,12 @@ function _selectEntityAndInsert() {
|
|
|
1943
1960
|
case 12:
|
|
1944
1961
|
slate.Transforms.select(editor, selection);
|
|
1945
1962
|
insertBlock(editor, nodeType, entity);
|
|
1963
|
+
ensureFollowingParagraph(editor);
|
|
1946
1964
|
logAction('insert', {
|
|
1947
1965
|
nodeType: nodeType
|
|
1948
1966
|
});
|
|
1949
1967
|
|
|
1950
|
-
case
|
|
1968
|
+
case 16:
|
|
1951
1969
|
case "end":
|
|
1952
1970
|
return _context.stop();
|
|
1953
1971
|
}
|
|
@@ -1957,6 +1975,43 @@ function _selectEntityAndInsert() {
|
|
|
1957
1975
|
return _selectEntityAndInsert.apply(this, arguments);
|
|
1958
1976
|
}
|
|
1959
1977
|
|
|
1978
|
+
function ensureFollowingParagraph(editor) {
|
|
1979
|
+
/*
|
|
1980
|
+
If the new block isn't followed by a sibling paragraph we insert a new empty one
|
|
1981
|
+
*/
|
|
1982
|
+
var next = slate.Editor.next(editor);
|
|
1983
|
+
|
|
1984
|
+
if (!next) {
|
|
1985
|
+
return insertEmptyParagraph(editor);
|
|
1986
|
+
}
|
|
1987
|
+
|
|
1988
|
+
var parent = slate.Editor.above(editor, {
|
|
1989
|
+
voids: false,
|
|
1990
|
+
match: function match(e) {
|
|
1991
|
+
return !slate.Element.isElement(e) || ![Contentful.BLOCKS.EMBEDDED_ASSET, Contentful.BLOCKS.EMBEDDED_ENTRY].includes(e.type);
|
|
1992
|
+
}
|
|
1993
|
+
});
|
|
1994
|
+
|
|
1995
|
+
if (slate.Editor.isEditor(parent)) {
|
|
1996
|
+
// at level 0, a following paragraph is handled by the tralingParagraph plugin
|
|
1997
|
+
moveToTheNextChar(editor);
|
|
1998
|
+
return;
|
|
1999
|
+
}
|
|
2000
|
+
|
|
2001
|
+
var paragraph = slate.Editor.above(editor, {
|
|
2002
|
+
at: next[1],
|
|
2003
|
+
match: function match(e) {
|
|
2004
|
+
return slate.Element.isElement(e) && Contentful.TEXT_CONTAINERS.includes(e.type);
|
|
2005
|
+
}
|
|
2006
|
+
});
|
|
2007
|
+
|
|
2008
|
+
if (!paragraph || !parent || !slate.Path.isChild(paragraph[1], parent[1])) {
|
|
2009
|
+
return insertEmptyParagraph(editor);
|
|
2010
|
+
}
|
|
2011
|
+
|
|
2012
|
+
moveToTheNextChar(editor);
|
|
2013
|
+
}
|
|
2014
|
+
|
|
1960
2015
|
var createNode = function createNode(nodeType, entity) {
|
|
1961
2016
|
return {
|
|
1962
2017
|
type: nodeType,
|
|
@@ -2004,11 +2059,29 @@ function EmbeddedEntityBlockToolbarIcon(_ref) {
|
|
|
2004
2059
|
var editor = useContentfulEditor();
|
|
2005
2060
|
var sdk = useSdkContext();
|
|
2006
2061
|
|
|
2007
|
-
var handleClick = function
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2062
|
+
var handleClick = /*#__PURE__*/function () {
|
|
2063
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(event) {
|
|
2064
|
+
return runtime_1.wrap(function _callee$(_context) {
|
|
2065
|
+
while (1) {
|
|
2066
|
+
switch (_context.prev = _context.next) {
|
|
2067
|
+
case 0:
|
|
2068
|
+
event.preventDefault();
|
|
2069
|
+
onClose();
|
|
2070
|
+
_context.next = 4;
|
|
2071
|
+
return selectEntityAndInsert(nodeType, sdk, editor, editor.tracking.onToolbarAction);
|
|
2072
|
+
|
|
2073
|
+
case 4:
|
|
2074
|
+
case "end":
|
|
2075
|
+
return _context.stop();
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2078
|
+
}, _callee);
|
|
2079
|
+
}));
|
|
2080
|
+
|
|
2081
|
+
return function handleClick(_x) {
|
|
2082
|
+
return _ref2.apply(this, arguments);
|
|
2083
|
+
};
|
|
2084
|
+
}();
|
|
2012
2085
|
|
|
2013
2086
|
var type = getEntityTypeFromNodeType(nodeType);
|
|
2014
2087
|
var baseClass = "rich-text__" + nodeType;
|
|
@@ -2341,15 +2414,18 @@ function _selectEntityAndInsert$1() {
|
|
|
2341
2414
|
return _context2.abrupt("return");
|
|
2342
2415
|
|
|
2343
2416
|
case 10:
|
|
2344
|
-
inlineEntryNode = createInlineEntryNode(entry.sys.id);
|
|
2345
|
-
|
|
2346
|
-
setTimeout(function () {
|
|
2347
|
-
slate.Transforms.setSelection(editor, selection);
|
|
2348
|
-
slate.Transforms.insertNodes(editor, inlineEntryNode);
|
|
2349
|
-
}, 0);
|
|
2417
|
+
inlineEntryNode = createInlineEntryNode(entry.sys.id);
|
|
2350
2418
|
logAction('insert', {
|
|
2351
2419
|
nodeType: Contentful.INLINES.EMBEDDED_ENTRY
|
|
2352
|
-
});
|
|
2420
|
+
}); // Got to wait until focus is really back on the editor or setSelection() won't work.
|
|
2421
|
+
|
|
2422
|
+
return _context2.abrupt("return", new Promise(function (resolve) {
|
|
2423
|
+
setTimeout(function () {
|
|
2424
|
+
slate.Transforms.setSelection(editor, selection);
|
|
2425
|
+
slate.Transforms.insertNodes(editor, inlineEntryNode);
|
|
2426
|
+
resolve();
|
|
2427
|
+
}, 0);
|
|
2428
|
+
}));
|
|
2353
2429
|
|
|
2354
2430
|
case 13:
|
|
2355
2431
|
case "end":
|
|
@@ -2390,6 +2466,9 @@ function ToolbarEmbeddedEntityInlineButton(props) {
|
|
|
2390
2466
|
return selectEntityAndInsert$1(editor, sdk, editor.tracking.onToolbarAction);
|
|
2391
2467
|
|
|
2392
2468
|
case 6:
|
|
2469
|
+
moveToTheNextChar(editor);
|
|
2470
|
+
|
|
2471
|
+
case 7:
|
|
2393
2472
|
case "end":
|
|
2394
2473
|
return _context.stop();
|
|
2395
2474
|
}
|
|
@@ -4998,10 +5077,6 @@ function toggleQuote(editor, logAction) {
|
|
|
4998
5077
|
},
|
|
4999
5078
|
split: true
|
|
5000
5079
|
});
|
|
5001
|
-
var _editor$selection = editor.selection,
|
|
5002
|
-
anchor = _editor$selection.anchor,
|
|
5003
|
-
focus = _editor$selection.focus;
|
|
5004
|
-
var isTripleSelection = anchor.path[0] !== focus.path[0] && anchor.offset === 0 && focus.offset === 0;
|
|
5005
5080
|
|
|
5006
5081
|
if (!isActive) {
|
|
5007
5082
|
var quote = {
|
|
@@ -5009,9 +5084,7 @@ function toggleQuote(editor, logAction) {
|
|
|
5009
5084
|
data: {},
|
|
5010
5085
|
children: []
|
|
5011
5086
|
};
|
|
5012
|
-
slate.Transforms.wrapNodes(editor, quote
|
|
5013
|
-
at: isTripleSelection ? editor.selection.anchor : undefined
|
|
5014
|
-
});
|
|
5087
|
+
slate.Transforms.wrapNodes(editor, quote);
|
|
5015
5088
|
}
|
|
5016
5089
|
});
|
|
5017
5090
|
}
|
|
@@ -5588,15 +5661,7 @@ var createTablePlugin = function createTablePlugin() {
|
|
|
5588
5661
|
});
|
|
5589
5662
|
|
|
5590
5663
|
if (fragmentHasTable) {
|
|
5591
|
-
|
|
5592
|
-
type: Contentful.BLOCKS.PARAGRAPH,
|
|
5593
|
-
children: [{
|
|
5594
|
-
text: ''
|
|
5595
|
-
}],
|
|
5596
|
-
data: {},
|
|
5597
|
-
isVoid: false
|
|
5598
|
-
};
|
|
5599
|
-
slate.Transforms.insertNodes(editor, emptyParagraph);
|
|
5664
|
+
insertEmptyParagraph(editor);
|
|
5600
5665
|
}
|
|
5601
5666
|
|
|
5602
5667
|
insertFragment(fragments);
|
|
@@ -5725,6 +5790,20 @@ function ToolbarTableButton(props) {
|
|
|
5725
5790
|
function createTextPlugin() {
|
|
5726
5791
|
return {
|
|
5727
5792
|
key: 'TextPlugin',
|
|
5793
|
+
handlers: {
|
|
5794
|
+
// Triple selection in a non-Firefox browser undesirably selects
|
|
5795
|
+
// the start of the next block. Editor.unhangRange helps removing
|
|
5796
|
+
// the extra block at the end.
|
|
5797
|
+
onMouseUp: function onMouseUp(editor) {
|
|
5798
|
+
return function () {
|
|
5799
|
+
if (!editor.selection) {
|
|
5800
|
+
return;
|
|
5801
|
+
}
|
|
5802
|
+
|
|
5803
|
+
slate.Transforms.setSelection(editor, slate.Editor.unhangRange(editor, editor.selection));
|
|
5804
|
+
};
|
|
5805
|
+
}
|
|
5806
|
+
},
|
|
5728
5807
|
withOverrides: function withOverrides(editor) {
|
|
5729
5808
|
// Reverts the change made upstream that caused the cursor
|
|
5730
5809
|
// to be trapped inside inline elements.
|
|
@@ -6336,7 +6415,10 @@ var useNormalizedSlateValue = function useNormalizedSlateValue(_ref) {
|
|
|
6336
6415
|
schema: schema
|
|
6337
6416
|
}); // Sets editor value & kicks normalization
|
|
6338
6417
|
|
|
6339
|
-
|
|
6418
|
+
editor.children = doc;
|
|
6419
|
+
slate.Editor.normalize(editor, {
|
|
6420
|
+
force: true
|
|
6421
|
+
}); // TODO: return the editor itself to avoid recompiling & initializing all
|
|
6340
6422
|
// of the plugins again. It's currently not possible due to a bug in Plate
|
|
6341
6423
|
// with initialValues
|
|
6342
6424
|
// See: https://slate-js.slack.com/archives/C013QHXSCG1/p1645112799942819
|