@jackuait/blok 0.23.1 → 0.23.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 (49) hide show
  1. package/README.md +3 -1
  2. package/dist/blok.cjs +1 -1
  3. package/dist/blok.iife.js +73 -73
  4. package/dist/blok.mjs +3 -3
  5. package/dist/blok.umd.js +53 -53
  6. package/dist/chunks/{blok-BPeM6wKv.mjs → blok-1H9roBGf.mjs} +2271 -2249
  7. package/dist/chunks/{blok-Ci1zCOUg.cjs → blok-J3Lfa_bK.cjs} +13 -13
  8. package/dist/chunks/{constants-DR3sya6U.mjs → constants-BJ79cqMa.mjs} +288 -284
  9. package/dist/chunks/constants-BZUc1kAY.cjs +606 -0
  10. package/dist/chunks/{tools-B72rczVw.mjs → tools-ByOjWADT.mjs} +420 -418
  11. package/dist/chunks/{tools-DlOZpcVU.cjs → tools-OHDv2C7w.cjs} +2 -2
  12. package/dist/full.cjs +1 -1
  13. package/dist/full.mjs +3 -3
  14. package/dist/react.cjs +1 -1
  15. package/dist/react.mjs +54 -33
  16. package/dist/tools.cjs +1 -1
  17. package/dist/tools.mjs +2 -2
  18. package/package.json +1 -1
  19. package/src/blok.ts +12 -0
  20. package/src/components/block/tool-renderer.ts +2 -2
  21. package/src/components/blocks.ts +32 -10
  22. package/src/components/constants/test-ids.ts +17 -0
  23. package/src/components/constants.ts +5 -0
  24. package/src/components/events/BlockRendered.ts +9 -0
  25. package/src/components/events/BlocksRendered.ts +13 -0
  26. package/src/components/events/index.ts +8 -0
  27. package/src/components/inline-tools/inline-tool-link.ts +23 -9
  28. package/src/components/modules/api/events.ts +10 -10
  29. package/src/components/modules/api/index.ts +3 -0
  30. package/src/components/modules/api/tools.ts +3 -0
  31. package/src/components/modules/blockManager/blockManager.ts +1 -1
  32. package/src/components/modules/paste/index.ts +10 -1
  33. package/src/components/modules/renderer.ts +146 -131
  34. package/src/components/modules/toolbar/plus-button.ts +2 -1
  35. package/src/components/modules/toolbar/settings-toggler.ts +2 -2
  36. package/src/components/modules/tools.ts +18 -0
  37. package/src/components/tools/factory.ts +28 -1
  38. package/src/react/BlokEditor.tsx +17 -5
  39. package/src/react/config-keys.ts +2 -0
  40. package/src/react/deep-equal.ts +48 -0
  41. package/src/react/types.ts +2 -0
  42. package/src/react/useBlok.ts +37 -0
  43. package/types/api/events.d.ts +35 -5
  44. package/types/api/tools.d.ts +16 -1
  45. package/types/configs/blok-config.d.ts +37 -0
  46. package/types/events/editor-events.ts +41 -0
  47. package/types/index.d.ts +5 -1
  48. package/types/react.d.ts +13 -2
  49. package/dist/chunks/constants-Bkncy0y5.cjs +0 -606
