prosemirror-safari-ime-span 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 ocavue
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # prosemirror-safari-ime-span
2
+
3
+ [![NPM version](https://img.shields.io/npm/v/prosemirror-safari-ime-span?color=a1b858&label=)](https://www.npmjs.com/package/prosemirror-safari-ime-span)
4
+
5
+ This module exports a [ProseMirror] plugin to work around the bug in Safari
6
+ where [IME] text replacement removes empty nodes when the composition finishes.
7
+ See also [prosemirror#934] for more details.
8
+
9
+ ## Usage
10
+
11
+ ```ts
12
+ import { imeSpan } from 'prosemirror-safari-ime-span'
13
+ ```
14
+
15
+ ## License
16
+
17
+ MIT
18
+
19
+ [ProseMirror]: https://prosemirror.net/
20
+ [IME]: https://developer.mozilla.org/en-US/docs/Glossary/Input_method_editor
21
+ [prosemirror#934]: https://github.com/ProseMirror/prosemirror/issues/934
package/dist/index.cjs ADDED
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key2 of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key2) && key2 !== except)
14
+ __defProp(to, key2, { get: () => from[key2], enumerable: !(desc = __getOwnPropDesc(from, key2)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ imeSpan: () => imeSpan
24
+ });
25
+ module.exports = __toCommonJS(src_exports);
26
+ var import_prosemirror_state = require("prosemirror-state");
27
+ var import_prosemirror_view = require("prosemirror-view");
28
+
29
+ // src/browser.ts
30
+ var nav = typeof navigator != "undefined" ? navigator : null;
31
+ var agent = nav && nav.userAgent || "";
32
+ var ie_edge = /Edge\/(\d+)/.exec(agent);
33
+ var ie_upto10 = /MSIE \d/.exec(agent);
34
+ var ie_11up = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(agent);
35
+ var ie = !!(ie_upto10 || ie_11up || ie_edge);
36
+ var safari = !ie && !!nav && /Apple Computer/.test(nav.vendor);
37
+
38
+ // src/index.ts
39
+ var key = new import_prosemirror_state.PluginKey("safari-ime-span");
40
+ var spec = {
41
+ key,
42
+ state: {
43
+ init: () => {
44
+ return false;
45
+ },
46
+ apply: (tr, value) => {
47
+ const composing = tr.getMeta(key);
48
+ return composing != null ? composing : value;
49
+ }
50
+ },
51
+ props: {
52
+ decorations: createDecorations,
53
+ handleDOMEvents: {
54
+ compositionstart: (view) => {
55
+ view.dispatch(view.state.tr.setMeta(key, true));
56
+ },
57
+ compositionend: (view) => {
58
+ view.dispatch(view.state.tr.setMeta(key, false));
59
+ }
60
+ }
61
+ }
62
+ };
63
+ function createDecorations(state) {
64
+ const { $from, $to, from } = state.selection;
65
+ const composing = key.getState(state);
66
+ if (composing && $from.sameParent($to)) {
67
+ const deco = import_prosemirror_view.Decoration.widget(from, createSpan, {
68
+ side: -100,
69
+ ignoreSelection: true,
70
+ key: "safari-ime-span"
71
+ });
72
+ return import_prosemirror_view.DecorationSet.create(state.doc, [deco]);
73
+ }
74
+ }
75
+ function createSpan(view) {
76
+ const span = view.dom.ownerDocument.createElement("span");
77
+ span.className = "ProseMirror-safari-ime-span";
78
+ return span;
79
+ }
80
+ var imeSpan = new import_prosemirror_state.Plugin(safari ? spec : { key });
81
+ // Annotate the CommonJS export names for ESM import in node:
82
+ 0 && (module.exports = {
83
+ imeSpan
84
+ });
@@ -0,0 +1,13 @@
1
+ import { Plugin } from 'prosemirror-state';
2
+
3
+ /**
4
+ * A plugin as a workaround for a bug in Safari that causes the composition
5
+ * based IME to remove the empty HTML element with CSS `position: relative`.
6
+ *
7
+ * See also https://github.com/ProseMirror/prosemirror/issues/934
8
+ *
9
+ * @public @group Plugins
10
+ */
11
+ declare const imeSpan: Plugin<boolean>;
12
+
13
+ export { imeSpan };
@@ -0,0 +1,13 @@
1
+ import { Plugin } from 'prosemirror-state';
2
+
3
+ /**
4
+ * A plugin as a workaround for a bug in Safari that causes the composition
5
+ * based IME to remove the empty HTML element with CSS `position: relative`.
6
+ *
7
+ * See also https://github.com/ProseMirror/prosemirror/issues/934
8
+ *
9
+ * @public @group Plugins
10
+ */
11
+ declare const imeSpan: Plugin<boolean>;
12
+
13
+ export { imeSpan };
package/dist/index.js ADDED
@@ -0,0 +1,62 @@
1
+ // src/index.ts
2
+ import {
3
+ Plugin,
4
+ PluginKey
5
+ } from "prosemirror-state";
6
+ import { Decoration, DecorationSet } from "prosemirror-view";
7
+
8
+ // src/browser.ts
9
+ var nav = typeof navigator != "undefined" ? navigator : null;
10
+ var agent = nav && nav.userAgent || "";
11
+ var ie_edge = /Edge\/(\d+)/.exec(agent);
12
+ var ie_upto10 = /MSIE \d/.exec(agent);
13
+ var ie_11up = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(agent);
14
+ var ie = !!(ie_upto10 || ie_11up || ie_edge);
15
+ var safari = !ie && !!nav && /Apple Computer/.test(nav.vendor);
16
+
17
+ // src/index.ts
18
+ var key = new PluginKey("safari-ime-span");
19
+ var spec = {
20
+ key,
21
+ state: {
22
+ init: () => {
23
+ return false;
24
+ },
25
+ apply: (tr, value) => {
26
+ const composing = tr.getMeta(key);
27
+ return composing != null ? composing : value;
28
+ }
29
+ },
30
+ props: {
31
+ decorations: createDecorations,
32
+ handleDOMEvents: {
33
+ compositionstart: (view) => {
34
+ view.dispatch(view.state.tr.setMeta(key, true));
35
+ },
36
+ compositionend: (view) => {
37
+ view.dispatch(view.state.tr.setMeta(key, false));
38
+ }
39
+ }
40
+ }
41
+ };
42
+ function createDecorations(state) {
43
+ const { $from, $to, from } = state.selection;
44
+ const composing = key.getState(state);
45
+ if (composing && $from.sameParent($to)) {
46
+ const deco = Decoration.widget(from, createSpan, {
47
+ side: -100,
48
+ ignoreSelection: true,
49
+ key: "safari-ime-span"
50
+ });
51
+ return DecorationSet.create(state.doc, [deco]);
52
+ }
53
+ }
54
+ function createSpan(view) {
55
+ const span = view.dom.ownerDocument.createElement("span");
56
+ span.className = "ProseMirror-safari-ime-span";
57
+ return span;
58
+ }
59
+ var imeSpan = new Plugin(safari ? spec : { key });
60
+ export {
61
+ imeSpan
62
+ };
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "prosemirror-safari-ime-span",
3
+ "type": "module",
4
+ "version": "1.0.0",
5
+ "packageManager": "pnpm@8.15.8",
6
+ "description": "",
7
+ "author": "ocavue <ocavue@gmail.com>",
8
+ "license": "MIT",
9
+ "funding": "https://github.com/sponsors/ocavue",
10
+ "homepage": "https://github.com/ocavue/prosemirror-safari-ime-span#readme",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/ocavue/prosemirror-safari-ime-span.git"
14
+ },
15
+ "bugs": "https://github.com/ocavue/prosemirror-safari-ime-span/issues",
16
+ "keywords": [],
17
+ "sideEffects": false,
18
+ "main": "./dist/index.cjs",
19
+ "module": "./dist/index.js",
20
+ "types": "./dist/index.d.ts",
21
+ "exports": {
22
+ ".": {
23
+ "types": "./dist/index.d.ts",
24
+ "require": "./dist/index.cjs",
25
+ "import": "./dist/index.js"
26
+ }
27
+ },
28
+ "typesVersions": {
29
+ "*": {
30
+ "*": [
31
+ "./dist/*",
32
+ "./dist/index.d.ts"
33
+ ]
34
+ }
35
+ },
36
+ "files": [
37
+ "dist"
38
+ ],
39
+ "dependencies": {
40
+ "prosemirror-state": "^1.4.3",
41
+ "prosemirror-view": "^1.33.8"
42
+ },
43
+ "devDependencies": {
44
+ "@ocavue/eslint-config": "^1.7.0",
45
+ "@types/node": "^20.14.9",
46
+ "eslint": "^8.57.0",
47
+ "prettier": "^3.3.2",
48
+ "tsup": "^8.1.0",
49
+ "typescript": "^5.5.3"
50
+ },
51
+ "renovate": {
52
+ "extends": [
53
+ "github>ocavue/config-renovate"
54
+ ]
55
+ },
56
+ "scripts": {
57
+ "build": "tsup",
58
+ "dev": "tsup --watch",
59
+ "lint": "eslint .",
60
+ "fix": "eslint --fix . && prettier --write .",
61
+ "typecheck": "tsc --noEmit"
62
+ }
63
+ }