@rtif-sdk/web 1.0.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/LICENSE +21 -0
- package/README.md +67 -0
- package/dist/block-drag-handler.d.ts +189 -0
- package/dist/block-drag-handler.d.ts.map +1 -0
- package/dist/block-drag-handler.js +745 -0
- package/dist/block-drag-handler.js.map +1 -0
- package/dist/block-renderer.d.ts +402 -0
- package/dist/block-renderer.d.ts.map +1 -0
- package/dist/block-renderer.js +424 -0
- package/dist/block-renderer.js.map +1 -0
- package/dist/clipboard.d.ts +178 -0
- package/dist/clipboard.d.ts.map +1 -0
- package/dist/clipboard.js +432 -0
- package/dist/clipboard.js.map +1 -0
- package/dist/command-bus.d.ts +113 -0
- package/dist/command-bus.d.ts.map +1 -0
- package/dist/command-bus.js +70 -0
- package/dist/command-bus.js.map +1 -0
- package/dist/composition.d.ts +220 -0
- package/dist/composition.d.ts.map +1 -0
- package/dist/composition.js +271 -0
- package/dist/composition.js.map +1 -0
- package/dist/content-extraction.d.ts +69 -0
- package/dist/content-extraction.d.ts.map +1 -0
- package/dist/content-extraction.js +228 -0
- package/dist/content-extraction.js.map +1 -0
- package/dist/content-handler-file.d.ts +40 -0
- package/dist/content-handler-file.d.ts.map +1 -0
- package/dist/content-handler-file.js +91 -0
- package/dist/content-handler-file.js.map +1 -0
- package/dist/content-handler-image.d.ts +82 -0
- package/dist/content-handler-image.d.ts.map +1 -0
- package/dist/content-handler-image.js +120 -0
- package/dist/content-handler-image.js.map +1 -0
- package/dist/content-handler-url.d.ts +129 -0
- package/dist/content-handler-url.d.ts.map +1 -0
- package/dist/content-handler-url.js +244 -0
- package/dist/content-handler-url.js.map +1 -0
- package/dist/content-handlers.d.ts +67 -0
- package/dist/content-handlers.d.ts.map +1 -0
- package/dist/content-handlers.js +263 -0
- package/dist/content-handlers.js.map +1 -0
- package/dist/content-pipeline.d.ts +383 -0
- package/dist/content-pipeline.d.ts.map +1 -0
- package/dist/content-pipeline.js +232 -0
- package/dist/content-pipeline.js.map +1 -0
- package/dist/cursor-nav.d.ts +149 -0
- package/dist/cursor-nav.d.ts.map +1 -0
- package/dist/cursor-nav.js +230 -0
- package/dist/cursor-nav.js.map +1 -0
- package/dist/cursor-rect.d.ts +65 -0
- package/dist/cursor-rect.d.ts.map +1 -0
- package/dist/cursor-rect.js +98 -0
- package/dist/cursor-rect.js.map +1 -0
- package/dist/drop-indicator.d.ts +108 -0
- package/dist/drop-indicator.d.ts.map +1 -0
- package/dist/drop-indicator.js +236 -0
- package/dist/drop-indicator.js.map +1 -0
- package/dist/editor.d.ts +41 -0
- package/dist/editor.d.ts.map +1 -0
- package/dist/editor.js +710 -0
- package/dist/editor.js.map +1 -0
- package/dist/floating-toolbar.d.ts +93 -0
- package/dist/floating-toolbar.d.ts.map +1 -0
- package/dist/floating-toolbar.js +159 -0
- package/dist/floating-toolbar.js.map +1 -0
- package/dist/index.d.ts +62 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +119 -0
- package/dist/index.js.map +1 -0
- package/dist/input-bridge.d.ts +273 -0
- package/dist/input-bridge.d.ts.map +1 -0
- package/dist/input-bridge.js +884 -0
- package/dist/input-bridge.js.map +1 -0
- package/dist/link-popover.d.ts +38 -0
- package/dist/link-popover.d.ts.map +1 -0
- package/dist/link-popover.js +278 -0
- package/dist/link-popover.js.map +1 -0
- package/dist/mark-renderer.d.ts +275 -0
- package/dist/mark-renderer.d.ts.map +1 -0
- package/dist/mark-renderer.js +210 -0
- package/dist/mark-renderer.js.map +1 -0
- package/dist/perf.d.ts +145 -0
- package/dist/perf.d.ts.map +1 -0
- package/dist/perf.js +260 -0
- package/dist/perf.js.map +1 -0
- package/dist/plugin-kit.d.ts +265 -0
- package/dist/plugin-kit.d.ts.map +1 -0
- package/dist/plugin-kit.js +234 -0
- package/dist/plugin-kit.js.map +1 -0
- package/dist/plugins/alignment-plugin.d.ts +68 -0
- package/dist/plugins/alignment-plugin.d.ts.map +1 -0
- package/dist/plugins/alignment-plugin.js +98 -0
- package/dist/plugins/alignment-plugin.js.map +1 -0
- package/dist/plugins/block-utils.d.ts +113 -0
- package/dist/plugins/block-utils.d.ts.map +1 -0
- package/dist/plugins/block-utils.js +191 -0
- package/dist/plugins/block-utils.js.map +1 -0
- package/dist/plugins/blockquote-plugin.d.ts +39 -0
- package/dist/plugins/blockquote-plugin.d.ts.map +1 -0
- package/dist/plugins/blockquote-plugin.js +88 -0
- package/dist/plugins/blockquote-plugin.js.map +1 -0
- package/dist/plugins/bold-plugin.d.ts +37 -0
- package/dist/plugins/bold-plugin.d.ts.map +1 -0
- package/dist/plugins/bold-plugin.js +48 -0
- package/dist/plugins/bold-plugin.js.map +1 -0
- package/dist/plugins/callout-plugin.d.ts +100 -0
- package/dist/plugins/callout-plugin.d.ts.map +1 -0
- package/dist/plugins/callout-plugin.js +200 -0
- package/dist/plugins/callout-plugin.js.map +1 -0
- package/dist/plugins/code-block-plugin.d.ts +62 -0
- package/dist/plugins/code-block-plugin.d.ts.map +1 -0
- package/dist/plugins/code-block-plugin.js +176 -0
- package/dist/plugins/code-block-plugin.js.map +1 -0
- package/dist/plugins/code-plugin.d.ts +37 -0
- package/dist/plugins/code-plugin.d.ts.map +1 -0
- package/dist/plugins/code-plugin.js +48 -0
- package/dist/plugins/code-plugin.js.map +1 -0
- package/dist/plugins/embed-plugin.d.ts +90 -0
- package/dist/plugins/embed-plugin.d.ts.map +1 -0
- package/dist/plugins/embed-plugin.js +147 -0
- package/dist/plugins/embed-plugin.js.map +1 -0
- package/dist/plugins/font-family-plugin.d.ts +58 -0
- package/dist/plugins/font-family-plugin.d.ts.map +1 -0
- package/dist/plugins/font-family-plugin.js +57 -0
- package/dist/plugins/font-family-plugin.js.map +1 -0
- package/dist/plugins/font-size-plugin.d.ts +57 -0
- package/dist/plugins/font-size-plugin.d.ts.map +1 -0
- package/dist/plugins/font-size-plugin.js +56 -0
- package/dist/plugins/font-size-plugin.js.map +1 -0
- package/dist/plugins/heading-plugin.d.ts +52 -0
- package/dist/plugins/heading-plugin.d.ts.map +1 -0
- package/dist/plugins/heading-plugin.js +114 -0
- package/dist/plugins/heading-plugin.js.map +1 -0
- package/dist/plugins/hr-plugin.d.ts +33 -0
- package/dist/plugins/hr-plugin.d.ts.map +1 -0
- package/dist/plugins/hr-plugin.js +75 -0
- package/dist/plugins/hr-plugin.js.map +1 -0
- package/dist/plugins/image-plugin.d.ts +115 -0
- package/dist/plugins/image-plugin.d.ts.map +1 -0
- package/dist/plugins/image-plugin.js +199 -0
- package/dist/plugins/image-plugin.js.map +1 -0
- package/dist/plugins/indent-plugin.d.ts +62 -0
- package/dist/plugins/indent-plugin.d.ts.map +1 -0
- package/dist/plugins/indent-plugin.js +128 -0
- package/dist/plugins/indent-plugin.js.map +1 -0
- package/dist/plugins/index.d.ts +45 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +42 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/plugins/italic-plugin.d.ts +37 -0
- package/dist/plugins/italic-plugin.d.ts.map +1 -0
- package/dist/plugins/italic-plugin.js +48 -0
- package/dist/plugins/italic-plugin.js.map +1 -0
- package/dist/plugins/link-plugin.d.ts +129 -0
- package/dist/plugins/link-plugin.d.ts.map +1 -0
- package/dist/plugins/link-plugin.js +212 -0
- package/dist/plugins/link-plugin.js.map +1 -0
- package/dist/plugins/list-plugin.d.ts +53 -0
- package/dist/plugins/list-plugin.d.ts.map +1 -0
- package/dist/plugins/list-plugin.js +309 -0
- package/dist/plugins/list-plugin.js.map +1 -0
- package/dist/plugins/mark-utils.d.ts +173 -0
- package/dist/plugins/mark-utils.d.ts.map +1 -0
- package/dist/plugins/mark-utils.js +425 -0
- package/dist/plugins/mark-utils.js.map +1 -0
- package/dist/plugins/mention-plugin.d.ts +191 -0
- package/dist/plugins/mention-plugin.d.ts.map +1 -0
- package/dist/plugins/mention-plugin.js +295 -0
- package/dist/plugins/mention-plugin.js.map +1 -0
- package/dist/plugins/strikethrough-plugin.d.ts +37 -0
- package/dist/plugins/strikethrough-plugin.d.ts.map +1 -0
- package/dist/plugins/strikethrough-plugin.js +48 -0
- package/dist/plugins/strikethrough-plugin.js.map +1 -0
- package/dist/plugins/text-color-plugin.d.ts +57 -0
- package/dist/plugins/text-color-plugin.d.ts.map +1 -0
- package/dist/plugins/text-color-plugin.js +56 -0
- package/dist/plugins/text-color-plugin.js.map +1 -0
- package/dist/plugins/underline-plugin.d.ts +37 -0
- package/dist/plugins/underline-plugin.d.ts.map +1 -0
- package/dist/plugins/underline-plugin.js +48 -0
- package/dist/plugins/underline-plugin.js.map +1 -0
- package/dist/presets.d.ts +95 -0
- package/dist/presets.d.ts.map +1 -0
- package/dist/presets.js +159 -0
- package/dist/presets.js.map +1 -0
- package/dist/renderer.d.ts +125 -0
- package/dist/renderer.d.ts.map +1 -0
- package/dist/renderer.js +415 -0
- package/dist/renderer.js.map +1 -0
- package/dist/scroll-to-cursor.d.ts +25 -0
- package/dist/scroll-to-cursor.d.ts.map +1 -0
- package/dist/scroll-to-cursor.js +59 -0
- package/dist/scroll-to-cursor.js.map +1 -0
- package/dist/selection-sync.d.ts +159 -0
- package/dist/selection-sync.d.ts.map +1 -0
- package/dist/selection-sync.js +527 -0
- package/dist/selection-sync.js.map +1 -0
- package/dist/shortcut-handler.d.ts +98 -0
- package/dist/shortcut-handler.d.ts.map +1 -0
- package/dist/shortcut-handler.js +155 -0
- package/dist/shortcut-handler.js.map +1 -0
- package/dist/toolbar.d.ts +103 -0
- package/dist/toolbar.d.ts.map +1 -0
- package/dist/toolbar.js +134 -0
- package/dist/toolbar.js.map +1 -0
- package/dist/trigger-manager.d.ts +205 -0
- package/dist/trigger-manager.d.ts.map +1 -0
- package/dist/trigger-manager.js +466 -0
- package/dist/trigger-manager.js.map +1 -0
- package/dist/types.d.ts +216 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +30 -0
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Callout block type plugin — registers the `callout` block type with 5 variants
|
|
3
|
+
* (info, warning, error, success, note), three commands (`insertCallout`,
|
|
4
|
+
* `setCalloutVariant`, `toggleCallout`), and an input rule for `> !` at block start.
|
|
5
|
+
*
|
|
6
|
+
* Callouts are blocks with a colored border, icon, and editable content area.
|
|
7
|
+
* The variant determines the visual treatment (color, icon) applied by the
|
|
8
|
+
* block renderer in the web layer.
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
import { getBlockStartOffset, getBlockAtCursor, isBlockType, setBlockType } from './block-utils.js';
|
|
13
|
+
/**
|
|
14
|
+
* Command name constants for the callout plugin.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* engine.exec(CalloutCommands.INSERT, { variant: 'warning' });
|
|
19
|
+
* engine.exec(CalloutCommands.SET_VARIANT, { variant: 'error' });
|
|
20
|
+
* engine.exec(CalloutCommands.TOGGLE);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export const CalloutCommands = {
|
|
24
|
+
INSERT: 'insertCallout',
|
|
25
|
+
SET_VARIANT: 'setCalloutVariant',
|
|
26
|
+
TOGGLE: 'toggleCallout',
|
|
27
|
+
};
|
|
28
|
+
/** All valid callout variant values, used for validation. */
|
|
29
|
+
const VALID_VARIANTS = new Set([
|
|
30
|
+
'info',
|
|
31
|
+
'warning',
|
|
32
|
+
'error',
|
|
33
|
+
'success',
|
|
34
|
+
'note',
|
|
35
|
+
]);
|
|
36
|
+
/**
|
|
37
|
+
* Check whether a variant string is a valid {@link CalloutVariant}.
|
|
38
|
+
*
|
|
39
|
+
* @param value - The value to check
|
|
40
|
+
* @returns `true` if the value is one of the 5 valid variant strings
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* isValidVariant('info'); // true
|
|
45
|
+
* isValidVariant('danger'); // false
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
function isValidVariant(value) {
|
|
49
|
+
return typeof value === 'string' && VALID_VARIANTS.has(value);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Create the callout block type plugin.
|
|
53
|
+
*
|
|
54
|
+
* Registers:
|
|
55
|
+
* - Block type: `callout` (attrs must have `variant` as one of 5 valid values)
|
|
56
|
+
* - Command: `insertCallout` — convert the block at cursor to a callout with
|
|
57
|
+
* an optional variant payload (defaults to `'info'`)
|
|
58
|
+
* - Command: `setCalloutVariant` — change the variant attr on the current
|
|
59
|
+
* callout block (only executable when cursor is in a callout)
|
|
60
|
+
* - Command: `toggleCallout` — toggle between callout (info variant) and
|
|
61
|
+
* plain text
|
|
62
|
+
* - Input rule: `> !` at the start of a block converts to a callout with
|
|
63
|
+
* `'info'` variant
|
|
64
|
+
*
|
|
65
|
+
* @returns A plugin instance ready for `engine.use()`
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* const engine = createEngine(initialDoc);
|
|
70
|
+
* engine.use(calloutPlugin());
|
|
71
|
+
*
|
|
72
|
+
* // Convert block at cursor to a warning callout
|
|
73
|
+
* engine.exec(CalloutCommands.INSERT, { variant: 'warning' });
|
|
74
|
+
*
|
|
75
|
+
* // Change variant of the current callout
|
|
76
|
+
* engine.exec(CalloutCommands.SET_VARIANT, { variant: 'error' });
|
|
77
|
+
*
|
|
78
|
+
* // Toggle callout on/off (uses 'info' variant when toggling on)
|
|
79
|
+
* engine.exec(CalloutCommands.TOGGLE);
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export function calloutPlugin() {
|
|
83
|
+
return {
|
|
84
|
+
id: 'block-callout',
|
|
85
|
+
init(ctx) {
|
|
86
|
+
// ---------------------------------------------------------------
|
|
87
|
+
// Block type registration
|
|
88
|
+
// ---------------------------------------------------------------
|
|
89
|
+
ctx.registerBlockType('callout', {
|
|
90
|
+
defaultAttrs: { variant: 'info' },
|
|
91
|
+
validate: (attrs) => {
|
|
92
|
+
return isValidVariant(attrs.variant);
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
// ---------------------------------------------------------------
|
|
96
|
+
// insertCallout command
|
|
97
|
+
// ---------------------------------------------------------------
|
|
98
|
+
ctx.registerCommand(CalloutCommands.INSERT, {
|
|
99
|
+
/**
|
|
100
|
+
* Convert the block at the cursor to a callout with the given variant.
|
|
101
|
+
* If no variant is provided in the payload, defaults to `'info'`.
|
|
102
|
+
*/
|
|
103
|
+
execute(engine, payload) {
|
|
104
|
+
const p = payload;
|
|
105
|
+
const variant = p?.variant ?? 'info';
|
|
106
|
+
if (!isValidVariant(variant))
|
|
107
|
+
return;
|
|
108
|
+
const block = getBlockAtCursor(engine);
|
|
109
|
+
setBlockType(engine, block.id, 'callout', { variant });
|
|
110
|
+
},
|
|
111
|
+
canExecute(_engine) {
|
|
112
|
+
return true;
|
|
113
|
+
},
|
|
114
|
+
isActive(engine) {
|
|
115
|
+
return isBlockType(engine, 'callout');
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
// ---------------------------------------------------------------
|
|
119
|
+
// setCalloutVariant command
|
|
120
|
+
// ---------------------------------------------------------------
|
|
121
|
+
ctx.registerCommand(CalloutCommands.SET_VARIANT, {
|
|
122
|
+
/**
|
|
123
|
+
* Change the variant attr on the current callout block.
|
|
124
|
+
* Requires a payload with `{ variant: CalloutVariant }`.
|
|
125
|
+
* Only executable when the cursor is inside a callout block.
|
|
126
|
+
*/
|
|
127
|
+
execute(engine, payload) {
|
|
128
|
+
const p = payload;
|
|
129
|
+
if (!p || !isValidVariant(p.variant))
|
|
130
|
+
return;
|
|
131
|
+
const block = getBlockAtCursor(engine);
|
|
132
|
+
if (block.type !== 'callout')
|
|
133
|
+
return;
|
|
134
|
+
engine.dispatch({
|
|
135
|
+
type: 'set_block_attrs',
|
|
136
|
+
blockId: block.id,
|
|
137
|
+
attrs: { variant: p.variant },
|
|
138
|
+
});
|
|
139
|
+
},
|
|
140
|
+
canExecute(engine) {
|
|
141
|
+
return isBlockType(engine, 'callout');
|
|
142
|
+
},
|
|
143
|
+
isActive(engine, payload) {
|
|
144
|
+
const p = payload;
|
|
145
|
+
if (!p || !isValidVariant(p.variant))
|
|
146
|
+
return false;
|
|
147
|
+
return isBlockType(engine, 'callout', { variant: p.variant });
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
// ---------------------------------------------------------------
|
|
151
|
+
// toggleCallout command
|
|
152
|
+
// ---------------------------------------------------------------
|
|
153
|
+
ctx.registerCommand(CalloutCommands.TOGGLE, {
|
|
154
|
+
/**
|
|
155
|
+
* Toggle between callout (info variant) and plain text.
|
|
156
|
+
* When the block is already a callout, reverts to text and clears
|
|
157
|
+
* the variant attr. When the block is not a callout, converts to
|
|
158
|
+
* a callout with the `'info'` variant.
|
|
159
|
+
*/
|
|
160
|
+
execute(engine) {
|
|
161
|
+
const block = getBlockAtCursor(engine);
|
|
162
|
+
if (isBlockType(engine, 'callout')) {
|
|
163
|
+
// Already a callout — revert to plain text and clear variant
|
|
164
|
+
engine.dispatch([
|
|
165
|
+
{ type: 'set_block_type', blockId: block.id, blockType: 'text' },
|
|
166
|
+
{ type: 'set_block_attrs', blockId: block.id, attrs: { variant: null } },
|
|
167
|
+
]);
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
// Set to callout with info variant
|
|
171
|
+
setBlockType(engine, block.id, 'callout', { variant: 'info' });
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
canExecute(_engine) {
|
|
175
|
+
return true;
|
|
176
|
+
},
|
|
177
|
+
isActive(engine) {
|
|
178
|
+
return isBlockType(engine, 'callout');
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
// ---------------------------------------------------------------
|
|
182
|
+
// Input rule: > ! at block start converts to callout
|
|
183
|
+
// ---------------------------------------------------------------
|
|
184
|
+
ctx.registerInputRule({
|
|
185
|
+
pattern: /^> !$/,
|
|
186
|
+
exclusive: true,
|
|
187
|
+
handler(engine, match, blockId) {
|
|
188
|
+
const blockStart = getBlockStartOffset(engine.state.doc, blockId);
|
|
189
|
+
const prefixLength = match[0].length;
|
|
190
|
+
engine.dispatch([
|
|
191
|
+
{ type: 'delete_text', offset: blockStart, count: prefixLength },
|
|
192
|
+
{ type: 'set_block_type', blockId, blockType: 'callout' },
|
|
193
|
+
{ type: 'set_block_attrs', blockId, attrs: { variant: 'info' } },
|
|
194
|
+
]);
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
},
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
//# sourceMappingURL=callout-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"callout-plugin.js","sourceRoot":"","sources":["../../src/plugins/callout-plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEpG;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,MAAM,EAAE,eAAe;IACvB,WAAW,EAAE,mBAAmB;IAChC,MAAM,EAAE,eAAe;CACf,CAAC;AA6CX,6DAA6D;AAC7D,MAAM,cAAc,GAAwB,IAAI,GAAG,CAAS;IAC1D,MAAM;IACN,SAAS;IACT,OAAO;IACP,SAAS;IACT,MAAM;CACP,CAAC,CAAC;AAEH;;;;;;;;;;;GAWG;AACH,SAAS,cAAc,CAAC,KAAc;IACpC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AAChE,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO;QACL,EAAE,EAAE,eAAe;QACnB,IAAI,CAAC,GAAG;YACN,kEAAkE;YAClE,0BAA0B;YAC1B,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M,CAAC;wBACN,mCAAmC;wBACnC,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;oBACjE,CAAC;gBACH,CAAC;gBAED,UAAU,CAAC,OAAsB;oBAC/B,OAAO,IAAI,CAAC;gBACd,CAAC;gBAED,QAAQ,CAAC,MAAqB;oBAC5B,OAAO,WAAW,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;gBACxC,CAAC;aACF,CAAC,CAAC;YAEH,kEAAkE;YAClE,qDAAqD;YACrD,kEAAkE;YAElE,GAAG,CAAC,iBAAiB,CAAC;gBACpB,OAAO,EAAE,OAAO;gBAChB,SAAS,EAAE,IAAI;gBACf,OAAO,CAAC,MAAqB,EAAE,KAAuB,EAAE,OAAe;oBACrE,MAAM,UAAU,GAAG,mBAAmB,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;oBAClE,MAAM,YAAY,GAAG,KAAK,CAAC,CAAC,CAAE,CAAC,MAAM,CAAC;oBAEtC,MAAM,CAAC,QAAQ,CAAC;wBACd,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,YAAY,EAAE;wBAChE,EAAE,IAAI,EAAE,gBAAgB,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE;wBACzD,EAAE,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE;qBACjE,CAAC,CAAC;gBACL,CAAC;aACF,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Code block type plugin — registers the `code_block` block type,
|
|
3
|
+
* `toggleCodeBlock` and `setCodeLanguage` commands, and an input rule
|
|
4
|
+
* for triple backtick + space at block start.
|
|
5
|
+
*
|
|
6
|
+
* Also intercepts `split_block` inside code blocks via `beforeApply`,
|
|
7
|
+
* replacing them with `insert_text('\n')` so that Enter inserts a
|
|
8
|
+
* newline instead of creating a new block.
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
import type { Plugin } from '@rtif-sdk/engine';
|
|
13
|
+
/**
|
|
14
|
+
* Command name constants for the code block plugin.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* engine.exec(CodeBlockCommands.TOGGLE);
|
|
19
|
+
* engine.exec(CodeBlockCommands.SET_LANGUAGE, { language: 'typescript' });
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare const CodeBlockCommands: {
|
|
23
|
+
readonly TOGGLE: "toggleCodeBlock";
|
|
24
|
+
readonly SET_LANGUAGE: "setCodeLanguage";
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Payload for the `setCodeLanguage` command.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* engine.exec('setCodeLanguage', { language: 'typescript' });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export interface SetCodeLanguagePayload {
|
|
35
|
+
/** The programming language identifier (e.g., "typescript", "python") */
|
|
36
|
+
readonly language: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Create the code block type plugin.
|
|
40
|
+
*
|
|
41
|
+
* Registers:
|
|
42
|
+
* - Block type: `code_block` (defaultAttrs: `{ language: '' }`, language must be a string)
|
|
43
|
+
* - Command: `toggleCodeBlock` — toggle between code block and plain text
|
|
44
|
+
* - Command: `setCodeLanguage` — set the language attribute on a code block
|
|
45
|
+
* - Input rule: ``` followed by space at block start converts to code block
|
|
46
|
+
*
|
|
47
|
+
* @returns A plugin instance ready for `engine.use()`
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* const engine = createEngine(initialDoc);
|
|
52
|
+
* engine.use(codeBlockPlugin());
|
|
53
|
+
*
|
|
54
|
+
* // Toggle code block on the block at cursor
|
|
55
|
+
* engine.exec(CodeBlockCommands.TOGGLE);
|
|
56
|
+
*
|
|
57
|
+
* // Set language on the current code block
|
|
58
|
+
* engine.exec(CodeBlockCommands.SET_LANGUAGE, { language: 'typescript' });
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare function codeBlockPlugin(): Plugin;
|
|
62
|
+
//# sourceMappingURL=code-block-plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-block-plugin.d.ts","sourceRoot":"","sources":["../../src/plugins/code-block-plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,KAAK,EAAE,MAAM,EAA8B,MAAM,kBAAkB,CAAC;AAG3E;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB;;;CAGpB,CAAC;AAEX;;;;;;;GAOG;AACH,MAAM,WAAW,sBAAsB;IACrC,yEAAyE;IACzE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAgJxC"}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Code block type plugin — registers the `code_block` block type,
|
|
3
|
+
* `toggleCodeBlock` and `setCodeLanguage` commands, and an input rule
|
|
4
|
+
* for triple backtick + space at block start.
|
|
5
|
+
*
|
|
6
|
+
* Also intercepts `split_block` inside code blocks via `beforeApply`,
|
|
7
|
+
* replacing them with `insert_text('\n')` so that Enter inserts a
|
|
8
|
+
* newline instead of creating a new block.
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
import { resolve, blockTextLength } from '@rtif-sdk/core';
|
|
13
|
+
import { getBlockStartOffset, getBlockAtCursor, isBlockType, setBlockType } from './block-utils.js';
|
|
14
|
+
/**
|
|
15
|
+
* Command name constants for the code block plugin.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* engine.exec(CodeBlockCommands.TOGGLE);
|
|
20
|
+
* engine.exec(CodeBlockCommands.SET_LANGUAGE, { language: 'typescript' });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export const CodeBlockCommands = {
|
|
24
|
+
TOGGLE: 'toggleCodeBlock',
|
|
25
|
+
SET_LANGUAGE: 'setCodeLanguage',
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Create the code block type plugin.
|
|
29
|
+
*
|
|
30
|
+
* Registers:
|
|
31
|
+
* - Block type: `code_block` (defaultAttrs: `{ language: '' }`, language must be a string)
|
|
32
|
+
* - Command: `toggleCodeBlock` — toggle between code block and plain text
|
|
33
|
+
* - Command: `setCodeLanguage` — set the language attribute on a code block
|
|
34
|
+
* - Input rule: ``` followed by space at block start converts to code block
|
|
35
|
+
*
|
|
36
|
+
* @returns A plugin instance ready for `engine.use()`
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* const engine = createEngine(initialDoc);
|
|
41
|
+
* engine.use(codeBlockPlugin());
|
|
42
|
+
*
|
|
43
|
+
* // Toggle code block on the block at cursor
|
|
44
|
+
* engine.exec(CodeBlockCommands.TOGGLE);
|
|
45
|
+
*
|
|
46
|
+
* // Set language on the current code block
|
|
47
|
+
* engine.exec(CodeBlockCommands.SET_LANGUAGE, { language: 'typescript' });
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export function codeBlockPlugin() {
|
|
51
|
+
return {
|
|
52
|
+
id: 'block-code-block',
|
|
53
|
+
beforeApply(ops, state) {
|
|
54
|
+
const removedBlockIds = new Set();
|
|
55
|
+
const transformed = ops.flatMap((op) => {
|
|
56
|
+
if (op.type !== 'split_block')
|
|
57
|
+
return [op];
|
|
58
|
+
let resolved;
|
|
59
|
+
let block;
|
|
60
|
+
try {
|
|
61
|
+
resolved = resolve(state.doc, op.offset);
|
|
62
|
+
block = state.doc.blocks[resolved.blockIndex];
|
|
63
|
+
if (!block || block.type !== 'code_block')
|
|
64
|
+
return [op];
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return [op];
|
|
68
|
+
}
|
|
69
|
+
const blockLen = blockTextLength(block);
|
|
70
|
+
// Exit condition: cursor at end of block and block text ends with \n.
|
|
71
|
+
// This implements "double-Enter to exit" — the first Enter inserted \n,
|
|
72
|
+
// the second Enter exits the code block and creates a new text block.
|
|
73
|
+
if (resolved.localOffset === blockLen && blockLen > 0) {
|
|
74
|
+
let blockText = '';
|
|
75
|
+
for (const span of block.spans) {
|
|
76
|
+
blockText += span.text;
|
|
77
|
+
}
|
|
78
|
+
if (blockText.endsWith('\n')) {
|
|
79
|
+
const newBlockId = op.newBlockId ?? `${block.id}_split`;
|
|
80
|
+
const deleteOffset = op.offset - 1;
|
|
81
|
+
return [
|
|
82
|
+
{ type: 'delete_text', offset: deleteOffset, count: 1 },
|
|
83
|
+
{ type: 'split_block', offset: deleteOffset, newBlockId },
|
|
84
|
+
{ type: 'set_block_type', blockId: newBlockId, blockType: 'text' },
|
|
85
|
+
];
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
// Normal case: convert split_block to insert_text('\n')
|
|
89
|
+
if (op.newBlockId) {
|
|
90
|
+
removedBlockIds.add(op.newBlockId);
|
|
91
|
+
}
|
|
92
|
+
return [{ type: 'insert_text', offset: op.offset, text: '\n' }];
|
|
93
|
+
});
|
|
94
|
+
if (removedBlockIds.size === 0)
|
|
95
|
+
return transformed;
|
|
96
|
+
return transformed.filter((op) => {
|
|
97
|
+
if ((op.type === 'set_block_type' || op.type === 'set_block_attrs' || op.type === 'merge_block') &&
|
|
98
|
+
removedBlockIds.has(op.blockId)) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
return true;
|
|
102
|
+
});
|
|
103
|
+
},
|
|
104
|
+
init(ctx) {
|
|
105
|
+
// ---------------------------------------------------------------
|
|
106
|
+
// Block type registration
|
|
107
|
+
// ---------------------------------------------------------------
|
|
108
|
+
ctx.registerBlockType('code_block', {
|
|
109
|
+
defaultAttrs: { language: '' },
|
|
110
|
+
validate: (attrs) => {
|
|
111
|
+
return typeof attrs.language === 'string';
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
// ---------------------------------------------------------------
|
|
115
|
+
// toggleCodeBlock command
|
|
116
|
+
// ---------------------------------------------------------------
|
|
117
|
+
ctx.registerCommand(CodeBlockCommands.TOGGLE, {
|
|
118
|
+
execute(engine) {
|
|
119
|
+
const block = getBlockAtCursor(engine);
|
|
120
|
+
if (isBlockType(engine, 'code_block')) {
|
|
121
|
+
// Already a code block — revert to plain text and clear language attr
|
|
122
|
+
engine.dispatch([
|
|
123
|
+
{ type: 'set_block_type', blockId: block.id, blockType: 'text' },
|
|
124
|
+
{ type: 'set_block_attrs', blockId: block.id, attrs: { language: null } },
|
|
125
|
+
]);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
// Set to code block
|
|
129
|
+
setBlockType(engine, block.id, 'code_block');
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
canExecute(_engine) {
|
|
133
|
+
return true;
|
|
134
|
+
},
|
|
135
|
+
isActive(engine) {
|
|
136
|
+
return isBlockType(engine, 'code_block');
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
// ---------------------------------------------------------------
|
|
140
|
+
// setCodeLanguage command
|
|
141
|
+
// ---------------------------------------------------------------
|
|
142
|
+
ctx.registerCommand(CodeBlockCommands.SET_LANGUAGE, {
|
|
143
|
+
execute(engine, payload) {
|
|
144
|
+
const p = payload;
|
|
145
|
+
if (!p || typeof p.language !== 'string')
|
|
146
|
+
return;
|
|
147
|
+
const block = getBlockAtCursor(engine);
|
|
148
|
+
if (block.type !== 'code_block')
|
|
149
|
+
return;
|
|
150
|
+
engine.dispatch([
|
|
151
|
+
{ type: 'set_block_attrs', blockId: block.id, attrs: { language: p.language } },
|
|
152
|
+
]);
|
|
153
|
+
},
|
|
154
|
+
canExecute(engine) {
|
|
155
|
+
return isBlockType(engine, 'code_block');
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
// ---------------------------------------------------------------
|
|
159
|
+
// Input rule: ``` followed by space at block start
|
|
160
|
+
// ---------------------------------------------------------------
|
|
161
|
+
ctx.registerInputRule({
|
|
162
|
+
pattern: /^``` $/,
|
|
163
|
+
exclusive: true,
|
|
164
|
+
handler(engine, match, blockId) {
|
|
165
|
+
const blockStart = getBlockStartOffset(engine.state.doc, blockId);
|
|
166
|
+
const prefixLength = match[0].length;
|
|
167
|
+
engine.dispatch([
|
|
168
|
+
{ type: 'delete_text', offset: blockStart, count: prefixLength },
|
|
169
|
+
{ type: 'set_block_type', blockId, blockType: 'code_block' },
|
|
170
|
+
]);
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=code-block-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-block-plugin.js","sourceRoot":"","sources":["../../src/plugins/code-block-plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAE1D,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEpG;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,MAAM,EAAE,iBAAiB;IACzB,YAAY,EAAE,iBAAiB;CACvB,CAAC;AAeX;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,eAAe;IAC7B,OAAO;QACL,EAAE,EAAE,kBAAkB;QAEtB,WAAW,CAAC,GAAgB,EAAE,KA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K,YAAY;wBAAE,OAAO;oBAExC,MAAM,CAAC,QAAQ,CAAC;wBACd,EAAE,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC,QAAQ,EAAE,EAAE;qBAChF,CAAC,CAAC;gBACL,CAAC;gBAED,UAAU,CAAC,MAAqB;oBAC9B,OAAO,WAAW,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;gBAC3C,CAAC;aACF,CAAC,CAAC;YAEH,kEAAkE;YAClE,mDAAmD;YACnD,kEAAkE;YAElE,GAAG,CAAC,iBAAiB,CAAC;gBACpB,OAAO,EAAE,QAAQ;gBACjB,SAAS,EAAE,IAAI;gBACf,OAAO,CAAC,MAAqB,EAAE,KAAuB,EAAE,OAAe;oBACrE,MAAM,UAAU,GAAG,mBAAmB,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;oBAClE,MAAM,YAAY,GAAG,KAAK,CAAC,CAAC,CAAE,CAAC,MAAM,CAAC;oBAEtC,MAAM,CAAC,QAAQ,CAAC;wBACd,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,YAAY,EAAE;wBAChE,EAAE,IAAI,EAAE,gBAAgB,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE;qBAC7D,CAAC,CAAC;gBACL,CAAC;aACF,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inline code mark plugin — registers the `code` mark type, `toggleMark:code`
|
|
3
|
+
* command, and Cmd/Ctrl+E keyboard shortcut.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import type { Plugin } from '@rtif-sdk/engine';
|
|
8
|
+
/**
|
|
9
|
+
* Command name constants for the inline code mark plugin.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* engine.exec(CodeMarkCommands.TOGGLE);
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare const CodeMarkCommands: {
|
|
17
|
+
readonly TOGGLE: "toggleMark:code";
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Create the inline code mark plugin.
|
|
21
|
+
*
|
|
22
|
+
* Registers:
|
|
23
|
+
* - Mark type: `code` (value must be `true`)
|
|
24
|
+
* - Command: `toggleMark:code`
|
|
25
|
+
* - Shortcut: Cmd/Ctrl+E
|
|
26
|
+
*
|
|
27
|
+
* @returns A plugin instance ready for `engine.use()`
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* const engine = createEngine(initialDoc);
|
|
32
|
+
* engine.use(codePlugin());
|
|
33
|
+
* engine.exec(CodeMarkCommands.TOGGLE);
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function codePlugin(): Plugin;
|
|
37
|
+
//# sourceMappingURL=code-plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-plugin.d.ts","sourceRoot":"","sources":["../../src/plugins/code-plugin.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAG/C;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB;;CAEnB,CAAC;AAEX;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,UAAU,IAAI,MAAM,CAanC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inline code mark plugin — registers the `code` mark type, `toggleMark:code`
|
|
3
|
+
* command, and Cmd/Ctrl+E keyboard shortcut.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { createToggleMarkCommand } from './mark-utils.js';
|
|
8
|
+
/**
|
|
9
|
+
* Command name constants for the inline code mark plugin.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* engine.exec(CodeMarkCommands.TOGGLE);
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export const CodeMarkCommands = {
|
|
17
|
+
TOGGLE: 'toggleMark:code',
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Create the inline code mark plugin.
|
|
21
|
+
*
|
|
22
|
+
* Registers:
|
|
23
|
+
* - Mark type: `code` (value must be `true`)
|
|
24
|
+
* - Command: `toggleMark:code`
|
|
25
|
+
* - Shortcut: Cmd/Ctrl+E
|
|
26
|
+
*
|
|
27
|
+
* @returns A plugin instance ready for `engine.use()`
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* const engine = createEngine(initialDoc);
|
|
32
|
+
* engine.use(codePlugin());
|
|
33
|
+
* engine.exec(CodeMarkCommands.TOGGLE);
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export function codePlugin() {
|
|
37
|
+
return {
|
|
38
|
+
id: 'mark-code',
|
|
39
|
+
init(ctx) {
|
|
40
|
+
ctx.registerMarkType('code', {
|
|
41
|
+
validate: (value) => value === true,
|
|
42
|
+
});
|
|
43
|
+
ctx.registerCommand(CodeMarkCommands.TOGGLE, createToggleMarkCommand('code'));
|
|
44
|
+
ctx.registerShortcut({ key: 'e', mod: true }, CodeMarkCommands.TOGGLE);
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=code-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-plugin.js","sourceRoot":"","sources":["../../src/plugins/code-plugin.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAE1D;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,MAAM,EAAE,iBAAiB;CACjB,CAAC;AAEX;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,UAAU;IACxB,OAAO;QACL,EAAE,EAAE,WAAW;QACf,IAAI,CAAC,GAAG;YACN,GAAG,CAAC,gBAAgB,CAAC,MAAM,EAAE;gBAC3B,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,IAAI;aACpC,CAAC,CAAC;YAEH,GAAG,CAAC,eAAe,CAAC,gBAAgB,CAAC,MAAM,EAAE,uBAAuB,CAAC,MAAM,CAAC,CAAC,CAAC;YAE9E,GAAG,CAAC,gBAAgB,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC;QACzE,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Embed block type plugin — registers the `embed` block type and
|
|
3
|
+
* `insertEmbed` / `removeEmbed` commands for embedding external content
|
|
4
|
+
* (YouTube, Twitter/X, Vimeo, etc.) as atomic, non-editable blocks.
|
|
5
|
+
*
|
|
6
|
+
* Embed blocks are atomic — they carry no meaningful text content.
|
|
7
|
+
* Their visual representation is determined by the block renderer layer
|
|
8
|
+
* (iframe, provider-specific HTML, etc.) based on the `url` and
|
|
9
|
+
* `embedType` attributes.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
import type { Plugin } from '@rtif-sdk/engine';
|
|
14
|
+
/**
|
|
15
|
+
* Command name constants for the embed plugin.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* engine.exec(EmbedCommands.INSERT, { url: 'https://youtube.com/...' });
|
|
20
|
+
* engine.exec(EmbedCommands.REMOVE, { blockId: 'b3' });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare const EmbedCommands: {
|
|
24
|
+
readonly INSERT: "insertEmbed";
|
|
25
|
+
readonly REMOVE: "removeEmbed";
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* The kind of embedded content.
|
|
29
|
+
*
|
|
30
|
+
* - `'video'` — Video embeds (YouTube, Vimeo, etc.)
|
|
31
|
+
* - `'tweet'` — Social media embeds (Twitter/X, etc.)
|
|
32
|
+
* - `'generic'` — Fallback for any other embeddable URL
|
|
33
|
+
*/
|
|
34
|
+
export type EmbedType = 'video' | 'tweet' | 'generic';
|
|
35
|
+
/**
|
|
36
|
+
* Payload for the `insertEmbed` command.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* engine.exec('insertEmbed', {
|
|
41
|
+
* url: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
|
|
42
|
+
* type: 'video',
|
|
43
|
+
* });
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export interface InsertEmbedPayload {
|
|
47
|
+
/** The URL of the content to embed */
|
|
48
|
+
readonly url: string;
|
|
49
|
+
/** The embed type. Defaults to `'generic'` when omitted. */
|
|
50
|
+
readonly type?: EmbedType;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Payload for the `removeEmbed` command.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* engine.exec('removeEmbed', { blockId: 'b3' });
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export interface RemoveEmbedPayload {
|
|
61
|
+
/** The ID of the embed block to revert to plain text */
|
|
62
|
+
readonly blockId: string;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Create the embed block type plugin.
|
|
66
|
+
*
|
|
67
|
+
* Registers:
|
|
68
|
+
* - Block type: `embed` (attrs must include `url` as a non-empty string)
|
|
69
|
+
* - Command: `insertEmbed` — inserts a new embed block after the current block
|
|
70
|
+
* - Command: `removeEmbed` — reverts an embed block to plain text, clearing embed attrs
|
|
71
|
+
*
|
|
72
|
+
* @returns A plugin instance ready for `engine.use()`
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* const engine = createEngine(initialDoc);
|
|
77
|
+
* engine.use(embedPlugin());
|
|
78
|
+
*
|
|
79
|
+
* // Insert a YouTube embed after the current block
|
|
80
|
+
* engine.exec(EmbedCommands.INSERT, {
|
|
81
|
+
* url: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
|
|
82
|
+
* type: 'video',
|
|
83
|
+
* });
|
|
84
|
+
*
|
|
85
|
+
* // Remove the embed, reverting to a plain text block
|
|
86
|
+
* engine.exec(EmbedCommands.REMOVE, { blockId: 'b2' });
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export declare function embedPlugin(): Plugin;
|
|
90
|
+
//# sourceMappingURL=embed-plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embed-plugin.d.ts","sourceRoot":"","sources":["../../src/plugins/embed-plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,kBAAkB,CAAC;AAK9D;;;;;;;;GAQG;AACH,eAAO,MAAM,aAAa;;;CAGhB,CAAC;AAEX;;;;;;GAMG;AACH,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,OAAO,GAAG,SAAS,CAAC;AAEtD;;;;;;;;;;GAUG;AACH,MAAM,WAAW,kBAAkB;IACjC,sCAAsC;IACtC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,4DAA4D;IAC5D,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC;CAC3B;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,kBAAkB;IACjC,wDAAwD;IACxD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,WAAW,IAAI,MAAM,CA4GpC"}
|