@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
|
@@ -418,6 +418,23 @@ function moveToTheNextLine(editor) {
|
|
|
418
418
|
unit: 'line'
|
|
419
419
|
});
|
|
420
420
|
}
|
|
421
|
+
function moveToTheNextChar(editor) {
|
|
422
|
+
Transforms.move(editor, {
|
|
423
|
+
distance: 1,
|
|
424
|
+
unit: 'character'
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
function insertEmptyParagraph(editor) {
|
|
428
|
+
var emptyParagraph = {
|
|
429
|
+
type: BLOCKS.PARAGRAPH,
|
|
430
|
+
children: [{
|
|
431
|
+
text: ''
|
|
432
|
+
}],
|
|
433
|
+
data: {},
|
|
434
|
+
isVoid: false
|
|
435
|
+
};
|
|
436
|
+
Transforms.insertNodes(editor, emptyParagraph);
|
|
437
|
+
}
|
|
421
438
|
function getElementFromCurrentSelection(editor) {
|
|
422
439
|
if (!editor.selection) return [];
|
|
423
440
|
return Array.from(Editor.nodes(editor, {
|
|
@@ -1936,11 +1953,12 @@ function _selectEntityAndInsert() {
|
|
|
1936
1953
|
case 12:
|
|
1937
1954
|
Transforms.select(editor, selection);
|
|
1938
1955
|
insertBlock(editor, nodeType, entity);
|
|
1956
|
+
ensureFollowingParagraph(editor);
|
|
1939
1957
|
logAction('insert', {
|
|
1940
1958
|
nodeType: nodeType
|
|
1941
1959
|
});
|
|
1942
1960
|
|
|
1943
|
-
case
|
|
1961
|
+
case 16:
|
|
1944
1962
|
case "end":
|
|
1945
1963
|
return _context.stop();
|
|
1946
1964
|
}
|
|
@@ -1950,6 +1968,43 @@ function _selectEntityAndInsert() {
|
|
|
1950
1968
|
return _selectEntityAndInsert.apply(this, arguments);
|
|
1951
1969
|
}
|
|
1952
1970
|
|
|
1971
|
+
function ensureFollowingParagraph(editor) {
|
|
1972
|
+
/*
|
|
1973
|
+
If the new block isn't followed by a sibling paragraph we insert a new empty one
|
|
1974
|
+
*/
|
|
1975
|
+
var next = Editor.next(editor);
|
|
1976
|
+
|
|
1977
|
+
if (!next) {
|
|
1978
|
+
return insertEmptyParagraph(editor);
|
|
1979
|
+
}
|
|
1980
|
+
|
|
1981
|
+
var parent = Editor.above(editor, {
|
|
1982
|
+
voids: false,
|
|
1983
|
+
match: function match(e) {
|
|
1984
|
+
return !Element.isElement(e) || ![BLOCKS.EMBEDDED_ASSET, BLOCKS.EMBEDDED_ENTRY].includes(e.type);
|
|
1985
|
+
}
|
|
1986
|
+
});
|
|
1987
|
+
|
|
1988
|
+
if (Editor.isEditor(parent)) {
|
|
1989
|
+
// at level 0, a following paragraph is handled by the tralingParagraph plugin
|
|
1990
|
+
moveToTheNextChar(editor);
|
|
1991
|
+
return;
|
|
1992
|
+
}
|
|
1993
|
+
|
|
1994
|
+
var paragraph = Editor.above(editor, {
|
|
1995
|
+
at: next[1],
|
|
1996
|
+
match: function match(e) {
|
|
1997
|
+
return Element.isElement(e) && TEXT_CONTAINERS.includes(e.type);
|
|
1998
|
+
}
|
|
1999
|
+
});
|
|
2000
|
+
|
|
2001
|
+
if (!paragraph || !parent || !Path.isChild(paragraph[1], parent[1])) {
|
|
2002
|
+
return insertEmptyParagraph(editor);
|
|
2003
|
+
}
|
|
2004
|
+
|
|
2005
|
+
moveToTheNextChar(editor);
|
|
2006
|
+
}
|
|
2007
|
+
|
|
1953
2008
|
var createNode = function createNode(nodeType, entity) {
|
|
1954
2009
|
return {
|
|
1955
2010
|
type: nodeType,
|
|
@@ -1997,11 +2052,29 @@ function EmbeddedEntityBlockToolbarIcon(_ref) {
|
|
|
1997
2052
|
var editor = useContentfulEditor();
|
|
1998
2053
|
var sdk = useSdkContext();
|
|
1999
2054
|
|
|
2000
|
-
var handleClick = function
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2055
|
+
var handleClick = /*#__PURE__*/function () {
|
|
2056
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(event) {
|
|
2057
|
+
return runtime_1.wrap(function _callee$(_context) {
|
|
2058
|
+
while (1) {
|
|
2059
|
+
switch (_context.prev = _context.next) {
|
|
2060
|
+
case 0:
|
|
2061
|
+
event.preventDefault();
|
|
2062
|
+
onClose();
|
|
2063
|
+
_context.next = 4;
|
|
2064
|
+
return selectEntityAndInsert(nodeType, sdk, editor, editor.tracking.onToolbarAction);
|
|
2065
|
+
|
|
2066
|
+
case 4:
|
|
2067
|
+
case "end":
|
|
2068
|
+
return _context.stop();
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
2071
|
+
}, _callee);
|
|
2072
|
+
}));
|
|
2073
|
+
|
|
2074
|
+
return function handleClick(_x) {
|
|
2075
|
+
return _ref2.apply(this, arguments);
|
|
2076
|
+
};
|
|
2077
|
+
}();
|
|
2005
2078
|
|
|
2006
2079
|
var type = getEntityTypeFromNodeType(nodeType);
|
|
2007
2080
|
var baseClass = "rich-text__" + nodeType;
|
|
@@ -2334,15 +2407,18 @@ function _selectEntityAndInsert$1() {
|
|
|
2334
2407
|
return _context2.abrupt("return");
|
|
2335
2408
|
|
|
2336
2409
|
case 10:
|
|
2337
|
-
inlineEntryNode = createInlineEntryNode(entry.sys.id);
|
|
2338
|
-
|
|
2339
|
-
setTimeout(function () {
|
|
2340
|
-
Transforms.setSelection(editor, selection);
|
|
2341
|
-
Transforms.insertNodes(editor, inlineEntryNode);
|
|
2342
|
-
}, 0);
|
|
2410
|
+
inlineEntryNode = createInlineEntryNode(entry.sys.id);
|
|
2343
2411
|
logAction('insert', {
|
|
2344
2412
|
nodeType: INLINES.EMBEDDED_ENTRY
|
|
2345
|
-
});
|
|
2413
|
+
}); // Got to wait until focus is really back on the editor or setSelection() won't work.
|
|
2414
|
+
|
|
2415
|
+
return _context2.abrupt("return", new Promise(function (resolve) {
|
|
2416
|
+
setTimeout(function () {
|
|
2417
|
+
Transforms.setSelection(editor, selection);
|
|
2418
|
+
Transforms.insertNodes(editor, inlineEntryNode);
|
|
2419
|
+
resolve();
|
|
2420
|
+
}, 0);
|
|
2421
|
+
}));
|
|
2346
2422
|
|
|
2347
2423
|
case 13:
|
|
2348
2424
|
case "end":
|
|
@@ -2383,6 +2459,9 @@ function ToolbarEmbeddedEntityInlineButton(props) {
|
|
|
2383
2459
|
return selectEntityAndInsert$1(editor, sdk, editor.tracking.onToolbarAction);
|
|
2384
2460
|
|
|
2385
2461
|
case 6:
|
|
2462
|
+
moveToTheNextChar(editor);
|
|
2463
|
+
|
|
2464
|
+
case 7:
|
|
2386
2465
|
case "end":
|
|
2387
2466
|
return _context.stop();
|
|
2388
2467
|
}
|
|
@@ -4991,10 +5070,6 @@ function toggleQuote(editor, logAction) {
|
|
|
4991
5070
|
},
|
|
4992
5071
|
split: true
|
|
4993
5072
|
});
|
|
4994
|
-
var _editor$selection = editor.selection,
|
|
4995
|
-
anchor = _editor$selection.anchor,
|
|
4996
|
-
focus = _editor$selection.focus;
|
|
4997
|
-
var isTripleSelection = anchor.path[0] !== focus.path[0] && anchor.offset === 0 && focus.offset === 0;
|
|
4998
5073
|
|
|
4999
5074
|
if (!isActive) {
|
|
5000
5075
|
var quote = {
|
|
@@ -5002,9 +5077,7 @@ function toggleQuote(editor, logAction) {
|
|
|
5002
5077
|
data: {},
|
|
5003
5078
|
children: []
|
|
5004
5079
|
};
|
|
5005
|
-
Transforms.wrapNodes(editor, quote
|
|
5006
|
-
at: isTripleSelection ? editor.selection.anchor : undefined
|
|
5007
|
-
});
|
|
5080
|
+
Transforms.wrapNodes(editor, quote);
|
|
5008
5081
|
}
|
|
5009
5082
|
});
|
|
5010
5083
|
}
|
|
@@ -5581,15 +5654,7 @@ var createTablePlugin = function createTablePlugin() {
|
|
|
5581
5654
|
});
|
|
5582
5655
|
|
|
5583
5656
|
if (fragmentHasTable) {
|
|
5584
|
-
|
|
5585
|
-
type: BLOCKS.PARAGRAPH,
|
|
5586
|
-
children: [{
|
|
5587
|
-
text: ''
|
|
5588
|
-
}],
|
|
5589
|
-
data: {},
|
|
5590
|
-
isVoid: false
|
|
5591
|
-
};
|
|
5592
|
-
Transforms.insertNodes(editor, emptyParagraph);
|
|
5657
|
+
insertEmptyParagraph(editor);
|
|
5593
5658
|
}
|
|
5594
5659
|
|
|
5595
5660
|
insertFragment(fragments);
|
|
@@ -5718,6 +5783,20 @@ function ToolbarTableButton(props) {
|
|
|
5718
5783
|
function createTextPlugin() {
|
|
5719
5784
|
return {
|
|
5720
5785
|
key: 'TextPlugin',
|
|
5786
|
+
handlers: {
|
|
5787
|
+
// Triple selection in a non-Firefox browser undesirably selects
|
|
5788
|
+
// the start of the next block. Editor.unhangRange helps removing
|
|
5789
|
+
// the extra block at the end.
|
|
5790
|
+
onMouseUp: function onMouseUp(editor) {
|
|
5791
|
+
return function () {
|
|
5792
|
+
if (!editor.selection) {
|
|
5793
|
+
return;
|
|
5794
|
+
}
|
|
5795
|
+
|
|
5796
|
+
Transforms.setSelection(editor, Editor.unhangRange(editor, editor.selection));
|
|
5797
|
+
};
|
|
5798
|
+
}
|
|
5799
|
+
},
|
|
5721
5800
|
withOverrides: function withOverrides(editor) {
|
|
5722
5801
|
// Reverts the change made upstream that caused the cursor
|
|
5723
5802
|
// to be trapped inside inline elements.
|
|
@@ -6329,7 +6408,10 @@ var useNormalizedSlateValue = function useNormalizedSlateValue(_ref) {
|
|
|
6329
6408
|
schema: schema
|
|
6330
6409
|
}); // Sets editor value & kicks normalization
|
|
6331
6410
|
|
|
6332
|
-
|
|
6411
|
+
editor.children = doc;
|
|
6412
|
+
Editor.normalize(editor, {
|
|
6413
|
+
force: true
|
|
6414
|
+
}); // TODO: return the editor itself to avoid recompiling & initializing all
|
|
6333
6415
|
// of the plugins again. It's currently not possible due to a bug in Plate
|
|
6334
6416
|
// with initialValues
|
|
6335
6417
|
// See: https://slate-js.slack.com/archives/C013QHXSCG1/p1645112799942819
|