@uxf/wysiwyg 16.3.0 → 16.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.
@@ -71,7 +71,8 @@ describe("an li with more than one lic", () => {
71
71
  expect(outline(editor).at(0)).toEqual(["ul", ["aa1", "b", "c"]]);
72
72
  });
73
73
  it("gives the split-off item an id of its own", () => {
74
- var _a, _b;
74
+ var _a;
75
+ var _b;
75
76
  const editor = createEditor([
76
77
  { children: [{ children: [content("a"), content("b")], type: "li" }], type: "ul" },
77
78
  ]);
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Shift+Enter inserts a line break itself: the browser decides by `beforeinput`, and Safari on macOS reports it
3
+ * as a new paragraph (its line break is Ctrl+Enter). A touch device keeps the browser's behaviour, because iOS
4
+ * sets `shiftKey` on Enter whenever the on-screen keyboard capitalizes the next letter (w3c/editing#542).
5
+ */
6
+ export declare const createSoftBreakPlugin: () => import("platejs/react").PlatePlugin<import("platejs").PluginConfig<"softBreak", {}, {}, {}, {}>>;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createSoftBreakPlugin = void 0;
4
+ const react_1 = require("platejs/react");
5
+ /**
6
+ * Shift+Enter inserts a line break itself: the browser decides by `beforeinput`, and Safari on macOS reports it
7
+ * as a new paragraph (its line break is Ctrl+Enter). A touch device keeps the browser's behaviour, because iOS
8
+ * sets `shiftKey` on Enter whenever the on-screen keyboard capitalizes the next letter (w3c/editing#542).
9
+ */
10
+ const createSoftBreakPlugin = () => (0, react_1.createPlatePlugin)({
11
+ key: "softBreak",
12
+ shortcuts: {
13
+ insert: {
14
+ handler: ({ editor }) => {
15
+ if (navigator.maxTouchPoints > 0) {
16
+ return false;
17
+ }
18
+ editor.tf.insertSoftBreak();
19
+ },
20
+ keys: "shift+enter",
21
+ },
22
+ },
23
+ });
24
+ exports.createSoftBreakPlugin = createSoftBreakPlugin;
package/utils.js CHANGED
@@ -11,13 +11,10 @@ const getPluginType = (editor, key) => editor.getType(key);
11
11
  exports.getPluginType = getPluginType;
12
12
  const someNode = (editor, options) => editor.api.some(options);
13
13
  exports.someNode = someNode;
14
- const toggleNodeType = (editor, options, editorNodesOptions) => {
15
- var _a;
16
- return editor.tf.toggleBlock((_a = options.activeType) !== null && _a !== void 0 ? _a : types_1.PARAGRAPH_PLUGIN_TYPE, {
17
- defaultType: options.inactiveType,
18
- someOptions: editorNodesOptions,
19
- });
20
- };
14
+ const toggleNodeType = (editor, options, editorNodesOptions) => { var _a; return editor.tf.toggleBlock((_a = options.activeType) !== null && _a !== void 0 ? _a : types_1.PARAGRAPH_PLUGIN_TYPE, {
15
+ defaultType: options.inactiveType,
16
+ someOptions: editorNodesOptions,
17
+ }); };
21
18
  exports.toggleNodeType = toggleNodeType;
22
19
  const focusEditor = (editor, target) => editor.tf.focus({ at: target });
23
20
  exports.focusEditor = focusEditor;
@@ -227,3 +227,53 @@ describe("WysiwygEditor onChange", () => {
227
227
  ]);
228
228
  });
229
229
  });
230
+ describe("WysiwygEditor Shift+Enter", () => {
231
+ let editor;
232
+ function EditorProbe() {
233
+ editor = (0, react_2.useEditorRef)();
234
+ return null;
235
+ }
236
+ async function renderAndPressShiftEnter(init = {}) {
237
+ const { container } = (0, react_1.render)(react_3.default.createElement(context_1.UiContextProvider, { value: UI_CONTEXT },
238
+ react_3.default.createElement(wysiwyg_editor_1.WysiwygEditor, { customPluginsToolbarButtons: react_3.default.createElement(EditorProbe, null), id: "shift-enter-editor", initialValue: INITIAL_VALUE, onChange: () => undefined, plugins: (0, create_plugins_with_ui_1.createPluginsWithUi)([]) })));
239
+ await settle();
240
+ const editable = container.querySelector("[contenteditable=true]");
241
+ (0, react_1.act)(() => {
242
+ editable === null || editable === void 0 ? void 0 : editable.focus();
243
+ editor === null || editor === void 0 ? void 0 : editor.tf.select(editor.api.end([]));
244
+ });
245
+ let notPrevented = true;
246
+ (0, react_1.act)(() => {
247
+ notPrevented = react_1.fireEvent.keyDown(editable !== null && editable !== void 0 ? editable : document.body, {
248
+ code: "Enter",
249
+ key: "Enter",
250
+ shiftKey: true,
251
+ ...init,
252
+ });
253
+ });
254
+ await settle();
255
+ return { notPrevented, texts: editor === null || editor === void 0 ? void 0 : editor.children.map((node) => editor === null || editor === void 0 ? void 0 : editor.api.string(node)) };
256
+ }
257
+ afterEach(() => {
258
+ Reflect.deleteProperty(navigator, "maxTouchPoints");
259
+ });
260
+ // Safari on macOS reports Shift+Enter as a new paragraph, so the editor inserts the line break itself
261
+ it("inserts a line break in the same paragraph on a physical keyboard", async () => {
262
+ Object.defineProperty(navigator, "maxTouchPoints", { configurable: true, value: 0 });
263
+ const { notPrevented, texts } = await renderAndPressShiftEnter();
264
+ expect(texts).toEqual(["hello\n"]);
265
+ expect(notPrevented).toBe(false);
266
+ });
267
+ // iOS sets shiftKey on Enter whenever the on-screen keyboard capitalizes the next letter
268
+ it("leaves Enter to the browser on a touch device", async () => {
269
+ Object.defineProperty(navigator, "maxTouchPoints", { configurable: true, value: 5 });
270
+ const { notPrevented, texts } = await renderAndPressShiftEnter();
271
+ expect(texts).toEqual(["hello"]);
272
+ expect(notPrevented).toBe(true);
273
+ });
274
+ it("leaves Mod+Shift+Enter to the exit break", async () => {
275
+ Object.defineProperty(navigator, "maxTouchPoints", { configurable: true, value: 0 });
276
+ const { texts } = await renderAndPressShiftEnter({ ctrlKey: true, metaKey: true });
277
+ expect(texts === null || texts === void 0 ? void 0 : texts.join("|")).not.toContain("\n");
278
+ });
279
+ });