@welshman/editor 0.0.1 → 0.0.3
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 +1 -1
- package/dist/components/EditBolt11.svelte +10 -0
- package/dist/components/EditBolt11.svelte.d.ts +20 -0
- package/dist/components/EditEvent.svelte +11 -0
- package/dist/components/EditEvent.svelte.d.ts +20 -0
- package/dist/components/EditMedia.svelte +10 -0
- package/dist/components/EditMedia.svelte.d.ts +20 -0
- package/dist/components/EditMention.svelte +10 -0
- package/dist/components/EditMention.svelte.d.ts +20 -0
- package/dist/components/SuggestionString.svelte +4 -0
- package/dist/components/SuggestionString.svelte.d.ts +18 -0
- package/dist/components/Suggestions.svelte +71 -0
- package/dist/components/Suggestions.svelte.d.ts +41 -0
- package/dist/components/index.d.ts +6 -0
- package/dist/components/index.js +6 -0
- package/dist/extensions/BreakOrSubmit.d.ts +8 -0
- package/dist/extensions/BreakOrSubmit.js +12 -0
- package/dist/extensions/CodeInline.d.ts +4 -0
- package/dist/extensions/CodeInline.js +65 -0
- package/dist/extensions/Welshman.d.ts +45 -0
- package/dist/extensions/Welshman.js +153 -0
- package/dist/extensions/WordCount.d.ts +2 -0
- package/dist/extensions/WordCount.js +15 -0
- package/dist/extensions/index.d.ts +4 -0
- package/dist/extensions/index.js +4 -0
- package/dist/index.css +105 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/plugins/TippySuggestion.d.ts +20 -0
- package/dist/plugins/TippySuggestion.js +98 -0
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins/index.js +1 -0
- package/package.json +78 -56
- package/build/index.js +0 -51735
- package/build/index.js.map +0 -1
- package/build/tsconfig.tsbuildinfo +0 -1
package/dist/index.css
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--tiptap-object-bg: #eee;
|
|
3
|
+
--tiptap-object-fg: #111;
|
|
4
|
+
--tiptap-active-bg: #ddd;
|
|
5
|
+
--tiptap-active-fg: #111;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.tiptap {
|
|
9
|
+
outline: none;
|
|
10
|
+
min-height: 0;
|
|
11
|
+
height: 100%;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.tiptap p.is-editor-empty:first-child::before {
|
|
15
|
+
color: #adb5bd;
|
|
16
|
+
content: attr(data-placeholder);
|
|
17
|
+
float: left;
|
|
18
|
+
height: 0;
|
|
19
|
+
pointer-events: none;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.tiptap pre code {
|
|
23
|
+
display: block;
|
|
24
|
+
max-width: 100%;
|
|
25
|
+
overflow: auto;
|
|
26
|
+
padding: 0.25rem;
|
|
27
|
+
background-color: var(--tiptap-object-bg);
|
|
28
|
+
color: var(--tiptap-object-fg);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.tiptap .tiptap-object,
|
|
32
|
+
.tiptap p code,
|
|
33
|
+
.tiptap [tag] {
|
|
34
|
+
max-width: 100%;
|
|
35
|
+
overflow: hidden;
|
|
36
|
+
text-overflow: ellipsis;
|
|
37
|
+
white-space: nowrap;
|
|
38
|
+
border-radius: 3px;
|
|
39
|
+
padding: 0 0.25rem;
|
|
40
|
+
background-color: var(--tiptap-object-bg);
|
|
41
|
+
color: var(--tiptap-object-fg);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.tiptap .tiptap-active {
|
|
45
|
+
background-color: var(--tiptap-active-bg);
|
|
46
|
+
color: var(--tiptap-active-fg);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.tiptap .tiptap-uploading {
|
|
50
|
+
animation: tiptapFileUpload 1.5s infinite;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.tiptap-suggestions {
|
|
54
|
+
margin-top: 0.5rem;
|
|
55
|
+
max-height: 350px;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.tiptap-suggestions__content {
|
|
59
|
+
border-radius: 3px;
|
|
60
|
+
box-shadow: 0px 5px 8px 0px rgba(0, 0, 0, 0.2);
|
|
61
|
+
overflow-y: auto;
|
|
62
|
+
overflow-x: hidden;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.tiptap-suggestions__create,
|
|
66
|
+
.tiptap-suggestions__item {
|
|
67
|
+
white-space: nowrap;
|
|
68
|
+
display: block;
|
|
69
|
+
width: 100%;
|
|
70
|
+
min-width: 0px;
|
|
71
|
+
cursor: pointer;
|
|
72
|
+
overflow-x: hidden;
|
|
73
|
+
text-overflow: ellipsis;
|
|
74
|
+
padding: 0.5rem 1rem;
|
|
75
|
+
text-align: left;
|
|
76
|
+
transition-duration: 100ms;
|
|
77
|
+
transition-property: color background-color;
|
|
78
|
+
background-color: var(--tiptap-object-bg);
|
|
79
|
+
color: var(--tiptap-object-fg);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.tiptap-suggestions__selected,
|
|
83
|
+
.tiptap-suggestions__create:hover,
|
|
84
|
+
.tiptap-suggestions__item:hover {
|
|
85
|
+
background-color: var(--tiptap-active-bg);
|
|
86
|
+
color: var(--tiptap-active-fg);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.tiptap-suggestions__empty {
|
|
90
|
+
display: flex;
|
|
91
|
+
gap: 0.5rem;
|
|
92
|
+
padding: 0.5rem 1rem;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
@keyframes tiptapFileUpload {
|
|
96
|
+
0% {
|
|
97
|
+
opacity: 0.2;
|
|
98
|
+
}
|
|
99
|
+
50% {
|
|
100
|
+
opacity: 1;
|
|
101
|
+
}
|
|
102
|
+
100% {
|
|
103
|
+
opacity: 0.2;
|
|
104
|
+
}
|
|
105
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ComponentType } from "svelte";
|
|
2
|
+
import type { Readable } from "svelte/store";
|
|
3
|
+
import type { Editor } from "svelte-tiptap";
|
|
4
|
+
export type TippySuggestionOptions = {
|
|
5
|
+
char: string;
|
|
6
|
+
name: string;
|
|
7
|
+
editor: Editor;
|
|
8
|
+
search: Readable<(term: string) => string[]>;
|
|
9
|
+
select: (value: string, props: any) => void;
|
|
10
|
+
allowCreate?: boolean;
|
|
11
|
+
wrapper?: ComponentType;
|
|
12
|
+
component?: ComponentType;
|
|
13
|
+
};
|
|
14
|
+
export declare const TippySuggestion: ({ char, name, editor, search, select, allowCreate, wrapper, component, }: TippySuggestionOptions) => import("prosemirror-state").Plugin<any>;
|
|
15
|
+
export type MentionSuggestionOptions = Partial<TippySuggestionOptions> & {
|
|
16
|
+
editor: Editor;
|
|
17
|
+
search: Readable<(term: string) => string[]>;
|
|
18
|
+
getRelays: (pubkey: string) => string[];
|
|
19
|
+
};
|
|
20
|
+
export declare const MentionSuggestion: (options: MentionSuggestionOptions) => import("prosemirror-state").Plugin<any>;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import tippy from "tippy.js";
|
|
2
|
+
import { nprofileEncode } from "nostr-tools/nip19";
|
|
3
|
+
import { PluginKey } from "@tiptap/pm/state";
|
|
4
|
+
import Suggestion from "@tiptap/suggestion";
|
|
5
|
+
import Suggestions from "../components/Suggestions.svelte";
|
|
6
|
+
import SuggestionString from "../components/SuggestionString.svelte";
|
|
7
|
+
export const TippySuggestion = ({ char, name, editor, search, select, allowCreate, wrapper = Suggestions, component = SuggestionString, }) => Suggestion({
|
|
8
|
+
char,
|
|
9
|
+
editor,
|
|
10
|
+
pluginKey: new PluginKey(`suggest-${name}`),
|
|
11
|
+
command: ({ editor, range, props }) => {
|
|
12
|
+
// increase range.to by one when the next node is of type "text"
|
|
13
|
+
// and starts with a space character
|
|
14
|
+
const nodeAfter = editor.view.state.selection.$to.nodeAfter;
|
|
15
|
+
const overrideSpace = nodeAfter?.text?.startsWith(" ");
|
|
16
|
+
if (overrideSpace) {
|
|
17
|
+
range.to += 1;
|
|
18
|
+
}
|
|
19
|
+
editor
|
|
20
|
+
.chain()
|
|
21
|
+
.focus()
|
|
22
|
+
.insertContentAt(range, [
|
|
23
|
+
{ type: name, attrs: props },
|
|
24
|
+
{ type: "text", text: " " },
|
|
25
|
+
])
|
|
26
|
+
.run();
|
|
27
|
+
window.getSelection()?.collapseToEnd();
|
|
28
|
+
},
|
|
29
|
+
allow: ({ state, range }) => {
|
|
30
|
+
const $from = state.doc.resolve(range.from);
|
|
31
|
+
const type = state.schema.nodes[name];
|
|
32
|
+
return !!$from.parent.type.contentMatch.matchType(type);
|
|
33
|
+
},
|
|
34
|
+
render: () => {
|
|
35
|
+
let popover;
|
|
36
|
+
let suggestions;
|
|
37
|
+
const mapProps = (props) => ({
|
|
38
|
+
term: props.query,
|
|
39
|
+
search,
|
|
40
|
+
component,
|
|
41
|
+
allowCreate,
|
|
42
|
+
select: (value) => select(value, props),
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
onStart: props => {
|
|
46
|
+
const target = document.createElement("div");
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
popover = tippy("body", {
|
|
49
|
+
getReferenceClientRect: props.clientRect,
|
|
50
|
+
appendTo: document.querySelector("dialog[open]") || document.body,
|
|
51
|
+
content: target,
|
|
52
|
+
showOnCreate: true,
|
|
53
|
+
interactive: true,
|
|
54
|
+
trigger: "manual",
|
|
55
|
+
placement: "bottom-start",
|
|
56
|
+
});
|
|
57
|
+
if (!props.query)
|
|
58
|
+
popover[0].hide();
|
|
59
|
+
suggestions = new wrapper({ target, props: mapProps(props) });
|
|
60
|
+
},
|
|
61
|
+
onUpdate: props => {
|
|
62
|
+
if (props.query) {
|
|
63
|
+
popover[0].show();
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
popover[0].hide();
|
|
67
|
+
}
|
|
68
|
+
suggestions.$set(mapProps(props));
|
|
69
|
+
if (props.clientRect) {
|
|
70
|
+
popover[0].setProps({
|
|
71
|
+
getReferenceClientRect: props.clientRect,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
onKeyDown: props => {
|
|
76
|
+
if (props.event.key === "Escape") {
|
|
77
|
+
popover[0].hide();
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
return Boolean(suggestions.onKeyDown?.(props.event));
|
|
81
|
+
},
|
|
82
|
+
onExit: () => {
|
|
83
|
+
popover[0].destroy();
|
|
84
|
+
suggestions.$destroy();
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
export const MentionSuggestion = (options) => TippySuggestion({
|
|
90
|
+
char: "@",
|
|
91
|
+
name: "nprofile",
|
|
92
|
+
select: (pubkey, props) => {
|
|
93
|
+
const relays = options.getRelays(pubkey);
|
|
94
|
+
const nprofile = nprofileEncode({ pubkey, relays });
|
|
95
|
+
return props.command({ pubkey, relays, nprofile });
|
|
96
|
+
},
|
|
97
|
+
...options,
|
|
98
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./TippySuggestion.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./TippySuggestion.js";
|
package/package.json
CHANGED
|
@@ -1,58 +1,80 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
2
|
+
"name": "@welshman/editor",
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"scripts": {
|
|
5
|
+
"pub": "npm run check && npm run build && npm publish",
|
|
6
|
+
"fix": "",
|
|
7
|
+
"dev": "vite dev",
|
|
8
|
+
"build": "vite build && npm run package",
|
|
9
|
+
"package": "svelte-kit sync && svelte-package && publint",
|
|
10
|
+
"prepublishOnly": "npm run package",
|
|
11
|
+
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
|
12
|
+
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"!dist/**/*.test.*",
|
|
17
|
+
"!dist/**/*.spec.*"
|
|
18
|
+
],
|
|
19
|
+
"sideEffects": [
|
|
20
|
+
"**/*.css"
|
|
21
|
+
],
|
|
22
|
+
"svelte": "./dist/index.js",
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"type": "module",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"svelte": "./dist/index.js"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"@tiptap/core": "^2.9.1",
|
|
33
|
+
"@tiptap/extension-code": "^2.9.1",
|
|
34
|
+
"@tiptap/extension-code-block": "^2.9.1",
|
|
35
|
+
"@tiptap/extension-document": "^2.9.1",
|
|
36
|
+
"@tiptap/extension-dropcursor": "^2.9.1",
|
|
37
|
+
"@tiptap/extension-gapcursor": "^2.9.1",
|
|
38
|
+
"@tiptap/extension-hard-break": "^2.9.1",
|
|
39
|
+
"@tiptap/extension-history": "^2.9.1",
|
|
40
|
+
"@tiptap/extension-paragraph": "^2.9.1",
|
|
41
|
+
"@tiptap/extension-placeholder": "^2.9.1",
|
|
42
|
+
"@tiptap/extension-text": "^2.9.1",
|
|
43
|
+
"@tiptap/pm": "^2.9.1",
|
|
44
|
+
"@tiptap/suggestion": "^2.9.1",
|
|
45
|
+
"@welshman/lib": "^0.0.36",
|
|
46
|
+
"@welshman/util": "^0.0.53",
|
|
47
|
+
"nostr-editor": "github:cesardeazevedo/nostr-editor#a211491c",
|
|
48
|
+
"nostr-tools": "^2.8.1",
|
|
49
|
+
"svelte": "^4.0.0",
|
|
50
|
+
"svelte-tiptap": "^1.0.0"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@sveltejs/kit": "^2.0.0",
|
|
54
|
+
"@sveltejs/package": "^2.0.0",
|
|
55
|
+
"@sveltejs/vite-plugin-svelte": "^3.0.0",
|
|
56
|
+
"@tiptap/core": "^2.9.1",
|
|
57
|
+
"@tiptap/extension-code": "^2.9.1",
|
|
58
|
+
"@tiptap/extension-code-block": "^2.9.1",
|
|
59
|
+
"@tiptap/extension-document": "^2.9.1",
|
|
60
|
+
"@tiptap/extension-dropcursor": "^2.9.1",
|
|
61
|
+
"@tiptap/extension-gapcursor": "^2.9.1",
|
|
62
|
+
"@tiptap/extension-hard-break": "^2.9.1",
|
|
63
|
+
"@tiptap/extension-history": "^2.9.1",
|
|
64
|
+
"@tiptap/extension-paragraph": "^2.9.1",
|
|
65
|
+
"@tiptap/extension-placeholder": "^2.9.1",
|
|
66
|
+
"@tiptap/extension-text": "^2.9.1",
|
|
67
|
+
"@tiptap/pm": "^2.9.1",
|
|
68
|
+
"@welshman/lib": "^0.0.36",
|
|
69
|
+
"@welshman/util": "^0.0.53",
|
|
70
|
+
"nostr-editor": "github:cesardeazevedo/nostr-editor#a211491c",
|
|
71
|
+
"nostr-tools": "^2.10.4",
|
|
72
|
+
"publint": "^0.2.0",
|
|
73
|
+
"svelte": "^4.0.0",
|
|
74
|
+
"svelte-check": "^4.0.0",
|
|
75
|
+
"svelte-tiptap": "^1.0.0",
|
|
76
|
+
"tippy.js": "^6.0.0",
|
|
77
|
+
"typescript": "^5.0.0",
|
|
78
|
+
"vite": "^6.0.0"
|
|
79
|
+
}
|
|
58
80
|
}
|