@@ -59,6 +59,17 @@ export interface BlokConfig {
59
59
  */
60
60
  sanitizer?: SanitizerConfig;
61
61
 
62
+ /**
63
+ * Transform or clean the raw clipboard HTML before Blok processes it.
64
+ * Runs on the unmodified `text/html` payload, before any Blok preprocessing
65
+ * or sanitization, so you no longer need a capture-phase paste interceptor.
66
+ *
67
+ * @param html - the raw `text/html` clipboard string
68
+ * @returns the transformed HTML to feed into the rest of the paste pipeline,
69
+ * or `null` to skip the HTML paste path (paste falls through to plain text).
70
+ */
71
+ onBeforePaste?: (html: string) => string | null;
72
+
62
73
  /**
63
74
  * If true, toolbar won't be shown
64
75
  */
@@ -124,6 +135,32 @@ export interface BlokConfig {
124
135
  */
125
136
  i18n?: I18nConfig;
126
137
 
138
+ /**
139
+ * Configures how the Link inline tool builds anchor elements, so consumers can
140
+ * control the created `<a>` instead of post-processing the rendered DOM.
141
+ */
142
+ link?: {
143
+ /**
144
+ * `target` attribute applied to created anchors.
145
+ * @default '_blank'
146
+ */
147
+ target?: string;
148
+
149
+ /**
150
+ * `rel` attribute applied to created anchors.
151
+ * @default 'nofollow'
152
+ */
153
+ rel?: string;
154
+
155
+ /**
156
+ * Transforms the href just before it is assigned to the anchor.
157
+ * Runs after URL validation/normalization, on the final value.
158
+ * @param href - the validated, protocol-normalized href
159
+ * @returns the href to set on the anchor
160
+ */
161
+ transformHref?: (href: string) => string;
162
+ };
163
+
127
164
  /**
128
165
  * Notion-style link-paste behavior. Pasting a URL always opens a small menu
129
166
  * (Plain link / Bookmark / Embed) instead of auto-inserting a block.
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Public payloads and name map for editor lifecycle events observable via
3
+ * `blok.events.on(...)`.
4
+ *
5
+ * These complement the mutation events delivered through the `onChange`
6
+ * config callback ({@link ./block}). Use together with the exported event-name
7
+ * constants `BlockRendered` (`'block:rendered'`) and `BlocksRendered`
8
+ * (`'blocks:rendered'`).
9
+ */
10
+
11
+ /**
12
+ * Payload for the `block:rendered` event.
13
+ */
14
+ export interface BlockRenderedPayload {
15
+ /**
16
+ * Id of the block that has just been rendered into the DOM.
17
+ * Use `blok.blocks.getById(blockId)` to access it.
18
+ */
19
+ blockId: string;
20
+ }
21
+
22
+ /**
23
+ * Payload for the `blocks:rendered` event.
24
+ */
25
+ export interface BlocksRenderedPayload {
26
+ /**
27
+ * Number of top-level blocks rendered in the completed batch.
28
+ */
29
+ count: number;
30
+ }
31
+
32
+ /**
33
+ * Map of editor lifecycle event name -> payload.
34
+ *
35
+ * Subscribers get fully typed payloads for these well-known events while the
36
+ * `Events` API still accepts arbitrary string event names for custom events.
37
+ */
38
+ export interface BlokEditorEventMap {
39
+ 'block:rendered': BlockRenderedPayload;
40
+ 'blocks:rendered': BlocksRenderedPayload;
41
+ }
package/types/index.d.ts CHANGED
@@ -42,6 +42,7 @@ import { BlockAddedMutationType, BlockAddedEvent } from './events/block/BlockAdd
42
42
  import { BlockChangedMutationType, BlockChangedEvent } from './events/block/BlockChanged';
43
43
  import { BlockMovedMutationType, BlockMovedEvent } from './events/block/BlockMoved';
44
44
  import { BlockRemovedMutationType, BlockRemovedEvent } from './events/block/BlockRemoved';
45
+ import { BlokEditorEventMap, BlockRenderedPayload, BlocksRenderedPayload } from './events/editor-events';
45
46
 
46
47
  /**
47
48
  * Interfaces used for development
@@ -144,6 +145,9 @@ export {
144
145
  BlockMovedEvent,
145
146
  BlockChangedMutationType,
146
147
  BlockChangedEvent,
148
+ BlokEditorEventMap,
149
+ BlockRenderedPayload,
150
+ BlocksRenderedPayload,
147
151
  }
148
152
 
149
153
  /**
@@ -170,7 +174,7 @@ export interface API {
170
174
  ui: Ui;
171
175
  theme: Theme;
172
176
  /** Read-only view of selected editor configuration. */
173
- config: Readonly<Pick<BlokConfig, 'linkPaste'>>;
177
+ config: Readonly<Pick<BlokConfig, 'linkPaste' | 'link'>>;
174
178
  rectangleSelection: {
175
179
  cancelActiveSelection: () => void;
176
180
  isRectActivated: () => boolean;
package/types/react.d.ts CHANGED
@@ -12,6 +12,8 @@ import type React from 'react';
12
12
  * - `theme` — calls `editor.theme.set(value)`
13
13
  * - `width` — calls `editor.width.set(value)`
14
14
  * - `placeholder` — calls `editor.placeholder.set(value)`
15
+ * - `data` — re-renders via `editor.render(value)` when the content changes
16
+ * (deep-equal–deduped and serialized; seeds the initial content at creation)
15
17
  *
16
18
  * All other config is consumed once at editor creation.
17
19
  */
@@ -34,7 +36,7 @@ export interface BlokContentProps extends React.HTMLAttributes<HTMLDivElement> {
34
36
  * React hook that creates and manages a Blok editor instance.
35
37
  *
36
38
  * @param config - Editor configuration (all BlokConfig props except `holder`)
37
- * @param deps - Optional dependency array. When any dep changes, the editor is destroyed and recreated.
39
+ * @param deps - Optional dependency array. When any dep changes, the editor is destroyed and recreated. Keep each value referentially stable (primitives or useMemo-stable objects) so the editor isn't recreated every render.
38
40
  * @returns The Blok editor instance, or null during SSR / before initialization.
39
41
  *
40
42
  * @example
@@ -72,7 +74,11 @@ export declare const BlokContent: React.ForwardRefExoticComponent<BlokContentPro
72
74
  export interface BlokEditorProps
73
75
  extends Omit<UseBlokConfig, 'onReady'>,
74
76
  Omit<React.HTMLAttributes<HTMLDivElement>, 'style' | 'onChange'> {
75
- /** When any value changes, the editor is destroyed and recreated. */
77
+ /**
78
+ * When any value changes, the editor is destroyed and recreated. Keep each
79
+ * value referentially stable (primitives or useMemo-stable objects) — a dep
80
+ * whose identity changes every render recreates the editor each time.
81
+ */
76
82
  deps?: React.DependencyList;
77
83
  /** Test id forwarded to the editor container element (via data-testid). */
78
84
  'data-testid'?: string;
@@ -84,6 +90,11 @@ export interface BlokEditorProps
84
90
  * The recommended all-in-one React component. Wires useBlok + BlokContent and
85
91
  * forwards a ref to the live Blok instance (null before the editor is ready).
86
92
  *
93
+ * Don't wrap this component in `styled()` or any HOC that reserves the `theme`
94
+ * prop — styled-components claims `theme` for its own `ThemeProvider`, so it
95
+ * never reaches the editor and theme sync silently breaks. Render it directly
96
+ * and style the container via `className`.
97
+ *
87
98
  * @example
88
99
  * ```tsx
89
100
  * const ref = useRef<Blok | null>(null);