@yiitap/extension-video 0.17.1 → 0.18.1

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/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";/**
2
2
  * Copyright 2026 Yiitap
3
3
  * @license MIT
4
- **/Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("@tiptap/core"),c=/(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/,a=n.Node.create({name:"video",draggable:!0,addOptions(){return{inline:!1,HTMLAttributes:{}}},inline(){return this.options.inline},group(){return this.options.inline?"inline":"block"},addAttributes(){return{caption:{default:"",rendered:!1},src:{default:null,parseHTML:t=>t.firstElementChild?.src??""}}},parseHTML(){return[{tag:"video"}]},renderHTML({node:t,HTMLAttributes:e}){return["video",{caption:t.attrs.caption},["source",n.mergeAttributes(this.options.HTMLAttributes,e)]]},parseMarkdown:(t,e)=>{if(t.type==="html_block"||t.type==="html_inline"){const r=t.content,i=r.match(/<video\b([^>]*)>/i);if(!i)return{};const u=i[1],s=r.match(/<source\s+src="([^"]+)"/i),o=u.match(/caption="([^"]*)"/i);if(s)return e.createNode("video",{src:s[1],caption:o?o[1]:""})}return{}},renderMarkdown:t=>{const e=t.attrs?.src??"";return`<video caption="${t.attrs?.caption??""}" controls>
4
+ **/Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const o=require("@tiptap/core"),a=/(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/,c=o.Node.create({name:"video",draggable:!0,addOptions(){return{inline:!1,HTMLAttributes:{}}},inline(){return this.options.inline},group(){return this.options.inline?"inline":"block"},addAttributes(){return{caption:{default:"",rendered:!1},src:{default:null,parseHTML:t=>t.firstElementChild?.src??""}}},parseHTML(){return[{tag:"video"}]},renderHTML({node:t,HTMLAttributes:e}){return["video",{caption:t.attrs.caption},["source",o.mergeAttributes(this.options.HTMLAttributes,e)]]},parseMarkdown:(t,e)=>{if(t.type==="html_block"||t.type==="html_inline"){const r=t.content,n=r.match(/<video\b([^>]*)>/i);if(!n)return{};const d=n[1],i=r.match(/<source\s+src="([^"]+)"/i),s=d.match(/caption="([^"]*)"/i);if(i)return e.createNode("video",{src:i[1],caption:s?s[1]:""})}return{}},renderMarkdown:t=>{const e=t.attrs?.src??"";return`<video caption="${t.attrs?.caption??""}" controls>
5
5
  <source src="${e}">
6
- </video>`},addCommands(){return{setVideo:t=>({commands:e})=>e.insertContent({type:this.name,attrs:t})}},addInputRules(){return[n.nodeInputRule({find:c,type:this.type,getAttributes:t=>{const[e]=t;return{src:e}}})]}});exports.Video=a;exports.default=a;exports.inputRegex=c;
6
+ </video>`},addCommands(){return{setVideo:t=>({commands:e})=>e.insertContent({type:this.name,attrs:t}),uploadVideo:t=>({editor:e})=>{const r=e.storage.uploadManager?.onUpload;return r?(r(t,"video").then(n=>{e.commands.setVideo({src:n})}).catch(n=>{console.error("Upload failed:",n)}),!0):(console.warn("onUpload callback is not defined in UploadManager extension options."),!1)}}},addInputRules(){return[o.nodeInputRule({find:a,type:this.type,getAttributes:t=>{const[e]=t;return{src:e}}})]}});exports.Video=c;exports.default=c;exports.inputRegex=a;
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- var Video=(function(r,i){"use strict";/**
1
+ var Video=(function(o,i){"use strict";/**
2
2
  * Copyright 2026 Yiitap
3
3
  * @license MIT
4
- **/const s=/(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/,o=i.Node.create({name:"video",draggable:!0,addOptions(){return{inline:!1,HTMLAttributes:{}}},inline(){return this.options.inline},group(){return this.options.inline?"inline":"block"},addAttributes(){return{caption:{default:"",rendered:!1},src:{default:null,parseHTML:t=>t.firstElementChild?.src??""}}},parseHTML(){return[{tag:"video"}]},renderHTML({node:t,HTMLAttributes:e}){return["video",{caption:t.attrs.caption},["source",i.mergeAttributes(this.options.HTMLAttributes,e)]]},parseMarkdown:(t,e)=>{if(t.type==="html_block"||t.type==="html_inline"){const n=t.content,c=n.match(/<video\b([^>]*)>/i);if(!c)return{};const d=c[1],a=n.match(/<source\s+src="([^"]+)"/i),u=d.match(/caption="([^"]*)"/i);if(a)return e.createNode("video",{src:a[1],caption:u?u[1]:""})}return{}},renderMarkdown:t=>{const e=t.attrs?.src??"";return`<video caption="${t.attrs?.caption??""}" controls>
4
+ **/const s=/(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/,a=i.Node.create({name:"video",draggable:!0,addOptions(){return{inline:!1,HTMLAttributes:{}}},inline(){return this.options.inline},group(){return this.options.inline?"inline":"block"},addAttributes(){return{caption:{default:"",rendered:!1},src:{default:null,parseHTML:t=>t.firstElementChild?.src??""}}},parseHTML(){return[{tag:"video"}]},renderHTML({node:t,HTMLAttributes:e}){return["video",{caption:t.attrs.caption},["source",i.mergeAttributes(this.options.HTMLAttributes,e)]]},parseMarkdown:(t,e)=>{if(t.type==="html_block"||t.type==="html_inline"){const n=t.content,r=n.match(/<video\b([^>]*)>/i);if(!r)return{};const u=r[1],c=n.match(/<source\s+src="([^"]+)"/i),d=u.match(/caption="([^"]*)"/i);if(c)return e.createNode("video",{src:c[1],caption:d?d[1]:""})}return{}},renderMarkdown:t=>{const e=t.attrs?.src??"";return`<video caption="${t.attrs?.caption??""}" controls>
5
5
  <source src="${e}">
6
- </video>`},addCommands(){return{setVideo:t=>({commands:e})=>e.insertContent({type:this.name,attrs:t})}},addInputRules(){return[i.nodeInputRule({find:s,type:this.type,getAttributes:t=>{const[e]=t;return{src:e}}})]}});return r.Video=o,r.default=o,r.inputRegex=s,Object.defineProperties(r,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),r})({},TiptapCore);
6
+ </video>`},addCommands(){return{setVideo:t=>({commands:e})=>e.insertContent({type:this.name,attrs:t}),uploadVideo:t=>({editor:e})=>{const n=e.storage.uploadManager?.onUpload;return n?(n(t,"video").then(r=>{e.commands.setVideo({src:r})}).catch(r=>{console.error("Upload failed:",r)}),!0):(console.warn("onUpload callback is not defined in UploadManager extension options."),!1)}}},addInputRules(){return[i.nodeInputRule({find:s,type:this.type,getAttributes:t=>{const[e]=t;return{src:e}}})]}});return o.Video=a,o.default=a,o.inputRegex=s,Object.defineProperties(o,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),o})({},TiptapCore);
package/dist/index.mjs CHANGED
@@ -1,9 +1,9 @@
1
- import { Node as c, nodeInputRule as a, mergeAttributes as d } from "@tiptap/core";
1
+ import { Node as a, nodeInputRule as c, mergeAttributes as d } from "@tiptap/core";
2
2
  /**
3
3
  * Copyright 2026 Yiitap
4
4
  * @license MIT
5
5
  **/
6
- const u = /(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/, l = c.create({
6
+ const l = /(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/, p = a.create({
7
7
  name: "video",
8
8
  draggable: !0,
9
9
  addOptions() {
@@ -48,12 +48,12 @@ const u = /(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/, l = c.create({
48
48
  },
49
49
  parseMarkdown: (t, e) => {
50
50
  if (t.type === "html_block" || t.type === "html_inline") {
51
- const r = t.content, n = r.match(/<video\b([^>]*)>/i);
52
- if (!n) return {};
53
- const o = n[1], i = r.match(/<source\s+src="([^"]+)"/i), s = o.match(/caption="([^"]*)"/i);
54
- if (i)
51
+ const n = t.content, r = n.match(/<video\b([^>]*)>/i);
52
+ if (!r) return {};
53
+ const i = r[1], o = n.match(/<source\s+src="([^"]+)"/i), s = i.match(/caption="([^"]*)"/i);
54
+ if (o)
55
55
  return e.createNode("video", {
56
- src: i[1],
56
+ src: o[1],
57
57
  caption: s ? s[1] : ""
58
58
  });
59
59
  }
@@ -70,13 +70,23 @@ const u = /(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/, l = c.create({
70
70
  setVideo: (t) => ({ commands: e }) => e.insertContent({
71
71
  type: this.name,
72
72
  attrs: t
73
- })
73
+ }),
74
+ uploadVideo: (t) => ({ editor: e }) => {
75
+ const n = e.storage.uploadManager?.onUpload;
76
+ return n ? (n(t, "video").then((r) => {
77
+ e.commands.setVideo({ src: r });
78
+ }).catch((r) => {
79
+ console.error("Upload failed:", r);
80
+ }), !0) : (console.warn(
81
+ "onUpload callback is not defined in UploadManager extension options."
82
+ ), !1);
83
+ }
74
84
  };
75
85
  },
76
86
  addInputRules() {
77
87
  return [
78
- a({
79
- find: u,
88
+ c({
89
+ find: l,
80
90
  type: this.type,
81
91
  getAttributes: (t) => {
82
92
  const [e] = t;
@@ -87,7 +97,7 @@ const u = /(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/, l = c.create({
87
97
  }
88
98
  });
89
99
  export {
90
- l as Video,
91
- l as default,
92
- u as inputRegex
100
+ p as Video,
101
+ p as default,
102
+ l as inputRegex
93
103
  };
@@ -4,6 +4,7 @@ declare module '@tiptap/core' {
4
4
  interface Commands<ReturnType> {
5
5
  video: {
6
6
  setVideo: (options: any) => ReturnType;
7
+ uploadVideo: (file: File) => ReturnType;
7
8
  };
8
9
  }
9
10
  }
@@ -1 +1 @@
1
- {"version":3,"file":"video.d.ts","sourceRoot":"","sources":["../../src/video.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAkC,MAAM,cAAc,CAAA;AAEnE,eAAO,MAAM,UAAU,QAAqD,CAAA;AAE5E,OAAO,QAAQ,cAAc,CAAC;IAC5B,UAAU,QAAQ,CAAC,UAAU;QAC3B,KAAK,EAAE;YACL,QAAQ,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,UAAU,CAAA;SACvC,CAAA;KACF;CACF;AAED,eAAO,MAAM,KAAK,gBA2GhB,CAAA"}
1
+ {"version":3,"file":"video.d.ts","sourceRoot":"","sources":["../../src/video.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EAIL,MAAM,cAAc,CAAA;AAErB,eAAO,MAAM,UAAU,QAAqD,CAAA;AAE5E,OAAO,QAAQ,cAAc,CAAC;IAC5B,UAAU,QAAQ,CAAC,UAAU;QAC3B,KAAK,EAAE;YACL,QAAQ,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,UAAU,CAAA;YACtC,WAAW,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,UAAU,CAAA;SACxC,CAAA;KACF;CACF;AAED,eAAO,MAAM,KAAK,gBAgIhB,CAAA"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@yiitap/extension-video",
3
3
  "description": "Video extension",
4
- "version": "0.17.1",
4
+ "version": "0.18.1",
5
5
  "private": false,
6
6
  "author": {
7
7
  "name": "Yiitap",
package/src/video.ts CHANGED
@@ -1,4 +1,9 @@
1
- import { Node, nodeInputRule, mergeAttributes } from '@tiptap/core'
1
+ import {
2
+ Node,
3
+ nodeInputRule,
4
+ mergeAttributes,
5
+ type CommandProps,
6
+ } from '@tiptap/core'
2
7
 
3
8
  export const inputRegex = /(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/
4
9
 
@@ -6,6 +11,7 @@ declare module '@tiptap/core' {
6
11
  interface Commands<ReturnType> {
7
12
  video: {
8
13
  setVideo: (options: any) => ReturnType
14
+ uploadVideo: (file: File) => ReturnType
9
15
  }
10
16
  }
11
17
  }
@@ -101,6 +107,27 @@ export const Video = Node.create({
101
107
  attrs: options,
102
108
  })
103
109
  },
110
+ uploadVideo:
111
+ (file: File) =>
112
+ ({ editor }: CommandProps) => {
113
+ const onUpload = (editor.storage as any).uploadManager?.onUpload
114
+ if (!onUpload) {
115
+ console.warn(
116
+ 'onUpload callback is not defined in UploadManager extension options.'
117
+ )
118
+ return false
119
+ }
120
+
121
+ onUpload(file, 'video')
122
+ .then((url: string) => {
123
+ editor.commands.setVideo({ src: url })
124
+ })
125
+ .catch((err: Error) => {
126
+ console.error('Upload failed:', err)
127
+ })
128
+
129
+ return true
130
+ },
104
131
  }
105
132
  },
106
133