@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.
Files changed (36) hide show
  1. package/README.md +1 -1
  2. package/dist/components/EditBolt11.svelte +10 -0
  3. package/dist/components/EditBolt11.svelte.d.ts +20 -0
  4. package/dist/components/EditEvent.svelte +11 -0
  5. package/dist/components/EditEvent.svelte.d.ts +20 -0
  6. package/dist/components/EditMedia.svelte +10 -0
  7. package/dist/components/EditMedia.svelte.d.ts +20 -0
  8. package/dist/components/EditMention.svelte +10 -0
  9. package/dist/components/EditMention.svelte.d.ts +20 -0
  10. package/dist/components/SuggestionString.svelte +4 -0
  11. package/dist/components/SuggestionString.svelte.d.ts +18 -0
  12. package/dist/components/Suggestions.svelte +71 -0
  13. package/dist/components/Suggestions.svelte.d.ts +41 -0
  14. package/dist/components/index.d.ts +6 -0
  15. package/dist/components/index.js +6 -0
  16. package/dist/extensions/BreakOrSubmit.d.ts +8 -0
  17. package/dist/extensions/BreakOrSubmit.js +12 -0
  18. package/dist/extensions/CodeInline.d.ts +4 -0
  19. package/dist/extensions/CodeInline.js +65 -0
  20. package/dist/extensions/Welshman.d.ts +45 -0
  21. package/dist/extensions/Welshman.js +153 -0
  22. package/dist/extensions/WordCount.d.ts +2 -0
  23. package/dist/extensions/WordCount.js +15 -0
  24. package/dist/extensions/index.d.ts +4 -0
  25. package/dist/extensions/index.js +4 -0
  26. package/dist/index.css +105 -0
  27. package/dist/index.d.ts +4 -0
  28. package/dist/index.js +4 -0
  29. package/dist/plugins/TippySuggestion.d.ts +20 -0
  30. package/dist/plugins/TippySuggestion.js +98 -0
  31. package/dist/plugins/index.d.ts +1 -0
  32. package/dist/plugins/index.js +1 -0
  33. package/package.json +78 -56
  34. package/build/index.js +0 -51735
  35. package/build/index.js.map +0 -1
  36. 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
+ }
@@ -0,0 +1,4 @@
1
+ import './index.css';
2
+ export * from './components/index.js';
3
+ export * from './extensions/index.js';
4
+ export * from './plugins/index.js';
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ import './index.css';
2
+ export * from './components/index.js';
3
+ export * from './extensions/index.js';
4
+ export * from './plugins/index.js';
@@ -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
- "name": "@welshman/editor",
3
- "version": "0.0.1",
4
- "author": "hodlbod",
5
- "license": "MIT",
6
- "description": "A good batteries-included configuration of nostr-editor for svelte apps.",
7
- "publishConfig": {
8
- "access": "public"
9
- },
10
- "type": "module",
11
- "files": [
12
- "build"
13
- ],
14
- "engines": {
15
- "node": ">=10.0.0"
16
- },
17
- "types": "./build/src/index.d.ts",
18
- "exports": {
19
- ".": {
20
- "types": "./build/src/index.d.ts",
21
- "import": "./build/src/index.mjs",
22
- "require": "./build/src/index.cjs"
23
- }
24
- },
25
- "scripts": {
26
- "pub": "npm run lint && npm run build && npm publish",
27
- "build": "gts clean && rollup -c rollup.config.js",
28
- "lint": "gts lint",
29
- "fix": "gts fix"
30
- },
31
- "dependencies": {
32
- "@tiptap/core": "^2.10.3",
33
- "@tiptap/extension-code": "^2.10.3",
34
- "@tiptap/extension-code-block": "^2.10.3",
35
- "@tiptap/extension-document": "^2.10.3",
36
- "@tiptap/extension-dropcursor": "^2.10.3",
37
- "@tiptap/extension-gapcursor": "^2.10.3",
38
- "@tiptap/extension-hard-break": "^2.10.3",
39
- "@tiptap/extension-history": "^2.10.3",
40
- "@tiptap/extension-paragraph": "^2.10.3",
41
- "@tiptap/extension-placeholder": "^2.10.3",
42
- "@tiptap/extension-text": "^2.10.3",
43
- "@tiptap/extension-youtube": "^2.10.3",
44
- "@tiptap/pm": "^2.10.3",
45
- "@tiptap/starter-kit": "^2.10.3",
46
- "@tiptap/suggestion": "^2.10.3",
47
- "@welshman/app": "^0.0.34",
48
- "@welshman/lib": "^0.0.34",
49
- "@welshman/util": "^0.0.52",
50
- "nostr-editor": "^0.0.3",
51
- "nostr-tools": "^2.10.4",
52
- "prosemirror-model": "^1.24.1",
53
- "prosemirror-state": "^1.4.3",
54
- "svelte": "^4.2.19",
55
- "svelte-tiptap": "^1.1.3",
56
- "tippy.js": "^6.3.7"
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
  }