@uxf/wysiwyg 16.4.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.
package/README.md
CHANGED
|
@@ -127,7 +127,7 @@ Everything below is exported from the package root (`@uxf/wysiwyg`) unless a dee
|
|
|
127
127
|
|
|
128
128
|
### Plugin builders
|
|
129
129
|
|
|
130
|
-
`createPluginsWithUi` / `createAllPluginsWithUi` return the `UxfPlatePlugin[]` you pass to `WysiwygEditor`. Both inject the base plugins automatically (paragraph, exit-break, node-id, trailing-block), so pass only the feature builders below — not raw Plate plugins.
|
|
130
|
+
`createPluginsWithUi` / `createAllPluginsWithUi` return the `UxfPlatePlugin[]` you pass to `WysiwygEditor`. Both inject the base plugins automatically (paragraph, exit-break, soft-break, node-id, trailing-block), so pass only the feature builders below — not raw Plate plugins. Soft-break makes Shift+Enter insert a line break in every browser (Safari on macOS would start a new paragraph) and leaves touch devices to the browser.
|
|
131
131
|
|
|
132
132
|
| Export | Signature | Notes |
|
|
133
133
|
| ------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------- |
|
|
@@ -5,6 +5,7 @@ const platejs_1 = require("platejs");
|
|
|
5
5
|
const create_exit_break_plugin_1 = require("./plugins/exit-break/create-exit-break-plugin");
|
|
6
6
|
const create_node_id_plugin_1 = require("./plugins/node-id/create-node-id-plugin");
|
|
7
7
|
const create_paragraph_plugin_1 = require("./plugins/paragraph/create-paragraph-plugin");
|
|
8
|
+
const create_soft_break_plugin_1 = require("./plugins/soft-break/create-soft-break-plugin");
|
|
8
9
|
const create_trailing_block_plugin_1 = require("./plugins/trailing-block/create-trailing-block-plugin");
|
|
9
10
|
const paragraph_element_1 = require("./ui/paragraph-element");
|
|
10
11
|
function isRecursivePlugin(plugin) {
|
|
@@ -30,6 +31,7 @@ const createPluginsWithUi = (wysiwygPlugins, options) => {
|
|
|
30
31
|
const plugins = [
|
|
31
32
|
(0, create_paragraph_plugin_1.createParagraphPlugin)().withComponent(paragraph_element_1.ParagraphElement),
|
|
32
33
|
(0, create_exit_break_plugin_1.createExitBreakPlugin)(),
|
|
34
|
+
(0, create_soft_break_plugin_1.createSoftBreakPlugin)(),
|
|
33
35
|
(0, create_node_id_plugin_1.createNodeIdPlugin)(),
|
|
34
36
|
(0, create_trailing_block_plugin_1.createTrailingBlockPlugin)(),
|
|
35
37
|
...withUi,
|
package/package.json
CHANGED
|
@@ -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/wysiwyg-editor.test.js
CHANGED
|
@@ -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
|
+
});
|