@jackuait/blok 0.21.1 → 0.23.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.
- package/README.md +12 -1
- package/dist/blok.cjs +1 -1
- package/dist/blok.iife.js +4 -4
- package/dist/blok.mjs +2 -2
- package/dist/blok.umd.js +41 -41
- package/dist/chunks/{blok-DxI1HQZC.mjs → blok-BmckXjmW.mjs} +2570 -2269
- package/dist/chunks/{blok-DrMzzi_n.cjs → blok-D4WXeg3t.cjs} +5 -5
- package/dist/chunks/{constants-DGJO_Nr-.cjs → constants-BbCnmzAr.cjs} +1 -1
- package/dist/chunks/{constants-0pfHI3Vc.mjs → constants-tXKHkDAG.mjs} +1 -1
- package/dist/chunks/{tools-DqspF7V9.mjs → tools-oXMAa9zD.mjs} +1 -1
- package/dist/chunks/{tools-sHA-2cBM.cjs → tools-tG5_UaWz.cjs} +1 -1
- package/dist/full.cjs +1 -1
- package/dist/full.mjs +3 -3
- package/dist/react.cjs +1 -1
- package/dist/react.mjs +69 -42
- package/dist/tools.cjs +1 -1
- package/dist/tools.mjs +2 -2
- package/package.json +1 -1
- package/src/components/modules/paste/index.ts +33 -6
- package/src/components/modules/paste/next-space-blocks.ts +520 -0
- package/src/components/modules/paste/notion-blocks-v3.ts +28 -4
- package/src/react/BlokEditor.tsx +63 -0
- package/src/react/index.ts +2 -0
- package/src/react/types.ts +13 -3
- package/src/react/useBlok.ts +18 -0
- package/types/react.d.ts +38 -3
package/dist/full.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./chunks/blok-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./chunks/blok-D4WXeg3t.cjs`),t=require(`./chunks/constants-BbCnmzAr.cjs`),n=require(`./chunks/objectSpread2-iNkE6aJh.cjs`),r=require(`./chunks/tools-tG5_UaWz.cjs`);var i={paragraph:{class:r.k,inlineToolbar:!0,config:{preserveBlank:!0}},header:{class:r.O,inlineToolbar:!0},list:{class:r.D,inlineToolbar:!0}},a=n.t(n.t({},i),{},{bold:{class:r.l},italic:{class:r.c},marker:{class:r.o},underline:{class:r.a},strikethrough:{class:r.i},link:{class:r.s}});exports.Blok=e.t,exports.Bold=r.l,exports.DATA_ATTR=t.ja,exports.Header=r.O,exports.Italic=r.c,exports.Link=r.s,exports.List=r.D,exports.Marker=r.o,exports.Paragraph=r.k,exports.Strikethrough=r.i,exports.Toggle=r.T,exports.Underline=r.a,exports.allTools=a,exports.defaultBlockTools=r.t,exports.defaultInlineTools=r.n,exports.defaultTools=i,exports.version=e.n;
|
package/dist/full.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { n as e, t } from "./chunks/blok-
|
|
2
|
-
import { ja as n } from "./chunks/constants-
|
|
1
|
+
import { n as e, t } from "./chunks/blok-BmckXjmW.mjs";
|
|
2
|
+
import { ja as n } from "./chunks/constants-tXKHkDAG.mjs";
|
|
3
3
|
import { t as r } from "./chunks/objectSpread2-jlBcdYeb.mjs";
|
|
4
|
-
import { D as i, O as a, T as o, a as s, c, i as l, k as u, l as d, n as f, o as p, s as m, t as h } from "./chunks/tools-
|
|
4
|
+
import { D as i, O as a, T as o, a as s, c, i as l, k as u, l as d, n as f, o as p, s as m, t as h } from "./chunks/tools-oXMAa9zD.mjs";
|
|
5
5
|
//#region src/full.ts
|
|
6
6
|
var g = {
|
|
7
7
|
paragraph: {
|
package/dist/react.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./chunks/chunk-BL1yB9zm.cjs`);const e=require(`./chunks/blok-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./chunks/chunk-BL1yB9zm.cjs`);const e=require(`./chunks/blok-D4WXeg3t.cjs`),t=require(`./chunks/objectSpread2-iNkE6aJh.cjs`);let n=require(`react`),r=require(`react/jsx-runtime`);var i=new WeakMap;function a(e,t){i.set(e,t)}function o(e){return i.get(e)}function s(e){i.delete(e)}function c(r,i){let[o,c]=(0,n.useState)(null),u=(0,n.useRef)(r);u.current=r;let d=(0,n.useRef)({editor:null,holder:null,destroyTimeout:null,isDestroyed:!1,depsToken:null}),f=(0,n.useMemo)(()=>({}),i==null?[]:i);(0,n.useEffect)(()=>{if(typeof window>`u`)return;let n=d.current;if(n.destroyTimeout!==null&&(clearTimeout(n.destroyTimeout),n.destroyTimeout=null),n.editor!==null&&!n.isDestroyed&&n.depsToken===f)return c(n.editor),()=>{l(n,c)};if(n.editor!==null&&!n.isDestroyed){s(n.editor);try{n.editor.destroy()}catch(e){}n.editor=null,n.holder=null,n.isDestroyed=!0,c(null)}let r=document.createElement(`div`);n.holder=r,n.isDestroyed=!1,n.depsToken=f;let i=u.current,o=new e.t(t.t(t.t({},i),{},{holder:r,onReady:()=>{var e,t;(e=(t=u.current).onReady)==null||e.call(t)},onChange:(...e)=>{var t,n;(t=(n=u.current).onChange)==null||t.call(n,...e)}}));return n.editor=o,a(o,r),o.isReady.then(()=>{n.editor===o&&!n.isDestroyed&&c(o)}).catch(()=>{if(n.editor===o&&!n.isDestroyed){s(o);try{o.destroy()}catch(e){}n.editor=null,n.holder=null,n.isDestroyed=!0,c(null)}}),()=>{l(n,c)}},[f]);let{readOnly:p}=r;(0,n.useEffect)(()=>{o!==null&&o.readOnly.set(p==null?!1:p)},[o,p]);let{autofocus:m}=r;(0,n.useEffect)(()=>{o===null||!m||o.focus()},[o,m]);let{theme:h}=r;(0,n.useEffect)(()=>{o===null||h===void 0||o.theme.set(h)},[o,h]);let{width:g}=r;return(0,n.useEffect)(()=>{o===null||g===void 0||o.width.set(g)},[o,g]),o}function l(e,t){e.destroyTimeout=setTimeout(()=>{if(e.editor!==null){s(e.editor);try{e.editor.destroy()}catch(e){}e.editor=null,e.holder=null,e.isDestroyed=!0,e.destroyTimeout=null,t(null)}},0)}var u=[`editor`],d=(0,n.forwardRef)(function(i,a){let{editor:s}=i,c=e.i(i,u),l=(0,n.useRef)(null);return(0,n.useEffect)(()=>{if(s===null||l.current===null)return;let e=o(s);if(e!==void 0)return l.current.appendChild(e),()=>{e.remove()}},[s]),(0,r.jsx)(`div`,t.t({ref:e=>{if(l.current=e,typeof a==`function`)a(e);else if(a!=null){let t=a;t.current=e}}},c))}),f=[`deps`,`className`,`onReady`,`data-testid`],p=(0,n.forwardRef)(function(t,i){let{deps:a,className:o,onReady:s,"data-testid":l}=t,u=c(e.i(t,f),a);(0,n.useImperativeHandle)(i,()=>u,[u]);let p=(0,n.useRef)(s);return p.current=s,(0,n.useEffect)(()=>{if(u!==null){var e;(e=p.current)==null||e.call(p,u)}},[u]),(0,r.jsx)(d,{editor:u,className:o,"data-testid":l})});exports.BlokContent=d,exports.BlokEditor=p,exports.useBlok=c;
|
package/dist/react.mjs
CHANGED
|
@@ -1,83 +1,91 @@
|
|
|
1
|
-
import { i as e, t } from "./chunks/blok-
|
|
1
|
+
import { i as e, t } from "./chunks/blok-BmckXjmW.mjs";
|
|
2
2
|
import { t as n } from "./chunks/objectSpread2-jlBcdYeb.mjs";
|
|
3
|
-
import { forwardRef as r, useEffect as i,
|
|
4
|
-
import { jsx as
|
|
3
|
+
import { forwardRef as r, useEffect as i, useImperativeHandle as a, useMemo as o, useRef as s, useState as c } from "react";
|
|
4
|
+
import { jsx as l } from "react/jsx-runtime";
|
|
5
5
|
//#region src/react/holder-map.ts
|
|
6
|
-
var
|
|
7
|
-
function
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
function d(e) {
|
|
11
|
-
return l.get(e);
|
|
6
|
+
var u = /* @__PURE__ */ new WeakMap();
|
|
7
|
+
function d(e, t) {
|
|
8
|
+
u.set(e, t);
|
|
12
9
|
}
|
|
13
10
|
function f(e) {
|
|
14
|
-
|
|
11
|
+
return u.get(e);
|
|
12
|
+
}
|
|
13
|
+
function p(e) {
|
|
14
|
+
u.delete(e);
|
|
15
15
|
}
|
|
16
16
|
//#endregion
|
|
17
17
|
//#region src/react/useBlok.ts
|
|
18
|
-
function
|
|
19
|
-
let [
|
|
20
|
-
|
|
21
|
-
let
|
|
18
|
+
function m(e, r) {
|
|
19
|
+
let [a, l] = c(null), u = s(e);
|
|
20
|
+
u.current = e;
|
|
21
|
+
let f = s({
|
|
22
22
|
editor: null,
|
|
23
23
|
holder: null,
|
|
24
24
|
destroyTimeout: null,
|
|
25
25
|
isDestroyed: !1,
|
|
26
26
|
depsToken: null
|
|
27
|
-
}),
|
|
27
|
+
}), m = o(() => ({}), r == null ? [] : r);
|
|
28
28
|
i(() => {
|
|
29
29
|
if (typeof window > "u") return;
|
|
30
|
-
let e =
|
|
31
|
-
if (e.destroyTimeout !== null && (clearTimeout(e.destroyTimeout), e.destroyTimeout = null), e.editor !== null && !e.isDestroyed && e.depsToken ===
|
|
32
|
-
|
|
30
|
+
let e = f.current;
|
|
31
|
+
if (e.destroyTimeout !== null && (clearTimeout(e.destroyTimeout), e.destroyTimeout = null), e.editor !== null && !e.isDestroyed && e.depsToken === m) return l(e.editor), () => {
|
|
32
|
+
h(e, l);
|
|
33
33
|
};
|
|
34
34
|
if (e.editor !== null && !e.isDestroyed) {
|
|
35
|
-
|
|
35
|
+
p(e.editor);
|
|
36
36
|
try {
|
|
37
37
|
e.editor.destroy();
|
|
38
38
|
} catch (e) {}
|
|
39
39
|
e.editor = null, e.holder = null, e.isDestroyed = !0, l(null);
|
|
40
40
|
}
|
|
41
41
|
let r = document.createElement("div");
|
|
42
|
-
e.holder = r, e.isDestroyed = !1, e.depsToken =
|
|
43
|
-
let i =
|
|
42
|
+
e.holder = r, e.isDestroyed = !1, e.depsToken = m;
|
|
43
|
+
let i = u.current, a = new t(n(n({}, i), {}, {
|
|
44
44
|
holder: r,
|
|
45
45
|
onReady: () => {
|
|
46
46
|
var e, t;
|
|
47
|
-
(e = (t =
|
|
47
|
+
(e = (t = u.current).onReady) == null || e.call(t);
|
|
48
48
|
},
|
|
49
49
|
onChange: (...e) => {
|
|
50
50
|
var t, n;
|
|
51
|
-
(t = (n =
|
|
51
|
+
(t = (n = u.current).onChange) == null || t.call(n, ...e);
|
|
52
52
|
}
|
|
53
53
|
}));
|
|
54
|
-
return e.editor = a,
|
|
54
|
+
return e.editor = a, d(a, r), a.isReady.then(() => {
|
|
55
55
|
e.editor === a && !e.isDestroyed && l(a);
|
|
56
56
|
}).catch(() => {
|
|
57
57
|
if (e.editor === a && !e.isDestroyed) {
|
|
58
|
-
|
|
58
|
+
p(a);
|
|
59
59
|
try {
|
|
60
60
|
a.destroy();
|
|
61
61
|
} catch (e) {}
|
|
62
62
|
e.editor = null, e.holder = null, e.isDestroyed = !0, l(null);
|
|
63
63
|
}
|
|
64
64
|
}), () => {
|
|
65
|
-
|
|
65
|
+
h(e, l);
|
|
66
66
|
};
|
|
67
|
-
}, [
|
|
67
|
+
}, [m]);
|
|
68
68
|
let { readOnly: g } = e;
|
|
69
69
|
i(() => {
|
|
70
|
-
|
|
71
|
-
}, [
|
|
70
|
+
a !== null && a.readOnly.set(g == null ? !1 : g);
|
|
71
|
+
}, [a, g]);
|
|
72
72
|
let { autofocus: _ } = e;
|
|
73
|
+
i(() => {
|
|
74
|
+
a === null || !_ || a.focus();
|
|
75
|
+
}, [a, _]);
|
|
76
|
+
let { theme: v } = e;
|
|
77
|
+
i(() => {
|
|
78
|
+
a === null || v === void 0 || a.theme.set(v);
|
|
79
|
+
}, [a, v]);
|
|
80
|
+
let { width: y } = e;
|
|
73
81
|
return i(() => {
|
|
74
|
-
|
|
75
|
-
}, [
|
|
82
|
+
a === null || y === void 0 || a.width.set(y);
|
|
83
|
+
}, [a, y]), a;
|
|
76
84
|
}
|
|
77
|
-
function
|
|
85
|
+
function h(e, t) {
|
|
78
86
|
e.destroyTimeout = setTimeout(() => {
|
|
79
87
|
if (e.editor !== null) {
|
|
80
|
-
|
|
88
|
+
p(e.editor);
|
|
81
89
|
try {
|
|
82
90
|
e.editor.destroy();
|
|
83
91
|
} catch (e) {}
|
|
@@ -87,21 +95,40 @@ function m(e, t) {
|
|
|
87
95
|
}
|
|
88
96
|
//#endregion
|
|
89
97
|
//#region src/react/BlokContent.tsx
|
|
90
|
-
var
|
|
91
|
-
let { editor: a } = t,
|
|
98
|
+
var g = ["editor"], _ = r(function(t, r) {
|
|
99
|
+
let { editor: a } = t, o = e(t, g), c = s(null);
|
|
92
100
|
return i(() => {
|
|
93
|
-
if (a === null ||
|
|
94
|
-
let e =
|
|
95
|
-
if (e !== void 0) return
|
|
101
|
+
if (a === null || c.current === null) return;
|
|
102
|
+
let e = f(a);
|
|
103
|
+
if (e !== void 0) return c.current.appendChild(e), () => {
|
|
96
104
|
e.remove();
|
|
97
105
|
};
|
|
98
|
-
}, [a]), /* @__PURE__ */
|
|
99
|
-
if (
|
|
106
|
+
}, [a]), /* @__PURE__ */ l("div", n({ ref: (e) => {
|
|
107
|
+
if (c.current = e, typeof r == "function") r(e);
|
|
100
108
|
else if (r != null) {
|
|
101
109
|
let t = r;
|
|
102
110
|
t.current = e;
|
|
103
111
|
}
|
|
104
|
-
} },
|
|
112
|
+
} }, o));
|
|
113
|
+
}), v = [
|
|
114
|
+
"deps",
|
|
115
|
+
"className",
|
|
116
|
+
"onReady",
|
|
117
|
+
"data-testid"
|
|
118
|
+
], y = r(function(t, n) {
|
|
119
|
+
let { deps: r, className: o, onReady: c, "data-testid": u } = t, d = m(e(t, v), r);
|
|
120
|
+
a(n, () => d, [d]);
|
|
121
|
+
let f = s(c);
|
|
122
|
+
return f.current = c, i(() => {
|
|
123
|
+
if (d !== null) {
|
|
124
|
+
var e;
|
|
125
|
+
(e = f.current) == null || e.call(f, d);
|
|
126
|
+
}
|
|
127
|
+
}, [d]), /* @__PURE__ */ l(_, {
|
|
128
|
+
editor: d,
|
|
129
|
+
className: o,
|
|
130
|
+
"data-testid": u
|
|
131
|
+
});
|
|
105
132
|
});
|
|
106
133
|
//#endregion
|
|
107
|
-
export {
|
|
134
|
+
export { _ as BlokContent, y as BlokEditor, m as useBlok };
|
package/dist/tools.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./chunks/constants-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./chunks/constants-BbCnmzAr.cjs`),t=require(`./chunks/tools-tG5_UaWz.cjs`);exports.Audio=t.g,exports.Bold=t.l,exports.Bookmark=t.u,exports.Callout=t.w,exports.Code=t.y,exports.Column=t.p,exports.ColumnList=t.m,exports.Columns=t.f,exports.Convert=e.m,exports.Database=t.C,exports.DatabaseRow=t.S,exports.Divider=t.x,exports.Embed=t.d,exports.File=t._,exports.Header=t.O,exports.Image=t.v,exports.InlineCode=t.r,exports.Italic=t.c,exports.Link=t.s,exports.List=t.D,exports.Marker=t.o,exports.Paragraph=t.k,exports.Quote=t.b,exports.Strikethrough=t.i,exports.Table=t.E,exports.Toggle=t.T,exports.Underline=t.a,exports.Video=t.h,exports.defaultBlockTools=t.t,exports.defaultInlineTools=t.n;
|
package/dist/tools.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { m as e } from "./chunks/constants-
|
|
2
|
-
import { C as t, D as n, E as r, O as i, S as a, T as o, _ as s, a as c, b as l, c as u, d, f, g as p, h as m, i as h, k as g, l as _, m as v, n as y, o as b, p as x, r as S, s as C, t as w, u as T, v as E, w as D, x as O, y as k } from "./chunks/tools-
|
|
1
|
+
import { m as e } from "./chunks/constants-tXKHkDAG.mjs";
|
|
2
|
+
import { C as t, D as n, E as r, O as i, S as a, T as o, _ as s, a as c, b as l, c as u, d, f, g as p, h as m, i as h, k as g, l as _, m as v, n as y, o as b, p as x, r as S, s as C, t as w, u as T, v as E, w as D, x as O, y as k } from "./chunks/tools-oXMAa9zD.mjs";
|
|
3
3
|
export { p as Audio, _ as Bold, T as Bookmark, D as Callout, k as Code, x as Column, v as ColumnList, f as Columns, e as Convert, t as Database, a as DatabaseRow, O as Divider, d as Embed, s as File, i as Header, E as Image, S as InlineCode, u as Italic, C as Link, n as List, b as Marker, g as Paragraph, l as Quote, h as Strikethrough, r as Table, o as Toggle, c as Underline, m as Video, w as defaultBlockTools, y as defaultInlineTools };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jackuait/blok",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"description": "Blok — headless, highly extensible rich text editor built for developers who need to implement a block-based editing experience (similar to Notion) without building it from scratch",
|
|
5
5
|
"module": "dist/blok.mjs",
|
|
6
6
|
"main": "./dist/blok.cjs",
|
|
@@ -7,6 +7,7 @@ import { SAFE_STRUCTURAL_TAGS } from './constants';
|
|
|
7
7
|
import { preprocessGoogleDocsHtml } from './google-docs-preprocessor';
|
|
8
8
|
import { preprocessNotionHtml } from './notion-preprocessor';
|
|
9
9
|
import { NOTION_BLOCKS_V3_MIME, parseNotionBlocksV3 } from './notion-blocks-v3';
|
|
10
|
+
import { NEXT_SPACE_MIMES, parseNextSpaceBlocks } from './next-space-blocks';
|
|
10
11
|
import type { PasteHandler } from './handlers/base';
|
|
11
12
|
import { BlokDataHandler } from './handlers/blok-data-handler';
|
|
12
13
|
import { FilesHandler } from './handlers/files-handler';
|
|
@@ -114,12 +115,15 @@ export class Paste extends Module {
|
|
|
114
115
|
const plainData = dataTransfer.getData('text/plain');
|
|
115
116
|
const rawHtmlData = dataTransfer.getData('text/html');
|
|
116
117
|
|
|
117
|
-
// Native Blok clipboard data always wins. When absent, fall back to
|
|
118
|
-
//
|
|
119
|
-
// block state (checked, language, nesting, colour…) that the
|
|
120
|
-
// cannot. We translate
|
|
121
|
-
// the existing BlokDataHandler two-pass hierarchy builder.
|
|
122
|
-
const blokData =
|
|
118
|
+
// Native Blok clipboard data always wins. When absent, fall back to the
|
|
119
|
+
// lossless proprietary flavours of other editors (web→web paste): they
|
|
120
|
+
// carry full block state (checked, language, nesting, colour…) that the
|
|
121
|
+
// HTML flavour cannot. We translate them into the Blok clipboard shape so
|
|
122
|
+
// they flow through the existing BlokDataHandler two-pass hierarchy builder.
|
|
123
|
+
const blokData =
|
|
124
|
+
dataTransfer.getData(this.MIME_TYPE) ||
|
|
125
|
+
this.readNotionBlocksV3(dataTransfer) ||
|
|
126
|
+
this.readNextSpaceBlocks(dataTransfer);
|
|
123
127
|
|
|
124
128
|
// Route to handlers based on data type
|
|
125
129
|
const handled = await this.routeToHandlers(dataTransfer, plainData, rawHtmlData, blokData, pasteTarget);
|
|
@@ -153,6 +157,29 @@ export class Paste extends Module {
|
|
|
153
157
|
return JSON.stringify(parsed);
|
|
154
158
|
}
|
|
155
159
|
|
|
160
|
+
/**
|
|
161
|
+
* Read buildin.ai's `text/next-space-blocks` / `text/next-space-content`
|
|
162
|
+
* clipboard flavours and translate them into the Blok clipboard JSON shape,
|
|
163
|
+
* or return '' when absent / unparseable (so the caller falls back to HTML).
|
|
164
|
+
*/
|
|
165
|
+
private readNextSpaceBlocks(dataTransfer: DataTransfer): string {
|
|
166
|
+
for (const mime of NEXT_SPACE_MIMES) {
|
|
167
|
+
const raw = dataTransfer.getData(mime);
|
|
168
|
+
|
|
169
|
+
if (!raw) {
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const parsed = parseNextSpaceBlocks(raw);
|
|
174
|
+
|
|
175
|
+
if (parsed !== null && parsed.length > 0) {
|
|
176
|
+
return JSON.stringify(parsed);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return '';
|
|
181
|
+
}
|
|
182
|
+
|
|
156
183
|
/**
|
|
157
184
|
* Route paste data to handlers in priority order.
|
|
158
185
|
*/
|