@prosekit/react 0.0.0-next-20230627094841

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) 2023 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
File without changes
@@ -0,0 +1,13 @@
1
+ // src/components/menu-item.gen.ts
2
+ import { createComponent } from "@lit-labs/react";
3
+ import { MenuItem as MenuItemElement } from "@prosekit/lit/elements/menu-item";
4
+ import React from "react";
5
+ var MenuItem = createComponent({
6
+ tagName: "prosekit-menu-item",
7
+ elementClass: MenuItemElement,
8
+ react: React,
9
+ displayName: "MenuItem"
10
+ });
11
+ export {
12
+ MenuItem
13
+ };
@@ -0,0 +1,16 @@
1
+ // src/components/menu.gen.ts
2
+ import { createComponent } from "@lit-labs/react";
3
+ import { Menu as MenuElement } from "@prosekit/lit/elements/menu";
4
+ import React from "react";
5
+ var Menu = createComponent({
6
+ tagName: "prosekit-menu",
7
+ elementClass: MenuElement,
8
+ react: React,
9
+ displayName: "Menu"
10
+ });
11
+
12
+ // src/components/menu.tsx
13
+ var Menu2 = Menu;
14
+ export {
15
+ Menu2 as Menu
16
+ };
@@ -0,0 +1,27 @@
1
+ // src/components/popover-slash.tsx
2
+ import { useState } from "react";
3
+
4
+ // src/components/popover-slash.gen.ts
5
+ import { createComponent } from "@lit-labs/react";
6
+ import { PopoverSlash as PopoverSlashElement } from "@prosekit/lit/elements/popover-slash";
7
+ import React from "react";
8
+ var PopoverSlash = createComponent({
9
+ tagName: "prosekit-popover-slash",
10
+ elementClass: PopoverSlashElement,
11
+ react: React,
12
+ displayName: "PopoverSlash"
13
+ });
14
+
15
+ // src/components/popover-slash.tsx
16
+ import { jsxDEV } from "react/jsx-dev-runtime";
17
+ var PopoverSlash2 = ({ render, editor }) => {
18
+ const [context, setContext] = useState(null);
19
+ return /* @__PURE__ */ jsxDEV(PopoverSlash, { editor, onContext: setContext, children: context ? render(context) : null }, void 0, false, {
20
+ fileName: "src/components/popover-slash.tsx",
21
+ lineNumber: 17,
22
+ columnNumber: 5
23
+ }, this);
24
+ };
25
+ export {
26
+ PopoverSlash2 as PopoverSlash
27
+ };
@@ -0,0 +1,13 @@
1
+ // src/components/popover-suggestion-consumer.gen.ts
2
+ import { createComponent } from "@lit-labs/react";
3
+ import { PopoverSuggestionConsumer as PopoverSuggestionConsumerElement } from "@prosekit/lit/elements/popover-suggestion-consumer";
4
+ import React from "react";
5
+ var PopoverSuggestionConsumer = createComponent({
6
+ tagName: "prosekit-popover-suggestion-consumer",
7
+ elementClass: PopoverSuggestionConsumerElement,
8
+ react: React,
9
+ displayName: "PopoverSuggestionConsumer"
10
+ });
11
+ export {
12
+ PopoverSuggestionConsumer
13
+ };
@@ -0,0 +1,27 @@
1
+ // src/components/popover-suggestion.tsx
2
+ import { useState } from "react";
3
+
4
+ // src/components/popover-suggestion.gen.ts
5
+ import { createComponent } from "@lit-labs/react";
6
+ import { PopoverSuggestion as PopoverSuggestionElement } from "@prosekit/lit/elements/popover-suggestion";
7
+ import React from "react";
8
+ var PopoverSuggestion = createComponent({
9
+ tagName: "prosekit-popover-suggestion",
10
+ elementClass: PopoverSuggestionElement,
11
+ react: React,
12
+ displayName: "PopoverSuggestion"
13
+ });
14
+
15
+ // src/components/popover-suggestion.tsx
16
+ import { jsxDEV } from "react/jsx-dev-runtime";
17
+ var PopoverSuggestion2 = ({ editor, rules, render }) => {
18
+ const [context, setContext] = useState(null);
19
+ return /* @__PURE__ */ jsxDEV(PopoverSuggestion, { editor, rules, onContext: setContext, children: context ? render(context) : null }, void 0, false, {
20
+ fileName: "src/components/popover-suggestion.tsx",
21
+ lineNumber: 23,
22
+ columnNumber: 5
23
+ }, this);
24
+ };
25
+ export {
26
+ PopoverSuggestion2 as PopoverSuggestion
27
+ };
@@ -0,0 +1,13 @@
1
+ // src/components/popover.gen.ts
2
+ import { createComponent } from "@lit-labs/react";
3
+ import { Popover as PopoverElement } from "@prosekit/lit/elements/popover";
4
+ import React from "react";
5
+ var Popover = createComponent({
6
+ tagName: "prosekit-popover",
7
+ elementClass: PopoverElement,
8
+ react: React,
9
+ displayName: "Popover"
10
+ });
11
+ export {
12
+ Popover
13
+ };
@@ -0,0 +1,13 @@
1
+ // src/components/popover2.gen.ts
2
+ import { createComponent } from "@lit-labs/react";
3
+ import { Popover2 as Popover2Element } from "@prosekit/lit/elements/popover2";
4
+ import React from "react";
5
+ var Popover2 = createComponent({
6
+ tagName: "prosekit-popover2",
7
+ elementClass: Popover2Element,
8
+ react: React,
9
+ displayName: "Popover2"
10
+ });
11
+ export {
12
+ Popover2
13
+ };
@@ -0,0 +1,13 @@
1
+ // src/components/slash-popover.gen.ts
2
+ import { createComponent } from "@lit-labs/react";
3
+ import { SlashPopover as SlashPopoverElement } from "@prosekit/lit/elements/slash-popover";
4
+ import React from "react";
5
+ var SlashPopover = createComponent({
6
+ tagName: "prosekit-slash-popover",
7
+ elementClass: SlashPopoverElement,
8
+ react: React,
9
+ displayName: "SlashPopover"
10
+ });
11
+ export {
12
+ SlashPopover
13
+ };
@@ -0,0 +1,93 @@
1
+ // src/components/prosekit.tsx
2
+ import { ProseKitError as ProseKitError2, createEditor } from "@prosekit/core";
3
+ import { useEffect, useMemo } from "react";
4
+
5
+ // src/contexts/editor-context.tsx
6
+ import { ProseKitError } from "@prosekit/core";
7
+ import { createContext, useContext } from "react";
8
+ import { jsxDEV } from "react/jsx-dev-runtime";
9
+ var context = createContext(null);
10
+ var EditorContextProvider = ({
11
+ value,
12
+ children
13
+ }) => {
14
+ return /* @__PURE__ */ jsxDEV(context.Provider, { value, children }, void 0, false, {
15
+ fileName: "src/contexts/editor-context.tsx",
16
+ lineNumber: 19,
17
+ columnNumber: 10
18
+ }, this);
19
+ };
20
+ function useEditorContext() {
21
+ const value = useContext(context);
22
+ if (!value) {
23
+ throw new ProseKitError(
24
+ "useEditorContext must be used within the ProseKit component"
25
+ );
26
+ }
27
+ return value;
28
+ }
29
+
30
+ // src/components/prosekit.tsx
31
+ import { jsxDEV as jsxDEV2 } from "react/jsx-dev-runtime";
32
+ var ProseKit = (props) => {
33
+ const place = props.place;
34
+ const editor = useEditorMemo(props.editor, props.extension);
35
+ useEffect(() => {
36
+ if (place) {
37
+ editor.mount(place);
38
+ } else if (editor.mounted) {
39
+ editor.unmount();
40
+ }
41
+ }, [editor, place]);
42
+ return /* @__PURE__ */ jsxDEV2(EditorContextProvider, { value: { editor }, children: props.children }, void 0, false, {
43
+ fileName: "src/components/prosekit.tsx",
44
+ lineNumber: 26,
45
+ columnNumber: 5
46
+ }, this);
47
+ };
48
+ function useEditorMemo(editor, extension) {
49
+ return useMemo(() => {
50
+ if (editor) {
51
+ if (extension) {
52
+ throw new ProseKitError2(
53
+ "You can't pass both an editor and an extension to ProseKit"
54
+ );
55
+ }
56
+ return editor;
57
+ } else {
58
+ if (extension) {
59
+ return createEditor({ extension });
60
+ } else {
61
+ throw new ProseKitError2(
62
+ "You must pass either an editor or an extension to ProseKit"
63
+ );
64
+ }
65
+ }
66
+ }, [editor, extension]);
67
+ }
68
+
69
+ // src/hooks/use-editor.ts
70
+ function useEditor() {
71
+ return useEditorContext().editor;
72
+ }
73
+
74
+ // src/hooks/use-extension.ts
75
+ import { useEffect as useEffect2 } from "react";
76
+ function useExtension({ extension }) {
77
+ const editor = useEditor();
78
+ useEffect2(() => editor.use(extension), [editor, extension]);
79
+ }
80
+
81
+ // src/hooks/use-keymap.ts
82
+ import { addKeymap } from "@prosekit/core";
83
+ import { useMemo as useMemo2 } from "react";
84
+ function useKeymap({ keymap }) {
85
+ const extension = useMemo2(() => addKeymap(keymap), [keymap]);
86
+ useExtension({ extension });
87
+ }
88
+ export {
89
+ ProseKit,
90
+ useEditor,
91
+ useExtension,
92
+ useKeymap
93
+ };
package/package.json ADDED
@@ -0,0 +1,89 @@
1
+ {
2
+ "name": "@prosekit/react",
3
+ "type": "module",
4
+ "version": "0.0.0-next-20230627094841",
5
+ "private": false,
6
+ "author": {
7
+ "name": "ocavue",
8
+ "email": "ocavue@gmail.com"
9
+ },
10
+ "license": "MIT",
11
+ "funding": "https://github.com/sponsors/ocavue",
12
+ "homepage": "https://github.com/ocavue/prosekit#readme",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/ocavue/prosekit.git",
16
+ "directory": "packages/react"
17
+ },
18
+ "bugs": {
19
+ "url": "https://github.com/ocavue/prosekit/issues"
20
+ },
21
+ "keywords": [
22
+ "ProseMirror"
23
+ ],
24
+ "sideEffects": false,
25
+ "main": "./dist/prosekit-react.js",
26
+ "module": "./dist/prosekit-react.js",
27
+ "exports": {
28
+ ".": {
29
+ "types": "./dist/prosekit-react.d.ts",
30
+ "import": "./dist/prosekit-react.js",
31
+ "default": "./dist/prosekit-react.js"
32
+ },
33
+ "./components/menu": {
34
+ "types": "./dist/prosekit-react-components-menu.d.ts",
35
+ "import": "./dist/prosekit-react-components-menu.js",
36
+ "default": "./dist/prosekit-react-components-menu.js"
37
+ },
38
+ "./components/menu-item": {
39
+ "types": "./dist/prosekit-react-components-menu-item.d.ts",
40
+ "import": "./dist/prosekit-react-components-menu-item.js",
41
+ "default": "./dist/prosekit-react-components-menu-item.js"
42
+ },
43
+ "./components/popover": {
44
+ "types": "./dist/prosekit-react-components-popover.d.ts",
45
+ "import": "./dist/prosekit-react-components-popover.js",
46
+ "default": "./dist/prosekit-react-components-popover.js"
47
+ },
48
+ "./components/popover-suggestion": {
49
+ "types": "./dist/prosekit-react-components-popover-suggestion.d.ts",
50
+ "import": "./dist/prosekit-react-components-popover-suggestion.js",
51
+ "default": "./dist/prosekit-react-components-popover-suggestion.js"
52
+ }
53
+ },
54
+ "files": [
55
+ "dist"
56
+ ],
57
+ "dependencies": {
58
+ "@lit-labs/react": "latest",
59
+ "@prosekit/core": "0.0.0-next-20230627094841",
60
+ "@prosekit/lit": "0.0.0-next-20230627094841"
61
+ },
62
+ "peerDependencies": {
63
+ "react": ">= 17.0.0",
64
+ "react-dom": ">= 17.0.0"
65
+ },
66
+ "peerDependenciesMeta": {
67
+ "react": {
68
+ "optional": true
69
+ },
70
+ "react-dom": {
71
+ "optional": true
72
+ }
73
+ },
74
+ "devDependencies": {
75
+ "@types/react": "^18.2.14",
76
+ "@types/react-dom": "^18.2.6",
77
+ "react": "^18.2.0",
78
+ "react-dom": "^18.2.0",
79
+ "tsup": "^7.1.0",
80
+ "typescript": "^5.1.3",
81
+ "vitest": "^0.32.2",
82
+ "@prosekit/dev": "0.0.0"
83
+ },
84
+ "scripts": {
85
+ "build:tsup": "tsup",
86
+ "build:tsc": "tsc -b tsconfig.json"
87
+ },
88
+ "types": "./dist/prosekit-react.d.ts"
89
+ }
package/src/index.ts ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @module @prosekit/react
3
+ */
4
+
5
+ export { ProseKit, type ProseKitProps } from './components/prosekit'
6
+ export { useEditor } from './hooks/use-editor'
7
+ export { useExtension } from './hooks/use-extension'
8
+ export { useKeymap } from './hooks/use-keymap'