@docs.plus/extension-hyperlink 1.5.1 → 4.3.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.
@@ -0,0 +1,323 @@
1
+ /**
2
+ * @docs.plus/extension-hyperlink — default styles
3
+ *
4
+ * A minimal, framework-agnostic stylesheet for the prebuilt create/preview/edit
5
+ * popovers. Every visual token is exposed as a `--hl-*` CSS custom property so
6
+ * consumers can retheme without copy-pasting rules.
7
+ *
8
+ * Usage:
9
+ * import '@docs.plus/extension-hyperlink/styles.css'
10
+ *
11
+ * Theming:
12
+ * :root {
13
+ * --hl-accent: #2563eb;
14
+ * --hl-radius: 8px;
15
+ * }
16
+ *
17
+ * Customizing a specific rule is fine — class names are part of the public API
18
+ * and are documented in the README.
19
+ */
20
+
21
+ /*
22
+ * Theme tokens use `light-dark()` so the popover follows the nearest
23
+ * ancestor's `color-scheme` — that means a consumer who toggles
24
+ * `color-scheme: light | dark` on <html> (or an ancestor) flips the
25
+ * popover automatically, and it no longer gets stuck in dark mode just
26
+ * because the OS prefers dark. When `color-scheme` is `normal` (the
27
+ * default), `light-dark()` falls back to `prefers-color-scheme`, which
28
+ * preserves the previous OS-driven behaviour for unopinionated hosts.
29
+ */
30
+ :root {
31
+ --hl-bg: light-dark(#ffffff, #1f2937);
32
+ --hl-fg: light-dark(#111827, #f3f4f6);
33
+ --hl-muted: light-dark(#6b7280, #9ca3af);
34
+ --hl-border: light-dark(#e5e7eb, #374151);
35
+ --hl-hover: light-dark(#f3f4f6, #374151);
36
+ --hl-accent: light-dark(#2563eb, #60a5fa);
37
+ --hl-accent-fg: light-dark(#ffffff, #0b1220);
38
+ --hl-danger: light-dark(#dc2626, #f87171);
39
+ --hl-shadow:
40
+ 0 1px 2px light-dark(rgba(0, 0, 0, 0.06), rgba(0, 0, 0, 0.4)),
41
+ 0 4px 12px light-dark(rgba(0, 0, 0, 0.08), rgba(0, 0, 0, 0.5));
42
+ --hl-radius: 6px;
43
+ --hl-radius-sm: 4px;
44
+ --hl-font:
45
+ ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
46
+ --hl-font-size: 14px;
47
+ --hl-z-index: 9999;
48
+ --hl-transition: 120ms ease-in-out;
49
+ }
50
+
51
+ /* -------------------------------------------------------------------------
52
+ Floating toolbar shell (shared by all three popovers)
53
+ ------------------------------------------------------------------------- */
54
+ .floating-toolbar {
55
+ position: absolute;
56
+ top: 0;
57
+ left: 0;
58
+ z-index: var(--hl-z-index);
59
+ opacity: 0;
60
+ transform: scale(0.96);
61
+ transition:
62
+ opacity var(--hl-transition),
63
+ transform var(--hl-transition);
64
+ pointer-events: none;
65
+ -webkit-tap-highlight-color: transparent;
66
+ will-change: transform, opacity;
67
+ }
68
+
69
+ .floating-toolbar.visible {
70
+ opacity: 1;
71
+ transform: scale(1);
72
+ pointer-events: auto;
73
+ }
74
+
75
+ .floating-toolbar-arrow {
76
+ position: absolute;
77
+ width: 10px;
78
+ height: 10px;
79
+ background: var(--hl-bg);
80
+ transform: rotate(45deg);
81
+ pointer-events: none;
82
+ z-index: 1;
83
+ }
84
+
85
+ .floating-toolbar-arrow-top {
86
+ border-right: 1px solid var(--hl-border);
87
+ border-bottom: 1px solid var(--hl-border);
88
+ }
89
+
90
+ .floating-toolbar-arrow-bottom {
91
+ border-top: 1px solid var(--hl-border);
92
+ border-left: 1px solid var(--hl-border);
93
+ }
94
+
95
+ .floating-toolbar-arrow-left {
96
+ border-right: 1px solid var(--hl-border);
97
+ border-bottom: 1px solid var(--hl-border);
98
+ }
99
+
100
+ .floating-toolbar-arrow-right {
101
+ border-top: 1px solid var(--hl-border);
102
+ border-left: 1px solid var(--hl-border);
103
+ }
104
+
105
+ .floating-toolbar-content {
106
+ position: relative;
107
+ z-index: 2;
108
+ }
109
+
110
+ /* -------------------------------------------------------------------------
111
+ Popover shell — shared shape for create / preview / edit
112
+ ------------------------------------------------------------------------- */
113
+ .hyperlink-create-popover,
114
+ .hyperlink-preview-popover,
115
+ .hyperlink-edit-popover {
116
+ display: flex;
117
+ align-items: center;
118
+ gap: 6px;
119
+ padding: 8px;
120
+ background: var(--hl-bg);
121
+ color: var(--hl-fg);
122
+ border: 1px solid var(--hl-border);
123
+ border-radius: var(--hl-radius);
124
+ box-shadow: var(--hl-shadow);
125
+ font-family: var(--hl-font);
126
+ font-size: var(--hl-font-size);
127
+ line-height: 1.4;
128
+ }
129
+
130
+ .hyperlink-create-popover form,
131
+ .hyperlink-edit-popover {
132
+ display: flex;
133
+ align-items: center;
134
+ gap: 8px;
135
+ margin: 0;
136
+ width: 100%;
137
+ }
138
+
139
+ /* Input groups (create + edit) */
140
+ .hyperlink-create-popover .inputs-wrapper,
141
+ .hyperlink-edit-popover .text-wrapper,
142
+ .hyperlink-edit-popover .href-wrapper {
143
+ position: relative;
144
+ display: flex;
145
+ align-items: center;
146
+ gap: 6px;
147
+ width: 100%;
148
+ padding: 6px 8px;
149
+ background: var(--hl-bg);
150
+ border: 1px solid var(--hl-border);
151
+ border-radius: var(--hl-radius-sm);
152
+ transition:
153
+ border-color var(--hl-transition),
154
+ box-shadow var(--hl-transition);
155
+ }
156
+
157
+ .hyperlink-create-popover .inputs-wrapper:focus-within,
158
+ .hyperlink-edit-popover .text-wrapper:focus-within,
159
+ .hyperlink-edit-popover .href-wrapper:focus-within {
160
+ border-color: var(--hl-accent);
161
+ box-shadow: 0 0 0 1px var(--hl-accent);
162
+ }
163
+
164
+ .hyperlink-create-popover .inputs-wrapper.error,
165
+ .hyperlink-edit-popover .text-wrapper.error,
166
+ .hyperlink-edit-popover .href-wrapper.error {
167
+ border-color: var(--hl-danger);
168
+ box-shadow: 0 0 0 1px var(--hl-danger);
169
+ }
170
+
171
+ .hyperlink-create-popover input,
172
+ .hyperlink-edit-popover input {
173
+ flex: 1;
174
+ min-width: 0;
175
+ padding: 0;
176
+ border: none;
177
+ outline: none;
178
+ background: transparent;
179
+ color: inherit;
180
+ font: inherit;
181
+ }
182
+
183
+ .hyperlink-create-popover input::placeholder,
184
+ .hyperlink-edit-popover input::placeholder {
185
+ color: var(--hl-muted);
186
+ }
187
+
188
+ .hyperlink-create-popover .search-icon,
189
+ .hyperlink-edit-popover .search-icon {
190
+ display: flex;
191
+ align-items: center;
192
+ flex-shrink: 0;
193
+ color: var(--hl-muted);
194
+ }
195
+
196
+ .hyperlink-create-popover .search-icon svg,
197
+ .hyperlink-edit-popover .search-icon svg {
198
+ width: 18px;
199
+ height: 18px;
200
+ }
201
+
202
+ .hyperlink-create-popover .error-message,
203
+ .hyperlink-edit-popover .error-message {
204
+ position: absolute;
205
+ top: -8px;
206
+ left: 8px;
207
+ display: none;
208
+ padding: 0 4px;
209
+ background: var(--hl-bg);
210
+ color: var(--hl-danger);
211
+ font-size: 11px;
212
+ font-weight: 600;
213
+ border-radius: var(--hl-radius-sm);
214
+ }
215
+
216
+ .hyperlink-create-popover .error-message.show,
217
+ .hyperlink-edit-popover .error-message.show {
218
+ display: block;
219
+ }
220
+
221
+ /* Action buttons (create submit + edit back/apply) */
222
+ .hyperlink-create-popover .buttons-wrapper,
223
+ .hyperlink-edit-popover .buttons-wrapper {
224
+ display: flex;
225
+ flex-shrink: 0;
226
+ gap: 4px;
227
+ }
228
+
229
+ .hyperlink-create-popover button[type='submit'],
230
+ .hyperlink-edit-popover .back-button,
231
+ .hyperlink-edit-popover .apply-button {
232
+ padding: 6px 12px;
233
+ background: transparent;
234
+ color: var(--hl-fg);
235
+ border: none;
236
+ border-radius: var(--hl-radius-sm);
237
+ font: inherit;
238
+ font-weight: 600;
239
+ white-space: nowrap;
240
+ cursor: pointer;
241
+ transition:
242
+ background-color var(--hl-transition),
243
+ color var(--hl-transition);
244
+ }
245
+
246
+ .hyperlink-create-popover button[type='submit']:hover:not(:disabled),
247
+ .hyperlink-edit-popover .back-button:hover,
248
+ .hyperlink-edit-popover .apply-button:hover {
249
+ background: var(--hl-accent);
250
+ color: var(--hl-accent-fg);
251
+ }
252
+
253
+ .hyperlink-create-popover button[type='submit']:disabled {
254
+ color: var(--hl-muted);
255
+ cursor: not-allowed;
256
+ }
257
+
258
+ /* -------------------------------------------------------------------------
259
+ Preview popover (anchor + copy / edit / remove icon buttons)
260
+ ------------------------------------------------------------------------- */
261
+ .hyperlink-preview-popover a {
262
+ display: inline-block;
263
+ max-width: 260px;
264
+ overflow: hidden;
265
+ text-overflow: ellipsis;
266
+ white-space: nowrap;
267
+ padding: 2px 6px;
268
+ color: var(--hl-accent);
269
+ text-decoration: none;
270
+ font-weight: 500;
271
+ }
272
+
273
+ .hyperlink-preview-popover a:hover {
274
+ text-decoration: underline;
275
+ }
276
+
277
+ .hyperlink-preview-popover button {
278
+ display: flex;
279
+ align-items: center;
280
+ justify-content: center;
281
+ padding: 5px;
282
+ background: transparent;
283
+ border: none;
284
+ border-radius: var(--hl-radius-sm);
285
+ color: var(--hl-fg);
286
+ cursor: pointer;
287
+ transition: background-color var(--hl-transition);
288
+ }
289
+
290
+ .hyperlink-preview-popover button:hover {
291
+ background: var(--hl-hover);
292
+ }
293
+
294
+ .hyperlink-preview-popover button svg {
295
+ width: 18px;
296
+ height: 18px;
297
+ }
298
+
299
+ .hyperlink-preview-popover .copy {
300
+ margin-left: auto;
301
+ }
302
+
303
+ /* -------------------------------------------------------------------------
304
+ Edit popover — stacked inputs on the left, stacked buttons on the right
305
+ ------------------------------------------------------------------------- */
306
+ .hyperlink-edit-popover {
307
+ align-items: flex-end;
308
+ }
309
+
310
+ .hyperlink-edit-popover .inputs-wrapper {
311
+ display: flex;
312
+ flex-direction: column;
313
+ align-items: stretch;
314
+ gap: 6px;
315
+ width: 100%;
316
+ }
317
+
318
+ .hyperlink-edit-popover .buttons-wrapper {
319
+ flex-direction: column;
320
+ align-items: stretch;
321
+ justify-content: flex-end;
322
+ gap: 6px;
323
+ }
package/package.json CHANGED
@@ -1,50 +1,97 @@
1
1
  {
2
2
  "name": "@docs.plus/extension-hyperlink",
3
- "description": "Hyperlink component for docs.plus",
4
- "version": "1.5.1",
3
+ "version": "4.3.0",
4
+ "description": "Tiptap extension for hyperlinks with built-in popovers, auto-linking, and 50+ URL scheme support",
5
+ "main": "./dist/index.cjs",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ },
14
+ "require": {
15
+ "types": "./dist/index.d.cts",
16
+ "default": "./dist/index.cjs"
17
+ }
18
+ },
19
+ "./styles.css": "./dist/styles.css",
20
+ "./package.json": "./package.json"
21
+ },
22
+ "sideEffects": [
23
+ "**/*.css"
24
+ ],
5
25
  "author": "Hossein Marzban",
6
- "homepage": "https://github.com/HMarzban/extension-hyperlink",
26
+ "license": "MIT",
27
+ "type": "module",
28
+ "homepage": "https://github.com/docs-plus/docs.plus/tree/main/packages/extension-hyperlink#readme",
29
+ "bugs": {
30
+ "url": "https://github.com/docs-plus/docs.plus/issues"
31
+ },
7
32
  "repository": {
8
33
  "type": "git",
9
34
  "url": "https://github.com/docs-plus/docs.plus",
10
35
  "directory": "packages/extension-hyperlink"
11
36
  },
37
+ "scripts": {
38
+ "build": "NODE_ENV=production bunx tsup",
39
+ "build:dev": "bunx tsup",
40
+ "dev": "bunx tsup --watch",
41
+ "lint": "eslint .",
42
+ "lint:fix": "eslint . --fix",
43
+ "playground": "bun --hot ./test/playground/server.ts",
44
+ "pretest": "bun run build",
45
+ "test": "bunx start-server-and-test playground http://127.0.0.1:5173 cy:run",
46
+ "test:open": "bunx start-server-and-test playground http://127.0.0.1:5173 cy:open",
47
+ "cy:run": "bunx cypress run",
48
+ "cy:open": "bunx cypress open",
49
+ "docs:screenshots": "bun run build && bunx start-server-and-test playground http://127.0.0.1:5173 'bunx cypress run --config specPattern=cypress/docs/**/*.cy.ts'",
50
+ "prepack": "bun run scripts/prepack.ts",
51
+ "prepublishOnly": "bun run scripts/preflight.ts"
52
+ },
53
+ "files": [
54
+ "dist",
55
+ "CHANGELOG.md",
56
+ "LICENSE"
57
+ ],
58
+ "publishConfig": {
59
+ "access": "public"
60
+ },
12
61
  "keywords": [
13
62
  "tiptap",
14
63
  "tiptap extension",
15
64
  "hyperlink",
16
65
  "link",
17
- "docs.plus",
18
- "prosemirror"
66
+ "autolink",
67
+ "rich-text-editor",
68
+ "floating-ui",
69
+ "url-validation",
70
+ "prosemirror",
71
+ "docs.plus"
19
72
  ],
20
- "exports": {
21
- ".": {
22
- "types": "./dist/index.d.ts",
23
- "import": "./dist/index.js",
24
- "require": "./dist/index.cjs"
25
- }
26
- },
27
- "type": "module",
28
- "main": "dist/index.cjs",
29
- "module": "dist/index.js",
30
- "umd": "dist/index.umd.js",
31
- "types": "dist/index.d.ts",
32
- "files": [
33
- "src",
34
- "dist"
35
- ],
36
- "scripts": {
37
- "clean": "rm -rf dist",
38
- "build": "npm run clean && rollup -c",
39
- "ts": "tsc -p tsconfig.json"
40
- },
41
- "license": "MIT",
42
73
  "dependencies": {
43
- "linkifyjs": "^4.1.1",
44
- "tippy.js": "^6.3.7"
74
+ "@floating-ui/dom": "^1.7.6",
75
+ "linkifyjs": "^4.3.2"
45
76
  },
46
77
  "peerDependencies": {
47
- "@tiptap/core": "^2.0.3",
48
- "@tiptap/pm": "^2.0.3"
78
+ "@tiptap/core": "^3.22.3",
79
+ "@tiptap/pm": "^3.22.3"
80
+ },
81
+ "devDependencies": {
82
+ "@eslint/js": "^9.39.4",
83
+ "@tiptap/core": "^3.22.3",
84
+ "@tiptap/pm": "^3.22.3",
85
+ "@tiptap/starter-kit": "^3.22.3",
86
+ "@types/node": "^25.5.2",
87
+ "@typescript-eslint/eslint-plugin": "^8.58.1",
88
+ "@typescript-eslint/parser": "^8.58.1",
89
+ "cypress": "^15.13.1",
90
+ "cypress-real-events": "^1.15.0",
91
+ "eslint": "^9.39.4",
92
+ "globals": "^17.4.0",
93
+ "start-server-and-test": "^2.1.0",
94
+ "tsup": "^8.5.1",
95
+ "typescript": "^5.9.3"
49
96
  }
50
97
  }
@@ -1,8 +0,0 @@
1
- import { MarkType } from "@tiptap/pm/model";
2
- import { Plugin } from "@tiptap/pm/state";
3
- type AutoHyperlinkOptions = {
4
- type: MarkType;
5
- validate?: (url: string) => boolean;
6
- };
7
- export default function autoHyperlink(options: AutoHyperlinkOptions): Plugin;
8
- export {};
@@ -1,11 +0,0 @@
1
- import { MarkType } from "@tiptap/pm/model";
2
- import { Plugin } from "@tiptap/pm/state";
3
- import { Editor } from "@tiptap/core";
4
- type ClickHandlerOptions = {
5
- type: MarkType;
6
- editor: Editor;
7
- validate?: (url: string) => boolean;
8
- modal?: ((options: any) => void | HTMLElement) | null;
9
- };
10
- export default function clickHandler(options: ClickHandlerOptions): Plugin;
11
- export {};
@@ -1,9 +0,0 @@
1
- import { Editor } from "@tiptap/core";
2
- type EditHyperlinkOptions = {
3
- editor: Editor;
4
- validate?: (url: string) => boolean;
5
- newURL?: string;
6
- newText?: string;
7
- };
8
- export default function editHyperlink(options: EditHyperlinkOptions): boolean;
9
- export {};
@@ -1,9 +0,0 @@
1
- import { Editor } from "@tiptap/core";
2
- import { MarkType } from "@tiptap/pm/model";
3
- import { Plugin } from "@tiptap/pm/state";
4
- type PasteHandlerOptions = {
5
- editor: Editor;
6
- type: MarkType;
7
- };
8
- export declare function pasteHandler(options: PasteHandlerOptions): Plugin;
9
- export {};
@@ -1,29 +0,0 @@
1
- import { Instance, Props } from "tippy.js";
2
- import { Editor } from "@tiptap/core";
3
- import { EditorView } from "@tiptap/pm/view";
4
- export interface TippyInitOptions {
5
- editor: Editor;
6
- validate?: (url: string) => boolean;
7
- }
8
- declare class Tooltip {
9
- private tippyInstance?;
10
- private preventHide;
11
- private tippyWrapper;
12
- private editor;
13
- private view;
14
- constructor(options: TippyInitOptions);
15
- init(): {
16
- tippyModal: HTMLDivElement;
17
- tippyInstance: Instance<Props> | undefined;
18
- };
19
- show(): boolean;
20
- hide(): boolean;
21
- private mousedownHandler;
22
- private dragstartHandler;
23
- private blurHandler;
24
- private tippyBlurHandler;
25
- private createTooltip;
26
- update(view: EditorView, option?: any): {};
27
- destroyTooltip(): void;
28
- }
29
- export default Tooltip;
@@ -1,77 +0,0 @@
1
- import { Mark } from "@tiptap/core";
2
- import { TSetHyperlinkModalOptions } from "./modals/setHyperlink";
3
- import { THyperlinkPreviewModalOptions } from "./modals/previewHyperlink";
4
- export interface LinkProtocolOptions {
5
- scheme: string;
6
- optionalSlashes?: boolean;
7
- }
8
- export interface HyperlinkOptions {
9
- /**
10
- * If enabled, it adds links as you type.
11
- */
12
- autoHyperlink: boolean;
13
- /**
14
- * An array of custom protocols to be registered with linkifyjs.
15
- */
16
- protocols: Array<LinkProtocolOptions | string>;
17
- /**
18
- * If enabled, links will be opened on click.
19
- */
20
- openOnClick: boolean;
21
- /**
22
- * Adds a link to the current selection if the pasted content only contains an url.
23
- */
24
- hyperlinkOnPaste: boolean;
25
- /**
26
- * A list of HTML attributes to be rendered.
27
- */
28
- HTMLAttributes: Record<string, any>;
29
- /**
30
- * A list of modals to be rendered.
31
- * @default null
32
- * @example
33
- */
34
- modals: {
35
- previewHyperlink?: ((options: THyperlinkPreviewModalOptions) => void | HTMLElement) | null;
36
- setHyperlink?: ((options: TSetHyperlinkModalOptions) => void | HTMLElement) | null;
37
- };
38
- /**
39
- * A validation function that modifies link verification for the auto linker.
40
- * @param url - The url to be validated.
41
- * @returns - True if the url is valid, false otherwise.
42
- */
43
- validate?: (url: string) => boolean;
44
- }
45
- declare module "@tiptap/core" {
46
- interface Commands<ReturnType> {
47
- link: {
48
- /**
49
- * Edit the hyperlink's text
50
- */
51
- editHyperLinkText: (text: string) => ReturnType;
52
- /**
53
- * Edit the hyperlink's href value
54
- */
55
- editHyperLinkHref: (href: string) => ReturnType;
56
- /**
57
- * Edit the hyperlink's
58
- */
59
- editHyperlink: (attributes?: {
60
- newText?: string;
61
- newURL?: string;
62
- }) => ReturnType;
63
- /**
64
- * Set a hyperlink
65
- */
66
- setHyperlink: (attributes?: {
67
- href: string;
68
- target?: string | null;
69
- }) => ReturnType;
70
- /**
71
- * Unset a link mark
72
- */
73
- unsetHyperlink: () => ReturnType;
74
- };
75
- }
76
- }
77
- export declare const Hyperlink: Mark<HyperlinkOptions, any>;