@notectl/core 2.0.1 → 2.0.2
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 -10
- package/dist/chunks/{AttrRegistry-Ckj9eCHj.mjs → AttrRegistry-iNpjvcSG.mjs} +2 -2
- package/dist/chunks/{AttrRegistry-Ckj9eCHj.mjs.map → AttrRegistry-iNpjvcSG.mjs.map} +1 -1
- package/dist/chunks/AttributedMarkCommands-BY1BSYWM.mjs +2 -0
- package/dist/chunks/{AttributedMarkCommands-x7h4Xy7V.mjs.map → AttributedMarkCommands-BY1BSYWM.mjs.map} +1 -1
- package/dist/chunks/BlockInsertion-BJFhE0jA.mjs +2 -0
- package/dist/chunks/BlockInsertion-BJFhE0jA.mjs.map +1 -0
- package/dist/chunks/{ColorPickerPopup-CDUvkgcK.mjs → ColorPickerPopup-D6XjShhv.mjs} +2 -2
- package/dist/chunks/{ColorPickerPopup-CDUvkgcK.mjs.map → ColorPickerPopup-D6XjShhv.mjs.map} +1 -1
- package/dist/chunks/CommandHelpers-M6mPS6Ww.mjs +2 -0
- package/dist/chunks/CommandHelpers-M6mPS6Ww.mjs.map +1 -0
- package/dist/chunks/Commands-D_gMCnVa.mjs +2 -0
- package/dist/chunks/Commands-D_gMCnVa.mjs.map +1 -0
- package/dist/chunks/Document-3pNX7ear.mjs +2 -0
- package/dist/chunks/{Document-HC8s50qJ.mjs.map → Document-3pNX7ear.mjs.map} +1 -1
- package/dist/chunks/{DocumentParser-w70-Axud.mjs → DocumentParser-LvzDQOd1.mjs} +2 -2
- package/dist/chunks/{DocumentParser-w70-Axud.mjs.map → DocumentParser-LvzDQOd1.mjs.map} +1 -1
- package/dist/chunks/{HeadingPlugin-B-LF-AMM.mjs → HeadingPlugin-BmkeUXj8.mjs} +2 -2
- package/dist/chunks/{HeadingPlugin-B-LF-AMM.mjs.map → HeadingPlugin-BmkeUXj8.mjs.map} +1 -1
- package/dist/chunks/MarkCommands-CeCa4WSC.mjs +2 -0
- package/dist/chunks/{MarkCommands-CTuVDqnn.mjs.map → MarkCommands-CeCa4WSC.mjs.map} +1 -1
- package/dist/chunks/NavigationQueries-11qe4j9x.mjs +2 -0
- package/dist/chunks/NavigationQueries-11qe4j9x.mjs.map +1 -0
- package/dist/chunks/NodeResolver-z0ReCR34.mjs +2 -0
- package/dist/chunks/NodeResolver-z0ReCR34.mjs.map +1 -0
- package/dist/chunks/NodeSelectionCommands-CXrOcPtG.mjs +2 -0
- package/dist/chunks/NodeSelectionCommands-CXrOcPtG.mjs.map +1 -0
- package/dist/chunks/NotectlEditor-BJD7-FFx.mjs +4 -0
- package/dist/chunks/NotectlEditor-BJD7-FFx.mjs.map +1 -0
- package/dist/chunks/PopupManager-0b_Q0m7K.mjs +2 -0
- package/dist/chunks/PopupManager-0b_Q0m7K.mjs.map +1 -0
- package/dist/chunks/{RangeIterator-CprUbOWv.mjs → RangeIterator-XFN5FaYf.mjs} +2 -2
- package/dist/chunks/{RangeIterator-CprUbOWv.mjs.map → RangeIterator-XFN5FaYf.mjs.map} +1 -1
- package/dist/chunks/SelectionTransactions-DzIZxcuN.mjs +2 -0
- package/dist/chunks/{SelectionTransactions-DB3YDIEa.mjs.map → SelectionTransactions-DzIZxcuN.mjs.map} +1 -1
- package/dist/chunks/{TextDirectionLocale-BraFI9JF.mjs → TextDirectionLocale-CKz0ZrH_.mjs} +2 -2
- package/dist/chunks/{TextDirectionLocale-BraFI9JF.mjs.map → TextDirectionLocale-CKz0ZrH_.mjs.map} +1 -1
- package/dist/chunks/index-C-L4awHz.mjs +2 -0
- package/dist/chunks/index-C-L4awHz.mjs.map +1 -0
- package/dist/chunks/{index-D3BZFsAD.mjs → index-Cs9iqxhF.mjs} +2 -2
- package/dist/chunks/{index-D3BZFsAD.mjs.map → index-Cs9iqxhF.mjs.map} +1 -1
- package/dist/commands/BlockInsertion.d.ts.map +1 -1
- package/dist/commands/CommandHelpers.d.ts +13 -2
- package/dist/commands/CommandHelpers.d.ts.map +1 -1
- package/dist/commands/NodeSelectionCommands.d.ts +3 -8
- package/dist/commands/NodeSelectionCommands.d.ts.map +1 -1
- package/dist/editor/ContentSerializer.d.ts.map +1 -1
- package/dist/editor/EditorConfig.d.ts +50 -0
- package/dist/editor/EditorConfig.d.ts.map +1 -0
- package/dist/editor/EditorConfigController.d.ts +1 -1
- package/dist/editor/EditorConfigController.d.ts.map +1 -1
- package/dist/editor/EditorDOM.d.ts.map +1 -1
- package/dist/editor/EditorInitializer.d.ts +37 -0
- package/dist/editor/EditorInitializer.d.ts.map +1 -0
- package/dist/editor/EditorLifecycleCoordinator.d.ts +6 -1
- package/dist/editor/EditorLifecycleCoordinator.d.ts.map +1 -1
- package/dist/editor/NotectlEditor.d.ts +13 -51
- package/dist/editor/NotectlEditor.d.ts.map +1 -1
- package/dist/editor/PluginBootstrapper.d.ts +1 -1
- package/dist/editor/PluginBootstrapper.d.ts.map +1 -1
- package/dist/full.mjs +1 -1
- package/dist/html.mjs +1 -1
- package/dist/input/ClipboardHandler.d.ts +5 -0
- package/dist/input/ClipboardHandler.d.ts.map +1 -1
- package/dist/input/HTMLParser.d.ts +9 -5
- package/dist/input/HTMLParser.d.ts.map +1 -1
- package/dist/input/InputHandler.d.ts +1 -0
- package/dist/input/InputHandler.d.ts.map +1 -1
- package/dist/input/PasteHTMLHandler.d.ts +25 -0
- package/dist/input/PasteHTMLHandler.d.ts.map +1 -0
- package/dist/input/PasteHandler.d.ts +2 -27
- package/dist/input/PasteHandler.d.ts.map +1 -1
- package/dist/input/PasteRichBlockHandler.d.ts +23 -0
- package/dist/input/PasteRichBlockHandler.d.ts.map +1 -0
- package/dist/input/SelectionDocument.d.ts +10 -0
- package/dist/input/SelectionDocument.d.ts.map +1 -0
- package/dist/model/RichBlockData.d.ts +12 -2
- package/dist/model/RichBlockData.d.ts.map +1 -1
- package/dist/notectl-core.mjs +1 -1
- package/dist/notectl-core.umd.js +1 -1
- package/dist/notectl-core.umd.js.map +1 -1
- package/dist/plugins/PluginContextFactory.d.ts +73 -0
- package/dist/plugins/PluginContextFactory.d.ts.map +1 -0
- package/dist/plugins/PluginManager.d.ts +5 -0
- package/dist/plugins/PluginManager.d.ts.map +1 -1
- package/dist/plugins/blockquote.mjs +1 -1
- package/dist/plugins/caret-navigation.mjs +1 -1
- package/dist/plugins/code-block.mjs +1 -1
- package/dist/plugins/font-size.mjs +1 -1
- package/dist/plugins/font.mjs +1 -1
- package/dist/plugins/gap-cursor.mjs +1 -1
- package/dist/plugins/hard-break.mjs +1 -1
- package/dist/plugins/heading.mjs +1 -1
- package/dist/plugins/highlight.mjs +1 -1
- package/dist/plugins/horizontal-rule.mjs +1 -1
- package/dist/plugins/image/ImageCommands.d.ts.map +1 -1
- package/dist/plugins/image.mjs +1 -1
- package/dist/plugins/image.mjs.map +1 -1
- package/dist/plugins/link.mjs +1 -1
- package/dist/plugins/list.mjs +1 -1
- package/dist/plugins/print.mjs +1 -1
- package/dist/plugins/shared/PopupManager.d.ts.map +1 -1
- package/dist/plugins/shared.mjs +1 -1
- package/dist/plugins/smart-paste.mjs +1 -1
- package/dist/plugins/strikethrough.mjs +1 -1
- package/dist/plugins/super-sub.mjs +1 -1
- package/dist/plugins/table/TableCommands.d.ts +1 -0
- package/dist/plugins/table/TableCommands.d.ts.map +1 -1
- package/dist/plugins/table/TableContextMenu.d.ts.map +1 -1
- package/dist/plugins/table/TableSelection.d.ts.map +1 -1
- package/dist/plugins/table.mjs +1 -1
- package/dist/plugins/table.mjs.map +1 -1
- package/dist/plugins/text-color.mjs +1 -1
- package/dist/plugins/text-direction-advanced.mjs +1 -1
- package/dist/plugins/text-direction.mjs +1 -1
- package/dist/plugins/text-formatting.mjs +1 -1
- package/dist/plugins/toolbar/ToolbarOverflowController.d.ts +2 -0
- package/dist/plugins/toolbar/ToolbarOverflowController.d.ts.map +1 -1
- package/dist/plugins/toolbar.mjs +1 -1
- package/dist/plugins/toolbar.mjs.map +1 -1
- package/dist/presets/full.mjs +1 -1
- package/dist/state/StepInversion.d.ts.map +1 -1
- package/dist/view/EditorView.d.ts +8 -58
- package/dist/view/EditorView.d.ts.map +1 -1
- package/dist/view/EditorViewEvents.d.ts +54 -0
- package/dist/view/EditorViewEvents.d.ts.map +1 -0
- package/dist/view/EditorViewNavigation.d.ts +47 -0
- package/dist/view/EditorViewNavigation.d.ts.map +1 -0
- package/dist/view/SelectionSync.d.ts.map +1 -1
- package/package.json +2 -2
- package/dist/chunks/AttributedMarkCommands-x7h4Xy7V.mjs +0 -2
- package/dist/chunks/BlockInsertion-zPxm6oa_.mjs +0 -2
- package/dist/chunks/BlockInsertion-zPxm6oa_.mjs.map +0 -1
- package/dist/chunks/Commands-DwXBBVGR.mjs +0 -2
- package/dist/chunks/Commands-DwXBBVGR.mjs.map +0 -1
- package/dist/chunks/Document-HC8s50qJ.mjs +0 -2
- package/dist/chunks/MarkCommands-CTuVDqnn.mjs +0 -2
- package/dist/chunks/NavigationQueries-DCOv4Ca5.mjs +0 -2
- package/dist/chunks/NavigationQueries-DCOv4Ca5.mjs.map +0 -1
- package/dist/chunks/NotectlEditor-DBBJkPCW.mjs +0 -3
- package/dist/chunks/NotectlEditor-DBBJkPCW.mjs.map +0 -1
- package/dist/chunks/PopupManager-Du3dYnsJ.mjs +0 -2
- package/dist/chunks/PopupManager-Du3dYnsJ.mjs.map +0 -1
- package/dist/chunks/SelectionTransactions-DB3YDIEa.mjs +0 -2
- package/dist/chunks/index-CVwf0cdH.mjs +0 -2
- package/dist/chunks/index-CVwf0cdH.mjs.map +0 -1
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { FileHandler, FileHandlerRegistry } from '../model/FileHandlerRegistry.js';
|
|
2
|
+
import { InputRule } from '../model/InputRule.js';
|
|
3
|
+
import { InputRuleRegistry } from '../model/InputRuleRegistry.js';
|
|
4
|
+
import { Keymap } from '../model/Keymap.js';
|
|
5
|
+
import { KeymapRegistry } from '../model/KeymapRegistry.js';
|
|
6
|
+
import { PasteInterceptorEntry } from '../model/PasteInterceptor.js';
|
|
7
|
+
import { SchemaRegistry } from '../model/SchemaRegistry.js';
|
|
8
|
+
import { EditorState } from '../state/EditorState.js';
|
|
9
|
+
import { Transaction } from '../state/Transaction.js';
|
|
10
|
+
import { NodeViewRegistry } from '../view/NodeViewRegistry.js';
|
|
11
|
+
import { EventBus } from './EventBus.js';
|
|
12
|
+
import { CommandEntry, Plugin, PluginContext, TransactionMiddleware } from './Plugin.js';
|
|
13
|
+
import { BlockTypePickerRegistry } from './heading/BlockTypePickerRegistry.js';
|
|
14
|
+
import { ToolbarRegistry } from './toolbar/ToolbarRegistry.js';
|
|
15
|
+
export interface MiddlewareEntry {
|
|
16
|
+
readonly name: string;
|
|
17
|
+
readonly pluginId: string;
|
|
18
|
+
readonly middleware: TransactionMiddleware;
|
|
19
|
+
readonly priority: number;
|
|
20
|
+
}
|
|
21
|
+
export interface PluginRegistrations {
|
|
22
|
+
commands: string[];
|
|
23
|
+
services: string[];
|
|
24
|
+
middlewares: MiddlewareEntry[];
|
|
25
|
+
pasteInterceptors: PasteInterceptorEntry[];
|
|
26
|
+
unsubscribers: (() => void)[];
|
|
27
|
+
nodeSpecs: string[];
|
|
28
|
+
markSpecs: string[];
|
|
29
|
+
inlineNodeSpecs: string[];
|
|
30
|
+
nodeViews: string[];
|
|
31
|
+
keymaps: Keymap[];
|
|
32
|
+
inputRules: InputRule[];
|
|
33
|
+
toolbarItems: string[];
|
|
34
|
+
fileHandlers: FileHandler[];
|
|
35
|
+
blockTypePickerEntries: string[];
|
|
36
|
+
stylesheets: CSSStyleSheet[];
|
|
37
|
+
}
|
|
38
|
+
/** Dependencies needed by the context factory from the PluginManager. */
|
|
39
|
+
export interface ContextFactoryDeps {
|
|
40
|
+
readonly pluginId: string;
|
|
41
|
+
getState(): EditorState;
|
|
42
|
+
dispatch(transaction: Transaction): void;
|
|
43
|
+
getContainer(): HTMLElement;
|
|
44
|
+
getPluginContainer(position: 'top' | 'bottom'): HTMLElement;
|
|
45
|
+
announce?(text: string): void;
|
|
46
|
+
hasAnnouncement?(): boolean;
|
|
47
|
+
readonly commands: Map<string, CommandEntry>;
|
|
48
|
+
readonly services: Map<string, unknown>;
|
|
49
|
+
readonly middlewares: MiddlewareEntry[];
|
|
50
|
+
readonly pasteInterceptors: PasteInterceptorEntry[];
|
|
51
|
+
readonly pluginStyleSheets: CSSStyleSheet[];
|
|
52
|
+
readonly plugins: Map<string, Plugin>;
|
|
53
|
+
readonly eventBus: EventBus;
|
|
54
|
+
readonly schemaRegistry: SchemaRegistry;
|
|
55
|
+
readonly keymapRegistry: KeymapRegistry;
|
|
56
|
+
readonly inputRuleRegistry: InputRuleRegistry;
|
|
57
|
+
readonly toolbarRegistry: ToolbarRegistry;
|
|
58
|
+
readonly blockTypePickerRegistry: BlockTypePickerRegistry;
|
|
59
|
+
readonly fileHandlerRegistry: FileHandlerRegistry;
|
|
60
|
+
readonly nodeViewRegistry: NodeViewRegistry;
|
|
61
|
+
isReadOnly(): boolean;
|
|
62
|
+
invalidateMiddlewareSort(): void;
|
|
63
|
+
invalidatePasteSort(): void;
|
|
64
|
+
executeCommand(name: string): boolean;
|
|
65
|
+
}
|
|
66
|
+
/** Creates an empty registration tracker for a plugin. */
|
|
67
|
+
export declare function createEmptyRegistrations(): PluginRegistrations;
|
|
68
|
+
/** Creates a complete PluginContext by composing focused registrar factories. */
|
|
69
|
+
export declare function createPluginContext(deps: ContextFactoryDeps): {
|
|
70
|
+
context: PluginContext;
|
|
71
|
+
registrations: PluginRegistrations;
|
|
72
|
+
};
|
|
73
|
+
//# sourceMappingURL=PluginContextFactory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PluginContextFactory.d.ts","sourceRoot":"","sources":["../../src/plugins/PluginContextFactory.ts"],"names":[],"mappings":"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"}
|
|
@@ -17,6 +17,7 @@ export interface MiddlewareInfo {
|
|
|
17
17
|
readonly pluginId: string;
|
|
18
18
|
}
|
|
19
19
|
export type { PasteInterceptorEntry } from '../model/PasteInterceptor.js';
|
|
20
|
+
export type { MiddlewareEntry, PluginRegistrations } from './PluginContextFactory.js';
|
|
20
21
|
export interface PluginManagerInitOptions {
|
|
21
22
|
getState(): EditorState;
|
|
22
23
|
dispatch(transaction: Transaction): void;
|
|
@@ -28,6 +29,8 @@ export interface PluginManagerInitOptions {
|
|
|
28
29
|
hasAnnouncement?(): boolean;
|
|
29
30
|
/** Called after all plugin init() calls complete, before onReady(). */
|
|
30
31
|
onBeforeReady?(): void | Promise<void>;
|
|
32
|
+
/** Returns whether initialization should stop early. */
|
|
33
|
+
isCancelled?(): boolean;
|
|
31
34
|
}
|
|
32
35
|
export declare class PluginManager {
|
|
33
36
|
private readonly plugins;
|
|
@@ -48,6 +51,7 @@ export declare class PluginManager {
|
|
|
48
51
|
private middlewareSorted;
|
|
49
52
|
private pasteInterceptorsSorted;
|
|
50
53
|
private initOrder;
|
|
54
|
+
private startedInitOrder;
|
|
51
55
|
private initialized;
|
|
52
56
|
private initializing;
|
|
53
57
|
private readOnly;
|
|
@@ -99,6 +103,7 @@ export declare class PluginManager {
|
|
|
99
103
|
/** Destroys all plugins in reverse init order. */
|
|
100
104
|
destroy(): Promise<void>;
|
|
101
105
|
private destroyPlugin;
|
|
106
|
+
private rollbackStartedPlugins;
|
|
102
107
|
private cleanupRegistrations;
|
|
103
108
|
private getSortedMiddleware;
|
|
104
109
|
private getSortedPasteInterceptors;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PluginManager.d.ts","sourceRoot":"","sources":["../../src/plugins/PluginManager.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,
|
|
1
|
+
{"version":3,"file":"PluginManager.d.ts","sourceRoot":"","sources":["../../src/plugins/PluginManager.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAE/D,OAAO,KAAK,EAEX,QAAQ,EAER,MAAM,EACN,YAAY,EAEZ,mBAAmB,EACnB,UAAU,EACV,MAAM,aAAa,CAAC;AAOrB,OAAO,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAI/D,2DAA2D;AAC3D,MAAM,WAAW,cAAc;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC1B;AAED,YAAY,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAC1E,YAAY,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAEtF,MAAM,WAAW,wBAAwB;IACxC,QAAQ,IAAI,WAAW,CAAC;IACxB,QAAQ,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI,CAAC;IACzC,YAAY,IAAI,WAAW,CAAC;IAC5B,kBAAkB,CAAC,QAAQ,EAAE,KAAK,GAAG,QAAQ,GAAG,WAAW,CAAC;IAC5D,6EAA6E;IAC7E,QAAQ,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,uEAAuE;IACvE,eAAe,CAAC,IAAI,OAAO,CAAC;IAC5B,uEAAuE;IACvE,aAAa,CAAC,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvC,wDAAwD;IACxD,WAAW,CAAC,IAAI,OAAO,CAAC;CACxB;AAED,qBAAa,aAAa;IACzB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA6B;IACrD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAmC;IAC5D,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA8B;IACvD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAyB;IACrD,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAA+B;IACjE,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA0C;IACxE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAkB;IAC3C,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAuB;IACzD,QAAQ,CAAC,cAAc,iBAAwB;IAC/C,QAAQ,CAAC,cAAc,iBAAwB;IAC/C,QAAQ,CAAC,iBAAiB,oBAA2B;IACrD,QAAQ,CAAC,mBAAmB,sBAA6B;IACzD,QAAQ,CAAC,gBAAgB,mBAA0B;IACnD,QAAQ,CAAC,eAAe,kBAAyB;IACjD,QAAQ,CAAC,uBAAuB,0BAAiC;IACjE,OAAO,CAAC,gBAAgB,CAAkC;IAC1D,OAAO,CAAC,uBAAuB,CAAwC;IACvE,OAAO,CAAC,SAAS,CAAgB;IACjC,OAAO,CAAC,gBAAgB,CAAgB;IACxC,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,oBAAoB,CAAS;IAErC;;;OAGG;IACH,eAAe,CAAC,CAAC,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI;IAOxD,wDAAwD;IACxD,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAU9B,uEAAuE;IACjE,IAAI,CAAC,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC,IAAI,CAAC;IAgD5D,6DAA6D;IAC7D,iBAAiB,CAAC,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAE,EAAE,EAAE,WAAW,GAAG,IAAI;IAYtF,wDAAwD;IACxD,kBAAkB,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE,CAAC,EAAE,WAAW,GAAG,aAAa;IAiBvE;;;OAGG;IACH,sBAAsB,CACrB,EAAE,EAAE,WAAW,EACf,KAAK,EAAE,WAAW,EAClB,aAAa,EAAE,CAAC,EAAE,EAAE,WAAW,KAAK,IAAI,GACtC,IAAI;IAmCP,gGAAgG;IAChG,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAOxC,2FAA2F;IAC3F,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAiBrC,0EAA0E;IAC1E,kBAAkB,IAAI,OAAO;IAI7B,wDAAwD;IACxD,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,GAAG,IAAI;IAa7D,2CAA2C;IAC3C,UAAU,IAAI,OAAO;IAIrB,wDAAwD;IACxD,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI;IAcpC,yCAAyC;IACzC,YAAY,IAAI,MAAM,EAAE;IAIxB,wFAAwF;IACxF,kBAAkB,IAAI,SAAS,cAAc,EAAE;IAQ/C,oDAAoD;IACpD,oBAAoB,IAAI,SAAS,qBAAqB,EAAE;IAIxD,2BAA2B;IAC3B,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAInC,8CAA8C;IAC9C,UAAU,CAAC,CAAC,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,SAAS;IAIhD,oGAAoG;IACpG,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI;IAI1E,iDAAiD;IACjD,oBAAoB,IAAI,SAAS,aAAa,EAAE;IAIhD,kDAAkD;IAC5C,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;YA8BhB,aAAa;YAYb,sBAAsB;IAUpC,OAAO,CAAC,oBAAoB;IA4C5B,OAAO,CAAC,mBAAmB;IAO3B,OAAO,CAAC,0BAA0B;IASlC,OAAO,CAAC,aAAa;IAsCrB;;;OAGG;IACH,OAAO,CAAC,YAAY;CAgEpB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{j as t,i as e,c as o}from"../chunks/Selection-DhbizDM4.mjs";import{n as c}from"../chunks/TypeBrands-Bp_Z_o5Y.mjs";import{c as n}from"../chunks/DomUtils-CznMAZZg.mjs";import{r}from"../chunks/PluginHelpers-CdPR0MuT.mjs";import{f as s}from"../chunks/ShortcutFormatting-BLKS0Gys.mjs";import{f as l,s as i}from"../chunks/Document-
|
|
1
|
+
import{j as t,i as e,c as o}from"../chunks/Selection-DhbizDM4.mjs";import{n as c}from"../chunks/TypeBrands-Bp_Z_o5Y.mjs";import{c as n}from"../chunks/DomUtils-CznMAZZg.mjs";import{r}from"../chunks/PluginHelpers-CdPR0MuT.mjs";import{f as s}from"../chunks/ShortcutFormatting-BLKS0Gys.mjs";import{f as l,s as i}from"../chunks/Document-3pNX7ear.mjs";function a(o,c){const n=o.getState();if(!t(n.selection))return!1;const r=n.selection;if(!e(r))return!1;const s=n.getBlock(r.anchor.blockId);return!(!s||"blockquote"!==s.type)&&c({state:n,block:s,blockId:r.anchor.blockId,offset:r.anchor.offset})}const u={label:"Blockquote",tooltip:t=>`Blockquote (${t})`},p=/* @__PURE__ */Object.assign({"./locales/ar.ts":()=>import("../chunks/ar-Bp3rDZky.mjs"),"./locales/de.ts":()=>import("../chunks/de-CLYtb6kD.mjs"),"./locales/es.ts":()=>import("../chunks/es-BjPsub0k.mjs"),"./locales/fr.ts":()=>import("../chunks/fr-Dx4Qqimj.mjs"),"./locales/hi.ts":()=>import("../chunks/hi-BmkfaZpg.mjs"),"./locales/pt.ts":()=>import("../chunks/pt-DwdSYJzC.mjs"),"./locales/ru.ts":()=>import("../chunks/ru-B0cRw90L.mjs"),"./locales/zh.ts":()=>import("../chunks/zh-DG2CNTUU.mjs")});async function k(t){if("en"===t)return u;const e=p[`./locales/${t}.ts`];if(!e)return u;try{return(await e()).default}catch{return u}}const m={};class h{id="blockquote";name="Blockquote";priority=35;config;locale;constructor(t){this.config={...m,...t}}async init(t){this.locale=await r(t,this.config.locale,u,k),t.registerStyleSheet("\n.notectl-content blockquote {\n\tmargin: 0;\n\tpadding: 2px 0;\n\tpadding-inline-start: 16px;\n\tborder-inline-start: 3px solid var(--notectl-border);\n\tmin-height: 1.6em;\n}\n"),this.registerNodeSpec(t),this.registerCommands(t),this.registerKeymap(t),this.registerInputRule(t),this.registerToolbarItem(t)}registerNodeSpec(t){t.registerNodeSpec({type:"blockquote",group:"block",content:{allow:["text"]},toDOM:t=>n("blockquote",t.id),toHTML:(t,e)=>`<blockquote>${e||"<br>"}</blockquote>`,parseHTML:[{tag:"blockquote"}],sanitize:{tags:["blockquote"]}})}registerCommands(t){t.registerCommand("toggleBlockquote",()=>this.toggleBlockquote(t)),t.registerCommand("setBlockquote",()=>this.setBlockType(t,c("blockquote")))}registerKeymap(t){t.registerKeymap({"Mod-Shift->":()=>t.executeCommand("toggleBlockquote")}),function(t){t.registerKeymap({ArrowDown:()=>function(t){return a(t,({state:e,block:n,blockId:r,offset:s})=>{if(s!==l(n))return!1;const a=e.getBlockOrder(),u=a.indexOf(r);if(u<a.length-1){const c=a[u+1],n=e.transaction("command").setSelection(o(c,0)).build();t.dispatch(n)}else!function(t,e){const n=t.getState(),r=n.getBlock(e);if(!r)return;const s=l(r),a=i(),u=n.transaction("command").splitBlock(e,s,a).setBlockType(a,c("paragraph")).setSelection(o(a,0)).build();t.dispatch(u)}(t,r);return!0})}(t),ArrowUp:()=>function(t){return a(t,({state:e,blockId:c,offset:n})=>{if(0!==n)return!1;const r=e.getBlockOrder(),s=r.indexOf(c);if(s>0){const c=r[s-1],n=e.getBlock(c),i=n?l(n):0,a=e.transaction("command").setSelection(o(c,i)).build();return t.dispatch(a),!0}return!1})}(t),Enter:()=>function(t){return a(t,({state:e,block:n,blockId:r})=>{if(l(n)>0)return!1;const s=e.transaction("command").setBlockType(r,c("paragraph")).setSelection(o(r,0)).build();return t.dispatch(s),!0})}(t),Backspace:()=>function(t){return a(t,({state:e,blockId:o,offset:n})=>{if(0!==n)return!1;const r=e.transaction("input").setBlockType(o,c("paragraph")).setSelection(e.selection).build();return t.dispatch(r),!0})}(t)},{priority:"context"})}(t)}registerInputRule(o){o.registerInputRule({pattern:/^> $/,handler(o,n,r,s){const l=o.selection;if(!t(l))return null;if(!e(l))return null;const i=o.getBlock(l.anchor.blockId);return i&&"paragraph"===i.type?o.transaction("input").deleteTextAt(l.anchor.blockId,r,r+2).setBlockType(l.anchor.blockId,c("blockquote")).setSelection(l).build():null}})}registerToolbarItem(e){e.registerToolbarItem({id:"blockquote",group:"block",icon:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M6 17h3l2-4V7H5v6h3zm8 0h3l2-4V7h-6v6h3z"/></svg>',label:this.locale.label,tooltip:this.locale.tooltip(s("Mod-Shift->")),command:"toggleBlockquote",isActive:e=>{if(!t(e.selection))return!1;const o=e.getBlock(e.selection.anchor.blockId);return"blockquote"===o?.type}})}toggleBlockquote(e){const o=e.getState();if(!t(o.selection))return!1;const n=o.getBlock(o.selection.anchor.blockId);return!!n&&("blockquote"===n.type?this.setBlockType(e,c("paragraph")):this.setBlockType(e,c("blockquote")))}setBlockType(e,o,c){const n=e.getState(),r=n.selection;if(!t(r))return!1;const s=n.transaction("command").setBlockType(r.anchor.blockId,o,c).setSelection(r).build();return e.dispatch(s),!0}}export{u as BLOCKQUOTE_LOCALE_EN,h as BlockquotePlugin,k as loadBlockquoteLocale};
|
|
2
2
|
//# sourceMappingURL=blockquote.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{J as a,K as i,L as o}from"../chunks/index-
|
|
1
|
+
import{J as a,K as i,L as o}from"../chunks/index-C-L4awHz.mjs";export{a as CARET_NAVIGATION_LOCALE_EN,i as CaretNavigationPlugin,o as loadCaretNavigationLocale};
|
|
2
2
|
//# sourceMappingURL=caret-navigation.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{i as t,D as e,n as o}from"../chunks/Decoration-D49mFXrH.mjs";import{f as n,i as c,s as r,k as l,q as s}from"../chunks/Document-HC8s50qJ.mjs";import{a}from"../chunks/HTMLUtils-Cxy99Ak2.mjs";import{j as i,i as d,c as u}from"../chunks/Selection-DhbizDM4.mjs";import{n as g}from"../chunks/TypeBrands-Bp_Z_o5Y.mjs";import{c as p}from"../chunks/DomUtils-CznMAZZg.mjs";import{S as h,r as k}from"../chunks/PluginHelpers-CdPR0MuT.mjs";import{f as b}from"../chunks/ShortcutFormatting-BLKS0Gys.mjs";import{a as f}from"../chunks/StyleRuntime-BmsLoEa8.mjs";import{a as m}from"../chunks/XmlPatterns-DxQXGjP8.mjs";function y(t,e){const o=t.getState();if(!i(o.selection))return!1;const n=o.selection,c=o.getBlock(n.anchor.blockId);return!(!c||"code_block"!==c.type)&&e({state:o,block:c,blockId:n.anchor.blockId,offset:n.anchor.offset})}function C(t){return y(t,({state:e,blockId:o})=>{const n=e.getBlockOrder(),c=n.indexOf(o);if(c<n.length-1){const o=n[c+1],r=e.transaction("command").setSelection(u(o,0)).build();t.dispatch(r)}else x(t,o);return!0})}function x(t,e){const o=t.getState(),c=o.getBlock(e);if(!c)return;const l=n(c),s=r(),a=o.transaction("command").splitBlock(e,l,s).setBlockType(s,g("paragraph")).setSelection(u(s,0)).build();t.dispatch(a)}function B(t,e){const o=t.getState(),c=o.selection;if(!i(c))return!1;const r=o.getBlock(c.anchor.blockId);if(!r||"code_block"===r.type)return!1;const a={language:e.defaultLanguage??"",backgroundColor:""},d=o.transaction("command");return function(t,e){if(0===n(e))return;const o=l(e);let c=0;for(const n of o)if(s(n)){if(n.text.length>0)for(const o of n.marks)t.removeMark(e.id,c,c+n.text.length,o);c+=n.text.length}else c+=1}(d,r),d.setBlockType(c.anchor.blockId,g("code_block"),a).setSelection(u(c.anchor.blockId,0)),t.dispatch(d.build()),!0}const v={label:"Code Block",tooltip:t=>t?`Code Block (${t})`:"Code Block",enteredCodeBlock:"Entered code block. Press Escape to exit.",leftCodeBlock:"Left code block.",copyCodeAria:"Copy code",escToExit:"Esc to exit",codeBlockAriaLabel:t=>`${t} code block. Press Escape to exit.`,copiedToClipboard:"Copied to clipboard"},S=/* @__PURE__ */Object.assign({"./locales/ar.ts":()=>import("../chunks/ar-DmmxE2W7.mjs"),"./locales/de.ts":()=>import("../chunks/de-CYJ6uWno.mjs"),"./locales/es.ts":()=>import("../chunks/es-Cu5_OA4X.mjs"),"./locales/fr.ts":()=>import("../chunks/fr-BrKk4SPg.mjs"),"./locales/hi.ts":()=>import("../chunks/hi-B2W8pFqK.mjs"),"./locales/pt.ts":()=>import("../chunks/pt-BX_t4luI.mjs"),"./locales/ru.ts":()=>import("../chunks/ru-D3j2x2xu.mjs"),"./locales/zh.ts":()=>import("../chunks/zh-Dt-wVrNr.mjs")});async function w(t){if("en"===t)return v;const e=S[`./locales/${t}.ts`];if(!e)return v;try{return(await e()).default}catch{return v}}const _={insertAfter:"Mod-Enter",toggle:"Mod-Shift-M"},I={defaultLanguage:"",useSpaces:!1,spaceCount:2,showCopyButton:!0},A=new h("codeBlock"),L=new h("syntaxHighlighter");function T(t,e,o,n){const c=t.getState(),r=c.getBlock(e);if(!r||"code_block"!==r.type)return;const l=c.getNodePath(e);if(!l)return;const s={...r.attrs,[o]:n},a=c.transaction("command").setNodeAttr(l,s).build();t.dispatch(a)}class M{languageMap=/* @__PURE__ */new Map;constructor(t){if(t)for(const e of t)this.registerLanguageInternal(e)}registerLanguage(t){this.registerLanguageInternal(t)}tokenize(t,e){const o=this.languageMap.get(e.toLowerCase());if(!o)return[];const n=[];let c=0;for(;c<t.length;){let e=!1;for(const r of o.patterns){const o=r.pattern.exec(t.slice(c));if(o&&o[0].length>0){n.push({from:c,to:c+o[0].length,type:r.type}),c+=o[0].length,e=!0;break}}e||c++}return n}getSupportedLanguages(){const t=/* @__PURE__ */new Set;for(const e of this.languageMap.values()){t.add(e.name);for(const o of e.aliases)t.add(o)}return[...t]}registerLanguageInternal(t){this.languageMap.set(t.name.toLowerCase(),t);for(const e of t.aliases)this.languageMap.set(e.toLowerCase(),t)}}const j={name:"json",aliases:["jsonc"],patterns:[{type:"property",pattern:/^"(?:[^"\\]|\\.)*"(?=\s*:)/},{type:"string",pattern:/^"(?:[^"\\]|\\.)*"/},{type:"number",pattern:/^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/},{type:"boolean",pattern:/^(?:true|false)\b/},{type:"null",pattern:/^null\b/},{type:"punctuation",pattern:/^[{}[\]:,]/}]},N={name:"xml",aliases:["html","xhtml","svg","xsl"],patterns:[{type:"comment",pattern:/^<!--[\s\S]*?-->/},{type:"keyword",pattern:/^<!\[CDATA\[[\s\S]*?\]\]>/},{type:"keyword",pattern:/^<\?[\s\S]*?\?>/},{type:"keyword",pattern:new RegExp(`^<\\/${m}`)},{type:"keyword",pattern:new RegExp(`^<${m}`)},{type:"punctuation",pattern:/^\/>|^>|^=/},{type:"property",pattern:new RegExp(`^${m}(?=\\s*=)`)},{type:"string",pattern:/^"[^"]*"/},{type:"string",pattern:/^'[^']*'/}]};class E{id="code-block";name="Code Block";priority=36;config;resolvedKeymap;context=null;locale;highlighter=null;tokenCache=/* @__PURE__ */new Map;constructor(t){this.config={...I,...t},this.resolvedKeymap={..._,...t?.keymap}}async init(t){this.locale=await k(t,this.config.locale,v,w),t.registerStyleSheet("\n/* Code Block — uses theme custom properties */\n.notectl-code-block {\n\tposition: relative;\n\tmargin: 8px 0;\n\tborder-radius: 6px;\n\tbackground: var(--notectl-code-block-bg);\n\tcolor: var(--notectl-code-block-color);\n\tfont-family: 'SF Mono', 'Fira Code', 'Cascadia Code', Menlo, Consolas, monospace;\n\tfont-size: 14px;\n\tline-height: 1.5;\n\toverflow: hidden;\n}\n\n.notectl-code-block__header {\n\tdisplay: flex;\n\talign-items: center;\n\tjustify-content: space-between;\n\tpadding: 6px 12px;\n\tbackground: var(--notectl-code-block-header-bg);\n\tborder-bottom: 1px solid var(--notectl-code-block-header-border);\n\tfont-size: 12px;\n\tcolor: var(--notectl-code-block-header-color);\n\tuser-select: none;\n}\n\n.notectl-code-block__language {\n\tfont-weight: 500;\n\tletter-spacing: 0.02em;\n}\n\n.notectl-code-block__copy {\n\tdisplay: inline-flex;\n\talign-items: center;\n\tjustify-content: center;\n\twidth: 24px;\n\theight: 24px;\n\tborder: none;\n\tborder-radius: 4px;\n\tbackground: transparent;\n\tcolor: var(--notectl-code-block-header-color);\n\tcursor: pointer;\n\tpadding: 0;\n\ttransition: background 0.15s, color 0.15s;\n}\n\n.notectl-code-block__copy:hover {\n\tbackground: rgba(128, 128, 128, 0.15);\n\tcolor: var(--notectl-code-block-color);\n}\n\n.notectl-code-block__copy svg {\n\tfill: currentColor;\n}\n\n.notectl-code-block__content {\n\tdisplay: block;\n\tpadding: 12px 16px;\n\twhite-space: pre-wrap;\n\tword-wrap: break-word;\n\ttab-size: 4;\n\t-moz-tab-size: 4;\n\toutline: none;\n\tmin-height: 1.5em;\n}\n\n.notectl-code-block--selected {\n\toutline: 2px solid var(--notectl-primary);\n\toutline-offset: 2px;\n}\n\n.notectl-code-block__esc-hint {\n\tdisplay: none;\n\tposition: absolute;\n\tbottom: 4px;\n\tinset-inline-end: 8px;\n\tfont-size: 11px;\n\tcolor: var(--notectl-code-block-header-color);\n\topacity: 0.5;\n\tpointer-events: none;\n\tuser-select: none;\n\tfont-family: system-ui, sans-serif;\n}\n\n.notectl-code-block--focused .notectl-code-block__esc-hint {\n\tdisplay: block;\n}\n\n/* Syntax highlighting token classes */\n.notectl-token--keyword { color: var(--notectl-code-token-keyword); }\n.notectl-token--string { color: var(--notectl-code-token-string); }\n.notectl-token--comment { color: var(--notectl-code-token-comment); font-style: italic; }\n.notectl-token--number { color: var(--notectl-code-token-number); }\n.notectl-token--function { color: var(--notectl-code-token-function); }\n.notectl-token--operator { color: var(--notectl-code-token-operator); }\n.notectl-token--punctuation { color: var(--notectl-code-token-punctuation); }\n.notectl-token--boolean { color: var(--notectl-code-token-boolean); }\n.notectl-token--null { color: var(--notectl-code-token-null); }\n.notectl-token--property { color: var(--notectl-code-token-property); }\n"),this.context=t,this.initHighlighter(),this.registerNodeSpec(t),this.registerNodeView(t),function(t,e){t.registerCommand("toggleCodeBlock",()=>function(t,e){const o=t.getState();if(!i(o.selection))return!1;const n=o.getBlock(o.selection.anchor.blockId);if(!n)return!1;if("code_block"===n.type){const e=o.transaction("command").setBlockType(o.selection.anchor.blockId,g("paragraph")).setSelection(o.selection).build();return t.dispatch(e),!0}return B(t,e)}(t,e)),t.registerCommand("insertCodeBlock",()=>B(t,e)),t.registerCommand("setCodeBlockLanguage",()=>!1),t.registerCommand("setCodeBlockBackground",()=>!1),t.registerCommand("exitCodeBlock",()=>C(t))}(t,this.config),function(t,e,o){const l={Enter:()=>function(t){return y(t,({state:e,block:o,blockId:n,offset:l})=>{if(!d(e.selection))return!1;const s=c(o);if(s.endsWith("\n")&&l===s.length)return function(t,e,o){const n=t.getState(),c=o.length-1,l=r(),s=n.transaction("input").deleteTextAt(e,c,o.length).splitBlock(e,c,l).setBlockType(l,g("paragraph")).setSelection(u(l,0)).build();return t.dispatch(s),!0}(t,n,s);const a=e.transaction("input").insertText(n,l,"\n",[]).setSelection(u(n,l+1)).build();return t.dispatch(a),!0})}(t),Backspace:()=>function(t){return y(t,({state:e,blockId:o,offset:n})=>{if(!d(e.selection))return!1;if(0!==n)return!1;const c=e.transaction("input").setBlockType(o,g("paragraph")).setSelection(e.selection).build();return t.dispatch(c),!0})}(t),Tab:()=>function(t,e){return y(t,({state:o,blockId:n,offset:c})=>{const r=e.useSpaces?" ".repeat(e.spaceCount??2):"\t",l=o.transaction("input").insertText(n,c,r,[]).setSelection(u(n,c+r.length)).build();return t.dispatch(l),!0})}(t,e),"Shift-Tab":()=>function(t,e){return y(t,({state:o,block:n,blockId:r,offset:l})=>{const s=c(n),a=s.lastIndexOf("\n",l-1)+1;if(e.useSpaces){const n=e.spaceCount??2;if(s.slice(a,a+n)===" ".repeat(n)){const e=o.transaction("input").deleteTextAt(r,a,a+n).setSelection(u(r,Math.max(a,l-n))).build();return t.dispatch(e),!0}}else if("\t"===s[a]){const e=o.transaction("input").deleteTextAt(r,a,a+1).setSelection(u(r,Math.max(a,l-1))).build();return t.dispatch(e),!0}return!0})}(t,e),Escape:()=>C(t),ArrowDown:()=>function(t){return y(t,({state:e,block:o,blockId:n,offset:r})=>{if(!d(e.selection))return!1;if(-1!==c(o).indexOf("\n",r))return!1;const l=e.getBlockOrder(),s=l.indexOf(n);if(s<l.length-1){const o=l[s+1],n=e.transaction("command").setSelection(u(o,0)).build();t.dispatch(n)}else x(t,n);return!0})}(t),ArrowUp:()=>function(t){return y(t,({state:e,block:o,blockId:r,offset:l})=>{if(!d(e.selection))return!1;const s=c(o).indexOf("\n");if(-1!==s&&l>s)return!1;const a=e.getBlockOrder(),i=a.indexOf(r);if(i>0){const o=a[i-1],c=e.getBlock(o),r=c?n(c):0,l=e.transaction("command").setSelection(u(o,r)).build();return t.dispatch(l),!0}return!1})}(t),ArrowRight:()=>function(t){return y(t,({state:e,block:o,blockId:n,offset:r})=>{if(!d(e.selection))return!1;if(r!==c(o).length)return!1;const l=e.getBlockOrder(),s=l.indexOf(n);if(s<l.length-1){const o=l[s+1],n=e.transaction("command").setSelection(u(o,0)).build();t.dispatch(n)}else x(t,n);return!0})}(t),ArrowLeft:()=>function(t){return y(t,({state:e,blockId:o,offset:c})=>{if(!d(e.selection))return!1;if(0!==c)return!1;const r=e.getBlockOrder(),l=r.indexOf(o);if(l>0){const o=r[l-1],c=e.getBlock(o),s=c?n(c):0,a=e.transaction("command").setSelection(u(o,s)).build();return t.dispatch(a),!0}return!1})}(t)},{insertAfter:s,toggle:a}=o;s&&(l[s]=()=>function(t){return y(t,({blockId:e})=>(x(t,e),!0))}(t)),a&&(l[a]=()=>t.executeCommand("toggleCodeBlock")),t.registerKeymap(l,{priority:"context"})}(t,this.config,this.resolvedKeymap),this.registerInputRule(t),this.registerToolbarItem(t),this.registerMiddleware(t),function(t,e,o){t.registerService(A,{setLanguage(e,o){T(t,e,"language",o)},getLanguage(t){const e=o();if(!e)return"";const n=e.getState().getBlock(t);return n&&"code_block"===n.type?n.attrs?.language??"":""},setBackground(e,o){T(t,e,"backgroundColor",o)},getBackground(t){const e=o();if(!e)return"";const n=e.getState().getBlock(t);return n&&"code_block"===n.type?n.attrs?.backgroundColor??"":""},isCodeBlock(t){const e=o();if(!e)return!1;const n=e.getState().getBlock(t);return"code_block"===n?.type},getSupportedLanguages:()=>e.highlighter?e.highlighter.getSupportedLanguages():[]})}(t,this.config,()=>this.context),this.registerSyntaxHighlighterService(t),this.patchTableCellContent(t)}destroy(){this.context=null,this.highlighter=null,this.tokenCache.clear()}onStateChange(t,e,o){if(!this.context)return;const n=i(t.selection)?t.selection.anchor.blockId:null,c=i(e.selection)?e.selection.anchor.blockId:null,r=n?t.getBlock(n):void 0,l=c?e.getBlock(c):void 0,s="code_block"===r?.type,a="code_block"===l?.type;!s&&a?this.context.announce(this.locale.enteredCodeBlock):s&&!a&&this.context.announce(this.locale.leftCodeBlock)}decorations(n){const r=[],l=this.getFocusedCodeBlockId(n);if(l&&r.push(o(l,{class:"notectl-code-block--focused"})),this.highlighter){const e=/* @__PURE__ */new Set;for(const o of n.getBlockOrder()){const l=n.getBlock(o);if(!l||"code_block"!==l.type)continue;const s=l.attrs?.language??"";if(!s)continue;const a=c(l);if(!a)continue;e.add(o);const i=this.getCachedTokens(o,a,s);for(const e of i)r.push(t(o,e.from,e.to,{class:`notectl-token--${e.type}`}))}for(const t of this.tokenCache.keys())e.has(t)||this.tokenCache.delete(t)}return 0===r.length?e.empty:e.create(r)}registerNodeSpec(t){t.registerNodeSpec({type:"code_block",group:"block",content:{allow:["text"]},selectable:!0,attrs:{language:{default:""},backgroundColor:{default:""}},toDOM(t){const e=p("pre",t.id);e.className="notectl-code-block",e.setAttribute("dir","ltr");const o=document.createElement("code");return o.className="notectl-code-block__content",e.appendChild(o),e},toHTML(t,e,o){const n=a(t.attrs?.language??""),c=a(t.attrs?.backgroundColor??""),r=n?` class="language-${n}"`:"";return`<pre dir="ltr"${c?o?.styleAttr(`background-color: ${c}`)??` style="background-color: ${c}"`:""}><code${r}>${e||""}</code></pre>`},parseHTML:[{tag:"pre",getAttrs(t){const e=t.querySelector("code"),o=e?.className.match(/language-(\S+)/)?.[1]??"";return{language:(e?.getAttribute("data-language")??"")||o}}}],sanitize:{tags:["pre","code"],attrs:["data-language","class","style"]}})}registerNodeView(t){t.registerNodeView("code_block",function(t,e=v){return(o,n,r)=>{const l=document.createElement("pre");l.className="notectl-code-block",l.setAttribute("data-block-id",o.id),l.setAttribute("dir","ltr"),l.setAttribute("role","group"),l.setAttribute("aria-roledescription","code block");const s=document.createElement("div");s.className="notectl-code-block__header",s.setAttribute("contenteditable","false");const a=document.createElement("span");a.className="notectl-code-block__language";let i=null;!1!==t.showCopyButton&&(i=document.createElement("button"),i.className="notectl-code-block__copy",i.setAttribute("aria-label",e.copyCodeAria),i.setAttribute("data-notectl-no-print",""),i.type="button",i.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="14" height="14"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg>');const d=document.createElement("span");d.className="notectl-sr-only",d.setAttribute("aria-live","assertive"),d.setAttribute("aria-atomic","true"),s.appendChild(a),i&&s.appendChild(i),s.appendChild(d);const u=document.createElement("code");u.className="notectl-code-block__content";const g=document.createElement("div");g.className="notectl-code-block__esc-hint",g.setAttribute("contenteditable","false"),g.setAttribute("aria-hidden","true"),g.setAttribute("data-notectl-no-print",""),g.textContent=e.escToExit,l.appendChild(s),l.appendChild(u),l.appendChild(g),t.background&&f(l,"--notectl-code-block-bg",t.background),t.headerBackground&&f(l,"--notectl-code-block-header-bg",t.headerBackground),t.textColor&&f(l,"--notectl-code-block-color",t.textColor),t.headerColor&&f(l,"--notectl-code-block-header-color",t.headerColor);let p=o.id;function h(t){const o=t.attrs?.language??"",n=o||"plain";a.textContent=n,l.setAttribute("aria-label",e.codeBlockAriaLabel(n)),o?u.setAttribute("data-language",o):u.removeAttribute("data-language");const c=t.attrs?.backgroundColor??"";f(l,"backgroundColor",c||"")}return h(o),i&&i.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation();const o=n().getBlock(p);if(!o)return;const r=c(o);navigator.clipboard.writeText(r),d.textContent=e.copiedToClipboard,setTimeout(()=>{d.textContent=""},1e3)}),{dom:l,contentDOM:u,update:t=>"code_block"===t.type&&(p=t.id,l.setAttribute("data-block-id",t.id),h(t),!0),selectNode(){l.classList.add("notectl-code-block--selected")},deselectNode(){l.classList.remove("notectl-code-block--selected")},destroy(){}}}}(this.config,this.locale))}registerInputRule(t){t.registerInputRule({pattern:/^```(\w*) $/,handler:(t,e,o,n)=>{const c=t.selection;if(!i(c))return null;if(!d(c))return null;const r=t.getBlock(c.anchor.blockId);if(!r||"paragraph"!==r.type)return null;const l={language:e[1]??"",backgroundColor:""};return t.transaction("input").deleteTextAt(c.anchor.blockId,o,o+e[0].length).setBlockType(c.anchor.blockId,g("code_block"),l).setSelection(u(c.anchor.blockId,0)).build()}})}registerToolbarItem(t){t.registerToolbarItem({id:"code_block",group:"block",icon:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.4 16.6L4.8 12l4.6-4.6L8 6l-6 6 6 6 1.4-1.4zm5.2 0l4.6-4.6-4.6-4.6L16 6l6 6-6 6-1.4-1.4z"/></svg>',label:this.locale.label,tooltip:this.locale.tooltip(this.resolvedKeymap.toggle?b(this.resolvedKeymap.toggle):void 0),command:"toggleCodeBlock",isActive:t=>{if(!i(t.selection))return!1;const e=t.getBlock(t.selection.anchor.blockId);return"code_block"===e?.type}})}registerMiddleware(t){t.registerMiddleware((t,e,o)=>{if(!t.steps.some(t=>{if("addMark"!==t.type)return!1;const o=e.getBlock(t.blockId);return"code_block"===o?.type}))return void o(t);const n=t.steps.filter(t=>{if("addMark"!==t.type)return!0;const o=e.getBlock(t.blockId);return"code_block"!==o?.type});o({...t,steps:n})},{name:"code-block:mark-guard",priority:50})}patchTableCellContent(t){const e=t.getSchemaRegistry(),o=e.getNodeSpec("table_cell");if(!o?.content)return;const n=o.content.allow??[];n.includes("code_block")||(e.removeNodeSpec("table_cell"),e.registerNodeSpec({...o,content:{...o.content,allow:[...n,"code_block"]}}))}initHighlighter(){this.config.highlighter?this.highlighter=this.config.highlighter:this.highlighter=new M([j,N])}registerSyntaxHighlighterService(t){const e=this.highlighter;e&&t.registerService(L,{registerLanguage:t=>{e.registerLanguage?.(t),this.tokenCache.clear()},getSupportedLanguages:()=>e.getSupportedLanguages(),tokenize:(t,o)=>e.tokenize(t,o)})}getCachedTokens(t,e,o){const n=this.tokenCache.get(t);if(n&&n.text===e&&n.language===o)return n.tokens;const c=this.highlighter?.tokenize(e,o)??[];return this.tokenCache.set(t,{text:e,language:o,tokens:c}),c}getFocusedCodeBlockId(t){if(!i(t.selection))return null;const e=t.selection.anchor.blockId,o=t.getBlock(e);return"code_block"===o?.type?e:null}}export{v as CODE_BLOCK_LOCALE_EN,A as CODE_BLOCK_SERVICE_KEY,E as CodeBlockPlugin,j as JSON_LANGUAGE,M as RegexTokenizer,L as SYNTAX_HIGHLIGHTER_SERVICE_KEY,N as XML_LANGUAGE,w as loadCodeBlockLocale};
|
|
1
|
+
import{i as t,D as e,n as o}from"../chunks/Decoration-D49mFXrH.mjs";import{f as n,i as c,s as r,k as l,q as s}from"../chunks/Document-3pNX7ear.mjs";import{a}from"../chunks/HTMLUtils-Cxy99Ak2.mjs";import{j as i,i as d,c as u}from"../chunks/Selection-DhbizDM4.mjs";import{n as g}from"../chunks/TypeBrands-Bp_Z_o5Y.mjs";import{c as p}from"../chunks/DomUtils-CznMAZZg.mjs";import{S as h,r as k}from"../chunks/PluginHelpers-CdPR0MuT.mjs";import{f as b}from"../chunks/ShortcutFormatting-BLKS0Gys.mjs";import{a as f}from"../chunks/StyleRuntime-BmsLoEa8.mjs";import{a as m}from"../chunks/XmlPatterns-DxQXGjP8.mjs";function y(t,e){const o=t.getState();if(!i(o.selection))return!1;const n=o.selection,c=o.getBlock(n.anchor.blockId);return!(!c||"code_block"!==c.type)&&e({state:o,block:c,blockId:n.anchor.blockId,offset:n.anchor.offset})}function C(t){return y(t,({state:e,blockId:o})=>{const n=e.getBlockOrder(),c=n.indexOf(o);if(c<n.length-1){const o=n[c+1],r=e.transaction("command").setSelection(u(o,0)).build();t.dispatch(r)}else x(t,o);return!0})}function x(t,e){const o=t.getState(),c=o.getBlock(e);if(!c)return;const l=n(c),s=r(),a=o.transaction("command").splitBlock(e,l,s).setBlockType(s,g("paragraph")).setSelection(u(s,0)).build();t.dispatch(a)}function B(t,e){const o=t.getState(),c=o.selection;if(!i(c))return!1;const r=o.getBlock(c.anchor.blockId);if(!r||"code_block"===r.type)return!1;const a={language:e.defaultLanguage??"",backgroundColor:""},d=o.transaction("command");return function(t,e){if(0===n(e))return;const o=l(e);let c=0;for(const n of o)if(s(n)){if(n.text.length>0)for(const o of n.marks)t.removeMark(e.id,c,c+n.text.length,o);c+=n.text.length}else c+=1}(d,r),d.setBlockType(c.anchor.blockId,g("code_block"),a).setSelection(u(c.anchor.blockId,0)),t.dispatch(d.build()),!0}const v={label:"Code Block",tooltip:t=>t?`Code Block (${t})`:"Code Block",enteredCodeBlock:"Entered code block. Press Escape to exit.",leftCodeBlock:"Left code block.",copyCodeAria:"Copy code",escToExit:"Esc to exit",codeBlockAriaLabel:t=>`${t} code block. Press Escape to exit.`,copiedToClipboard:"Copied to clipboard"},S=/* @__PURE__ */Object.assign({"./locales/ar.ts":()=>import("../chunks/ar-DmmxE2W7.mjs"),"./locales/de.ts":()=>import("../chunks/de-CYJ6uWno.mjs"),"./locales/es.ts":()=>import("../chunks/es-Cu5_OA4X.mjs"),"./locales/fr.ts":()=>import("../chunks/fr-BrKk4SPg.mjs"),"./locales/hi.ts":()=>import("../chunks/hi-B2W8pFqK.mjs"),"./locales/pt.ts":()=>import("../chunks/pt-BX_t4luI.mjs"),"./locales/ru.ts":()=>import("../chunks/ru-D3j2x2xu.mjs"),"./locales/zh.ts":()=>import("../chunks/zh-Dt-wVrNr.mjs")});async function w(t){if("en"===t)return v;const e=S[`./locales/${t}.ts`];if(!e)return v;try{return(await e()).default}catch{return v}}const _={insertAfter:"Mod-Enter",toggle:"Mod-Shift-M"},I={defaultLanguage:"",useSpaces:!1,spaceCount:2,showCopyButton:!0},A=new h("codeBlock"),L=new h("syntaxHighlighter");function T(t,e,o,n){const c=t.getState(),r=c.getBlock(e);if(!r||"code_block"!==r.type)return;const l=c.getNodePath(e);if(!l)return;const s={...r.attrs,[o]:n},a=c.transaction("command").setNodeAttr(l,s).build();t.dispatch(a)}class M{languageMap=/* @__PURE__ */new Map;constructor(t){if(t)for(const e of t)this.registerLanguageInternal(e)}registerLanguage(t){this.registerLanguageInternal(t)}tokenize(t,e){const o=this.languageMap.get(e.toLowerCase());if(!o)return[];const n=[];let c=0;for(;c<t.length;){let e=!1;for(const r of o.patterns){const o=r.pattern.exec(t.slice(c));if(o&&o[0].length>0){n.push({from:c,to:c+o[0].length,type:r.type}),c+=o[0].length,e=!0;break}}e||c++}return n}getSupportedLanguages(){const t=/* @__PURE__ */new Set;for(const e of this.languageMap.values()){t.add(e.name);for(const o of e.aliases)t.add(o)}return[...t]}registerLanguageInternal(t){this.languageMap.set(t.name.toLowerCase(),t);for(const e of t.aliases)this.languageMap.set(e.toLowerCase(),t)}}const j={name:"json",aliases:["jsonc"],patterns:[{type:"property",pattern:/^"(?:[^"\\]|\\.)*"(?=\s*:)/},{type:"string",pattern:/^"(?:[^"\\]|\\.)*"/},{type:"number",pattern:/^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/},{type:"boolean",pattern:/^(?:true|false)\b/},{type:"null",pattern:/^null\b/},{type:"punctuation",pattern:/^[{}[\]:,]/}]},N={name:"xml",aliases:["html","xhtml","svg","xsl"],patterns:[{type:"comment",pattern:/^<!--[\s\S]*?-->/},{type:"keyword",pattern:/^<!\[CDATA\[[\s\S]*?\]\]>/},{type:"keyword",pattern:/^<\?[\s\S]*?\?>/},{type:"keyword",pattern:new RegExp(`^<\\/${m}`)},{type:"keyword",pattern:new RegExp(`^<${m}`)},{type:"punctuation",pattern:/^\/>|^>|^=/},{type:"property",pattern:new RegExp(`^${m}(?=\\s*=)`)},{type:"string",pattern:/^"[^"]*"/},{type:"string",pattern:/^'[^']*'/}]};class E{id="code-block";name="Code Block";priority=36;config;resolvedKeymap;context=null;locale;highlighter=null;tokenCache=/* @__PURE__ */new Map;constructor(t){this.config={...I,...t},this.resolvedKeymap={..._,...t?.keymap}}async init(t){this.locale=await k(t,this.config.locale,v,w),t.registerStyleSheet("\n/* Code Block — uses theme custom properties */\n.notectl-code-block {\n\tposition: relative;\n\tmargin: 8px 0;\n\tborder-radius: 6px;\n\tbackground: var(--notectl-code-block-bg);\n\tcolor: var(--notectl-code-block-color);\n\tfont-family: 'SF Mono', 'Fira Code', 'Cascadia Code', Menlo, Consolas, monospace;\n\tfont-size: 14px;\n\tline-height: 1.5;\n\toverflow: hidden;\n}\n\n.notectl-code-block__header {\n\tdisplay: flex;\n\talign-items: center;\n\tjustify-content: space-between;\n\tpadding: 6px 12px;\n\tbackground: var(--notectl-code-block-header-bg);\n\tborder-bottom: 1px solid var(--notectl-code-block-header-border);\n\tfont-size: 12px;\n\tcolor: var(--notectl-code-block-header-color);\n\tuser-select: none;\n}\n\n.notectl-code-block__language {\n\tfont-weight: 500;\n\tletter-spacing: 0.02em;\n}\n\n.notectl-code-block__copy {\n\tdisplay: inline-flex;\n\talign-items: center;\n\tjustify-content: center;\n\twidth: 24px;\n\theight: 24px;\n\tborder: none;\n\tborder-radius: 4px;\n\tbackground: transparent;\n\tcolor: var(--notectl-code-block-header-color);\n\tcursor: pointer;\n\tpadding: 0;\n\ttransition: background 0.15s, color 0.15s;\n}\n\n.notectl-code-block__copy:hover {\n\tbackground: rgba(128, 128, 128, 0.15);\n\tcolor: var(--notectl-code-block-color);\n}\n\n.notectl-code-block__copy svg {\n\tfill: currentColor;\n}\n\n.notectl-code-block__content {\n\tdisplay: block;\n\tpadding: 12px 16px;\n\twhite-space: pre-wrap;\n\tword-wrap: break-word;\n\ttab-size: 4;\n\t-moz-tab-size: 4;\n\toutline: none;\n\tmin-height: 1.5em;\n}\n\n.notectl-code-block--selected {\n\toutline: 2px solid var(--notectl-primary);\n\toutline-offset: 2px;\n}\n\n.notectl-code-block__esc-hint {\n\tdisplay: none;\n\tposition: absolute;\n\tbottom: 4px;\n\tinset-inline-end: 8px;\n\tfont-size: 11px;\n\tcolor: var(--notectl-code-block-header-color);\n\topacity: 0.5;\n\tpointer-events: none;\n\tuser-select: none;\n\tfont-family: system-ui, sans-serif;\n}\n\n.notectl-code-block--focused .notectl-code-block__esc-hint {\n\tdisplay: block;\n}\n\n/* Syntax highlighting token classes */\n.notectl-token--keyword { color: var(--notectl-code-token-keyword); }\n.notectl-token--string { color: var(--notectl-code-token-string); }\n.notectl-token--comment { color: var(--notectl-code-token-comment); font-style: italic; }\n.notectl-token--number { color: var(--notectl-code-token-number); }\n.notectl-token--function { color: var(--notectl-code-token-function); }\n.notectl-token--operator { color: var(--notectl-code-token-operator); }\n.notectl-token--punctuation { color: var(--notectl-code-token-punctuation); }\n.notectl-token--boolean { color: var(--notectl-code-token-boolean); }\n.notectl-token--null { color: var(--notectl-code-token-null); }\n.notectl-token--property { color: var(--notectl-code-token-property); }\n"),this.context=t,this.initHighlighter(),this.registerNodeSpec(t),this.registerNodeView(t),function(t,e){t.registerCommand("toggleCodeBlock",()=>function(t,e){const o=t.getState();if(!i(o.selection))return!1;const n=o.getBlock(o.selection.anchor.blockId);if(!n)return!1;if("code_block"===n.type){const e=o.transaction("command").setBlockType(o.selection.anchor.blockId,g("paragraph")).setSelection(o.selection).build();return t.dispatch(e),!0}return B(t,e)}(t,e)),t.registerCommand("insertCodeBlock",()=>B(t,e)),t.registerCommand("setCodeBlockLanguage",()=>!1),t.registerCommand("setCodeBlockBackground",()=>!1),t.registerCommand("exitCodeBlock",()=>C(t))}(t,this.config),function(t,e,o){const l={Enter:()=>function(t){return y(t,({state:e,block:o,blockId:n,offset:l})=>{if(!d(e.selection))return!1;const s=c(o);if(s.endsWith("\n")&&l===s.length)return function(t,e,o){const n=t.getState(),c=o.length-1,l=r(),s=n.transaction("input").deleteTextAt(e,c,o.length).splitBlock(e,c,l).setBlockType(l,g("paragraph")).setSelection(u(l,0)).build();return t.dispatch(s),!0}(t,n,s);const a=e.transaction("input").insertText(n,l,"\n",[]).setSelection(u(n,l+1)).build();return t.dispatch(a),!0})}(t),Backspace:()=>function(t){return y(t,({state:e,blockId:o,offset:n})=>{if(!d(e.selection))return!1;if(0!==n)return!1;const c=e.transaction("input").setBlockType(o,g("paragraph")).setSelection(e.selection).build();return t.dispatch(c),!0})}(t),Tab:()=>function(t,e){return y(t,({state:o,blockId:n,offset:c})=>{const r=e.useSpaces?" ".repeat(e.spaceCount??2):"\t",l=o.transaction("input").insertText(n,c,r,[]).setSelection(u(n,c+r.length)).build();return t.dispatch(l),!0})}(t,e),"Shift-Tab":()=>function(t,e){return y(t,({state:o,block:n,blockId:r,offset:l})=>{const s=c(n),a=s.lastIndexOf("\n",l-1)+1;if(e.useSpaces){const n=e.spaceCount??2;if(s.slice(a,a+n)===" ".repeat(n)){const e=o.transaction("input").deleteTextAt(r,a,a+n).setSelection(u(r,Math.max(a,l-n))).build();return t.dispatch(e),!0}}else if("\t"===s[a]){const e=o.transaction("input").deleteTextAt(r,a,a+1).setSelection(u(r,Math.max(a,l-1))).build();return t.dispatch(e),!0}return!0})}(t,e),Escape:()=>C(t),ArrowDown:()=>function(t){return y(t,({state:e,block:o,blockId:n,offset:r})=>{if(!d(e.selection))return!1;if(-1!==c(o).indexOf("\n",r))return!1;const l=e.getBlockOrder(),s=l.indexOf(n);if(s<l.length-1){const o=l[s+1],n=e.transaction("command").setSelection(u(o,0)).build();t.dispatch(n)}else x(t,n);return!0})}(t),ArrowUp:()=>function(t){return y(t,({state:e,block:o,blockId:r,offset:l})=>{if(!d(e.selection))return!1;const s=c(o).indexOf("\n");if(-1!==s&&l>s)return!1;const a=e.getBlockOrder(),i=a.indexOf(r);if(i>0){const o=a[i-1],c=e.getBlock(o),r=c?n(c):0,l=e.transaction("command").setSelection(u(o,r)).build();return t.dispatch(l),!0}return!1})}(t),ArrowRight:()=>function(t){return y(t,({state:e,block:o,blockId:n,offset:r})=>{if(!d(e.selection))return!1;if(r!==c(o).length)return!1;const l=e.getBlockOrder(),s=l.indexOf(n);if(s<l.length-1){const o=l[s+1],n=e.transaction("command").setSelection(u(o,0)).build();t.dispatch(n)}else x(t,n);return!0})}(t),ArrowLeft:()=>function(t){return y(t,({state:e,blockId:o,offset:c})=>{if(!d(e.selection))return!1;if(0!==c)return!1;const r=e.getBlockOrder(),l=r.indexOf(o);if(l>0){const o=r[l-1],c=e.getBlock(o),s=c?n(c):0,a=e.transaction("command").setSelection(u(o,s)).build();return t.dispatch(a),!0}return!1})}(t)},{insertAfter:s,toggle:a}=o;s&&(l[s]=()=>function(t){return y(t,({blockId:e})=>(x(t,e),!0))}(t)),a&&(l[a]=()=>t.executeCommand("toggleCodeBlock")),t.registerKeymap(l,{priority:"context"})}(t,this.config,this.resolvedKeymap),this.registerInputRule(t),this.registerToolbarItem(t),this.registerMiddleware(t),function(t,e,o){t.registerService(A,{setLanguage(e,o){T(t,e,"language",o)},getLanguage(t){const e=o();if(!e)return"";const n=e.getState().getBlock(t);return n&&"code_block"===n.type?n.attrs?.language??"":""},setBackground(e,o){T(t,e,"backgroundColor",o)},getBackground(t){const e=o();if(!e)return"";const n=e.getState().getBlock(t);return n&&"code_block"===n.type?n.attrs?.backgroundColor??"":""},isCodeBlock(t){const e=o();if(!e)return!1;const n=e.getState().getBlock(t);return"code_block"===n?.type},getSupportedLanguages:()=>e.highlighter?e.highlighter.getSupportedLanguages():[]})}(t,this.config,()=>this.context),this.registerSyntaxHighlighterService(t),this.patchTableCellContent(t)}destroy(){this.context=null,this.highlighter=null,this.tokenCache.clear()}onStateChange(t,e,o){if(!this.context)return;const n=i(t.selection)?t.selection.anchor.blockId:null,c=i(e.selection)?e.selection.anchor.blockId:null,r=n?t.getBlock(n):void 0,l=c?e.getBlock(c):void 0,s="code_block"===r?.type,a="code_block"===l?.type;!s&&a?this.context.announce(this.locale.enteredCodeBlock):s&&!a&&this.context.announce(this.locale.leftCodeBlock)}decorations(n){const r=[],l=this.getFocusedCodeBlockId(n);if(l&&r.push(o(l,{class:"notectl-code-block--focused"})),this.highlighter){const e=/* @__PURE__ */new Set;for(const o of n.getBlockOrder()){const l=n.getBlock(o);if(!l||"code_block"!==l.type)continue;const s=l.attrs?.language??"";if(!s)continue;const a=c(l);if(!a)continue;e.add(o);const i=this.getCachedTokens(o,a,s);for(const e of i)r.push(t(o,e.from,e.to,{class:`notectl-token--${e.type}`}))}for(const t of this.tokenCache.keys())e.has(t)||this.tokenCache.delete(t)}return 0===r.length?e.empty:e.create(r)}registerNodeSpec(t){t.registerNodeSpec({type:"code_block",group:"block",content:{allow:["text"]},selectable:!0,attrs:{language:{default:""},backgroundColor:{default:""}},toDOM(t){const e=p("pre",t.id);e.className="notectl-code-block",e.setAttribute("dir","ltr");const o=document.createElement("code");return o.className="notectl-code-block__content",e.appendChild(o),e},toHTML(t,e,o){const n=a(t.attrs?.language??""),c=a(t.attrs?.backgroundColor??""),r=n?` class="language-${n}"`:"";return`<pre dir="ltr"${c?o?.styleAttr(`background-color: ${c}`)??` style="background-color: ${c}"`:""}><code${r}>${e||""}</code></pre>`},parseHTML:[{tag:"pre",getAttrs(t){const e=t.querySelector("code"),o=e?.className.match(/language-(\S+)/)?.[1]??"";return{language:(e?.getAttribute("data-language")??"")||o}}}],sanitize:{tags:["pre","code"],attrs:["data-language","class","style"]}})}registerNodeView(t){t.registerNodeView("code_block",function(t,e=v){return(o,n,r)=>{const l=document.createElement("pre");l.className="notectl-code-block",l.setAttribute("data-block-id",o.id),l.setAttribute("dir","ltr"),l.setAttribute("role","group"),l.setAttribute("aria-roledescription","code block");const s=document.createElement("div");s.className="notectl-code-block__header",s.setAttribute("contenteditable","false");const a=document.createElement("span");a.className="notectl-code-block__language";let i=null;!1!==t.showCopyButton&&(i=document.createElement("button"),i.className="notectl-code-block__copy",i.setAttribute("aria-label",e.copyCodeAria),i.setAttribute("data-notectl-no-print",""),i.type="button",i.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="14" height="14"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg>');const d=document.createElement("span");d.className="notectl-sr-only",d.setAttribute("aria-live","assertive"),d.setAttribute("aria-atomic","true"),s.appendChild(a),i&&s.appendChild(i),s.appendChild(d);const u=document.createElement("code");u.className="notectl-code-block__content";const g=document.createElement("div");g.className="notectl-code-block__esc-hint",g.setAttribute("contenteditable","false"),g.setAttribute("aria-hidden","true"),g.setAttribute("data-notectl-no-print",""),g.textContent=e.escToExit,l.appendChild(s),l.appendChild(u),l.appendChild(g),t.background&&f(l,"--notectl-code-block-bg",t.background),t.headerBackground&&f(l,"--notectl-code-block-header-bg",t.headerBackground),t.textColor&&f(l,"--notectl-code-block-color",t.textColor),t.headerColor&&f(l,"--notectl-code-block-header-color",t.headerColor);let p=o.id;function h(t){const o=t.attrs?.language??"",n=o||"plain";a.textContent=n,l.setAttribute("aria-label",e.codeBlockAriaLabel(n)),o?u.setAttribute("data-language",o):u.removeAttribute("data-language");const c=t.attrs?.backgroundColor??"";f(l,"backgroundColor",c||"")}return h(o),i&&i.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation();const o=n().getBlock(p);if(!o)return;const r=c(o);navigator.clipboard.writeText(r),d.textContent=e.copiedToClipboard,setTimeout(()=>{d.textContent=""},1e3)}),{dom:l,contentDOM:u,update:t=>"code_block"===t.type&&(p=t.id,l.setAttribute("data-block-id",t.id),h(t),!0),selectNode(){l.classList.add("notectl-code-block--selected")},deselectNode(){l.classList.remove("notectl-code-block--selected")},destroy(){}}}}(this.config,this.locale))}registerInputRule(t){t.registerInputRule({pattern:/^```(\w*) $/,handler:(t,e,o,n)=>{const c=t.selection;if(!i(c))return null;if(!d(c))return null;const r=t.getBlock(c.anchor.blockId);if(!r||"paragraph"!==r.type)return null;const l={language:e[1]??"",backgroundColor:""};return t.transaction("input").deleteTextAt(c.anchor.blockId,o,o+e[0].length).setBlockType(c.anchor.blockId,g("code_block"),l).setSelection(u(c.anchor.blockId,0)).build()}})}registerToolbarItem(t){t.registerToolbarItem({id:"code_block",group:"block",icon:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.4 16.6L4.8 12l4.6-4.6L8 6l-6 6 6 6 1.4-1.4zm5.2 0l4.6-4.6-4.6-4.6L16 6l6 6-6 6-1.4-1.4z"/></svg>',label:this.locale.label,tooltip:this.locale.tooltip(this.resolvedKeymap.toggle?b(this.resolvedKeymap.toggle):void 0),command:"toggleCodeBlock",isActive:t=>{if(!i(t.selection))return!1;const e=t.getBlock(t.selection.anchor.blockId);return"code_block"===e?.type}})}registerMiddleware(t){t.registerMiddleware((t,e,o)=>{if(!t.steps.some(t=>{if("addMark"!==t.type)return!1;const o=e.getBlock(t.blockId);return"code_block"===o?.type}))return void o(t);const n=t.steps.filter(t=>{if("addMark"!==t.type)return!0;const o=e.getBlock(t.blockId);return"code_block"!==o?.type});o({...t,steps:n})},{name:"code-block:mark-guard",priority:50})}patchTableCellContent(t){const e=t.getSchemaRegistry(),o=e.getNodeSpec("table_cell");if(!o?.content)return;const n=o.content.allow??[];n.includes("code_block")||(e.removeNodeSpec("table_cell"),e.registerNodeSpec({...o,content:{...o.content,allow:[...n,"code_block"]}}))}initHighlighter(){this.config.highlighter?this.highlighter=this.config.highlighter:this.highlighter=new M([j,N])}registerSyntaxHighlighterService(t){const e=this.highlighter;e&&t.registerService(L,{registerLanguage:t=>{e.registerLanguage?.(t),this.tokenCache.clear()},getSupportedLanguages:()=>e.getSupportedLanguages(),tokenize:(t,o)=>e.tokenize(t,o)})}getCachedTokens(t,e,o){const n=this.tokenCache.get(t);if(n&&n.text===e&&n.language===o)return n.tokens;const c=this.highlighter?.tokenize(e,o)??[];return this.tokenCache.set(t,{text:e,language:o,tokens:c}),c}getFocusedCodeBlockId(t){if(!i(t.selection))return null;const e=t.selection.anchor.blockId,o=t.getBlock(e);return"code_block"===o?.type?e:null}}export{v as CODE_BLOCK_LOCALE_EN,A as CODE_BLOCK_SERVICE_KEY,E as CodeBlockPlugin,j as JSON_LANGUAGE,M as RegexTokenizer,L as SYNTAX_HIGHLIGHTER_SERVICE_KEY,N as XML_LANGUAGE,w as loadCodeBlockLocale};
|
|
2
2
|
//# sourceMappingURL=code-block.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as t}from"../chunks/HTMLUtils-Cxy99Ak2.mjs";import{a as e}from"../chunks/StyleRuntime-BmsLoEa8.mjs";import{b as n}from"../chunks/ColorValidation-DCSKq9B2.mjs";import{r as o}from"../chunks/PluginHelpers-CdPR0MuT.mjs";import{r as i,i as s,a as r,g as a}from"../chunks/AttributedMarkCommands-
|
|
1
|
+
import{a as t}from"../chunks/HTMLUtils-Cxy99Ak2.mjs";import{a as e}from"../chunks/StyleRuntime-BmsLoEa8.mjs";import{b as n}from"../chunks/ColorValidation-DCSKq9B2.mjs";import{r as o}from"../chunks/PluginHelpers-CdPR0MuT.mjs";import{r as i,i as s,a as r,g as a}from"../chunks/AttributedMarkCommands-BY1BSYWM.mjs";import{m as c}from"../chunks/TypeBrands-Bp_Z_o5Y.mjs";const l={label:"Font Size",tooltip:"Font Size",customFontSizeAria:"Custom font size",fontSizesAria:"Font sizes"},u=/* @__PURE__ */Object.assign({"./locales/ar.ts":()=>import("../chunks/ar-DR6OA3ZO.mjs"),"./locales/de.ts":()=>import("../chunks/de-UREymH-5.mjs"),"./locales/es.ts":()=>import("../chunks/es-BHGwPgrP.mjs"),"./locales/fr.ts":()=>import("../chunks/fr-C9oiPW0k.mjs"),"./locales/hi.ts":()=>import("../chunks/hi-yxAcR3w6.mjs"),"./locales/pt.ts":()=>import("../chunks/pt-CHjmBegF.mjs"),"./locales/ru.ts":()=>import("../chunks/ru-CVSCT776.mjs"),"./locales/zh.ts":()=>import("../chunks/zh-Cqb55JWa.mjs")});async function p(t){if("en"===t)return l;const e=u[`./locales/${t}.ts`];if(!e)return l;try{return(await e()).default}catch{return l}}function f(t,e){const n=function(t){return a(t,"fontSize",t=>t.attrs.size??null)}(t);if(!n)return e;const o=Number.parseInt(n,10);return Number.isNaN(o)?e:o}function m(t,e,n){const o={type:c("fontSize"),attrs:{size:n}},i=r(e,o);return!!i&&(t.dispatch(i),!0)}function d(t,e){const n=i(e,c("fontSize"));return!!n&&(t.dispatch(n),!0)}function z(t,e,n,o,i){const s=function(t,e,n){if("up"===e){for(const e of n)if(e>t)return e;return null}for(let o=n.length-1;o>=0;o--){const e=n[o];if(void 0!==e&&e<t)return e}return null}(f(e,i),n,o);return null!==s&&(s===i?d(t,e):m(t,e,`${s}px`))}function h(t,e,n){e===n?t.executeCommand("removeFontSize"):m(t,t.getState(),`${e}px`)}function g(t,e){const n=document.createElement("button");n.type="button",n.id=`notectl-font-size-option-${t}`,n.className="notectl-font-size-picker__item",n.setAttribute("role","option"),n.setAttribute("aria-selected",String(e)),e&&n.classList.add("notectl-font-size-picker__item--active");const o=document.createElement("span");o.className="notectl-font-size-picker__check",o.textContent=e?"✓":"",n.appendChild(o);const i=document.createElement("span");return i.className="notectl-font-size-picker__label",i.textContent=String(t),n.appendChild(i),n}const S=[8,9,10,11,12,14,16,18,20,24,28,32,36,48,64,72,96];class k{id="fontSize";name="Font Size";priority=21;config;sizes;defaultSize;locale;constructor(t){var e;this.config={...t},this.sizes=function(t){if(!t||0===t.length)return S;const e=[...new Set(t)].filter(t=>Number.isInteger(t)&&t>0);return e.sort((t,e)=>t-e),e.length>0?e:S}(t?.sizes),this.defaultSize=(e=t?.defaultSize,void 0===e?16:Number.isInteger(e)&&e>0?e:16)}async init(t){this.locale=await o(t,this.config.locale,l,p),t.registerStyleSheet("\n/* Font Size Select — Width overrides for combobox button */\n.notectl-toolbar-btn--fontSize {\n\tmin-width: 60px;\n\tmax-width: 80px;\n}\n\n/* Font Size Picker Popup */\n.notectl-font-size-picker {\n\tmin-width: 140px;\n\tdisplay: flex;\n\tflex-direction: column;\n}\n\n.notectl-font-size-picker__input-wrapper {\n\tpadding: 8px 8px 4px;\n}\n\n.notectl-font-size-picker__input {\n\twidth: 100%;\n\tpadding: 6px 8px;\n\tborder: 1px solid var(--notectl-border);\n\tborder-radius: 4px;\n\tfont-size: 13px;\n\tfont-family: inherit;\n\tcolor: var(--notectl-fg);\n\tbackground: var(--notectl-bg);\n\toutline: none;\n\tbox-sizing: border-box;\n\t-moz-appearance: textfield;\n}\n\n.notectl-font-size-picker__input::-webkit-inner-spin-button,\n.notectl-font-size-picker__input::-webkit-outer-spin-button {\n\t-webkit-appearance: none;\n\tmargin: 0;\n}\n\n.notectl-font-size-picker__input:focus {\n\tborder-color: var(--notectl-border-focus);\n\tbox-shadow: 0 0 0 2px var(--notectl-focus-ring);\n}\n\n.notectl-font-size-picker__list {\n\tmax-height: 280px;\n\toverflow-y: auto;\n\tpadding: 4px 0;\n}\n\n.notectl-font-size-picker__item {\n\tdisplay: flex;\n\talign-items: center;\n\tgap: 8px;\n\twidth: 100%;\n\tpadding: 7px 12px;\n\tborder: none;\n\tbackground: none;\n\tcursor: pointer;\n\tfont-size: 14px;\n\tcolor: var(--notectl-fg);\n\tline-height: 1.4;\n\ttext-align: start;\n\twhite-space: nowrap;\n\tfont-family: inherit;\n\ttransition: background 0.1s;\n\toutline: none;\n}\n\n@media (hover: hover) {\n\t.notectl-font-size-picker__item:hover {\n\t\tbackground: var(--notectl-hover-bg);\n\t}\n}\n\n.notectl-font-size-picker__item--active {\n\tbackground: var(--notectl-active-bg);\n\tcolor: var(--notectl-primary-fg);\n}\n\n@media (hover: hover) {\n\t.notectl-font-size-picker__item--active:hover {\n\t\tbackground: var(--notectl-active-bg);\n\t}\n}\n\n.notectl-font-size-picker__item--focused {\n\toutline: 2px solid var(--notectl-primary);\n\toutline-offset: -2px;\n}\n\n.notectl-font-size-picker__check {\n\tdisplay: inline-flex;\n\talign-items: center;\n\tjustify-content: center;\n\twidth: 16px;\n\tflex-shrink: 0;\n\tfont-size: 13px;\n\tfont-weight: 600;\n\tcolor: var(--notectl-primary-fg);\n}\n\n.notectl-font-size-picker__label {\n\tflex: 1;\n}\n"),this.registerMarkSpec(t),this.registerCommands(t),this.registerKeymaps(t),this.registerToolbarItem(t),this.applyDefaultSizeToContainer(t)}destroy(){}registerMarkSpec(o){o.registerMarkSpec({type:"fontSize",rank:4,attrs:{size:{default:""}},toDOM(t){const n=document.createElement("span"),o=t.attrs?.size??"";return o&&e(n,"fontSize",o),n},toHTMLString:(e,o,i)=>{const s=String(e.attrs?.size??"");if(!s||!n(s))return o;const r=`font-size: ${t(s)}`;return`<span${i?.styleAttr(r)??` style="${r}"`}>${o}</span>`},toHTMLStyle:e=>{const o=String(e.attrs?.size??"");return o&&n(o)?`font-size: ${t(o)}`:null},parseHTML:[{tag:"span",getAttrs:t=>{const e=t.style.fontSize;return!!e&&{size:e}}}],sanitize:{tags:["span"]}})}registerCommands(t){t.registerCommand("removeFontSize",()=>d(t,t.getState())),t.registerCommand("setFontSize",()=>!1),t.registerCommand("increaseFontSize",()=>z(t,t.getState(),"up",this.sizes,this.defaultSize)),t.registerCommand("decreaseFontSize",()=>z(t,t.getState(),"down",this.sizes,this.defaultSize))}registerKeymaps(t){t.registerKeymap({"Mod-Shift-+":()=>z(t,t.getState(),"up",this.sizes,this.defaultSize),"Mod-Shift-_":()=>z(t,t.getState(),"down",this.sizes,this.defaultSize)})}registerToolbarItem(t){t.registerToolbarItem({id:"fontSize",group:"format",label:this.locale.label,tooltip:this.locale.tooltip,command:"removeFontSize",popupType:"combobox",getLabel:t=>String(f(t,this.defaultSize)),renderPopup:(t,e,n)=>{!function(t,e,n){t.classList.add("notectl-font-size-picker");const o=f(e.getState(),n.defaultSize),i=function(t,e){const n=document.createElement("input");return n.type="number",n.className="notectl-font-size-picker__input",n.min=String(1),n.max=String(400),n.value=String(t),n.setAttribute("aria-label",e.locale.customFontSizeAria),n}(o,n);!function(t,e){const n=document.createElement("div");n.className="notectl-font-size-picker__input-wrapper",n.appendChild(e),t.appendChild(n)}(t,i);const{list:s,items:r}=function(t,e,n,o){const i=document.createElement("div");i.className="notectl-font-size-picker__list",i.setAttribute("role","listbox"),i.setAttribute("aria-label",o.locale.fontSizesAria);const s=[];for(const r of t){const t=g(r,r===e);t.addEventListener("mousedown",t=>{t.preventDefault(),t.stopPropagation(),h(n,r,o.defaultSize),o.onClose({restoreFocusTo:o.contentElement})}),s.push(t),i.appendChild(t)}return{list:i,items:s}}(n.sizes,o,e,n);t.appendChild(s),function(t,e,n,o){const i=e.indexOf(n);if(i<0)return;const s=t[i];s&&(requestAnimationFrame(()=>{s.scrollIntoView({block:"nearest"})}),o.setAttribute("aria-activedescendant",s.id))}(r,n.sizes,o,s),function(t,e,n,o,i){let s=-1;const r=t=>{s>=0&&s<n.length&&n[s]?.classList.remove("notectl-font-size-picker__item--focused"),s=t;const o=n[s];s>=0&&s<n.length&&o&&(o.classList.add("notectl-font-size-picker__item--focused"),o.scrollIntoView({block:"nearest"}),e.setAttribute("aria-activedescendant",o.id))};t.addEventListener("keydown",e=>{if("Enter"===e.key){e.preventDefault();const n=Number.parseInt(t.value,10);!Number.isNaN(n)&&n>=1&&n<=400&&(h(o,n,i.defaultSize),i.onClose({restoreFocusTo:i.contentElement}))}else"ArrowDown"===e.key?(e.preventDefault(),r(0),n[0]?.focus()):"Escape"===e.key&&(e.preventDefault(),i.onClose({restoreFocusTo:i.contentElement}))}),e.addEventListener("keydown",e=>{if("ArrowDown"===e.key)e.preventDefault(),s<n.length-1&&(r(s+1),n[s]?.focus());else if("ArrowUp"===e.key)e.preventDefault(),s>0?(r(s-1),n[s]?.focus()):(r(-1),t.focus());else if("Enter"===e.key){e.preventDefault();const t=i.sizes[s];s>=0&&s<i.sizes.length&&void 0!==t&&(h(o,t,i.defaultSize),i.onClose({restoreFocusTo:i.contentElement}))}else"Escape"===e.key&&(e.preventDefault(),i.onClose({restoreFocusTo:i.contentElement}))})}(i,s,r,e,n)}(t,e,{sizes:this.sizes,defaultSize:this.defaultSize,onClose:n,contentElement:e.getContainer(),locale:this.locale})},isActive:t=>function(t){return s(t,"fontSize")}(t)})}applyDefaultSizeToContainer(t){const n=t.getContainer();e(n,"fontSize",`${this.defaultSize}px`)}}export{l as FONT_SIZE_LOCALE_EN,k as FontSizePlugin,p as loadFontSizeLocale};
|
|
2
2
|
//# sourceMappingURL=font-size.mjs.map
|
package/dist/plugins/font.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{i as t,g as e,a as n,r as o}from"../chunks/AttributedMarkCommands-
|
|
1
|
+
import{i as t,g as e,a as n,r as o}from"../chunks/AttributedMarkCommands-BY1BSYWM.mjs";import{a as i}from"../chunks/HTMLUtils-Cxy99Ak2.mjs";import{m as r}from"../chunks/TypeBrands-Bp_Z_o5Y.mjs";import{a as s,g as a}from"../chunks/StyleRuntime-BmsLoEa8.mjs";import{a as c}from"../chunks/ColorValidation-DCSKq9B2.mjs";import{r as l}from"../chunks/PluginHelpers-CdPR0MuT.mjs";const m={label:"Font",tooltip:"Font Family"},p=/* @__PURE__ */Object.assign({"./locales/ar.ts":()=>import("../chunks/ar-Dlb5riUN.mjs"),"./locales/de.ts":()=>import("../chunks/de-De2miMxo.mjs"),"./locales/es.ts":()=>import("../chunks/es-D-II7LZC.mjs"),"./locales/fr.ts":()=>import("../chunks/fr-CfUg1FxU.mjs"),"./locales/hi.ts":()=>import("../chunks/hi-C-l_R2SO.mjs"),"./locales/pt.ts":()=>import("../chunks/pt-DfB-IaYi.mjs"),"./locales/ru.ts":()=>import("../chunks/ru-CNLx7T3O.mjs"),"./locales/zh.ts":()=>import("../chunks/zh-Da1z6qbB.mjs")});async function f(t){if("en"===t)return m;const e=p[`./locales/${t}.ts`];if(!e)return m;try{return(await e()).default}catch{return m}}class h{id="font";name="Font";priority=22;config;locale;injectedStyleElement=null;context=null;constructor(t){this.config=t}async init(t){this.locale=await l(t,this.config.locale,m,f),t.registerStyleSheet("\n/* Font Select — Width overrides for combobox button */\n.notectl-toolbar-btn--font {\n\tmin-width: 100px;\n\tmax-width: 160px;\n}\n\n/* Font Picker Popup */\n.notectl-font-picker {\n\tmin-width: 200px;\n\tmax-height: 320px;\n\toverflow-y: auto;\n}\n\n.notectl-font-picker__list {\n\tpadding: 4px 0;\n}\n\n.notectl-font-picker__item {\n\tdisplay: flex;\n\talign-items: center;\n\tgap: 8px;\n\twidth: 100%;\n\tpadding: 7px 12px;\n\tborder: none;\n\tbackground: none;\n\tcursor: pointer;\n\tfont-size: 14px;\n\tcolor: var(--notectl-fg);\n\tline-height: 1.4;\n\ttext-align: start;\n\twhite-space: nowrap;\n\tfont-family: inherit;\n\ttransition: background 0.1s;\n}\n\n@media (hover: hover) {\n\t.notectl-font-picker__item:hover {\n\t\tbackground: var(--notectl-hover-bg);\n\t}\n}\n\n.notectl-font-picker__item--active {\n\tbackground: var(--notectl-active-bg);\n\tcolor: var(--notectl-primary-fg);\n}\n\n@media (hover: hover) {\n\t.notectl-font-picker__item--active:hover {\n\t\tbackground: var(--notectl-active-bg);\n\t}\n}\n\n.notectl-font-picker__check {\n\tdisplay: inline-flex;\n\talign-items: center;\n\tjustify-content: center;\n\twidth: 16px;\n\tflex-shrink: 0;\n\tfont-size: 13px;\n\tfont-weight: 600;\n\tcolor: var(--notectl-primary-fg);\n}\n\n.notectl-font-picker__label {\n\tflex: 1;\n}\n\n.notectl-font-picker__separator {\n\theight: 1px;\n\tbackground: var(--notectl-border);\n\tmargin: 4px 8px;\n}\n"),this.context=t,this.registerMarkSpec(t),this.registerCommands(t),this.registerToolbarItem(t),this.injectFontFaces()}destroy(){this.injectedStyleElement?.remove(),this.injectedStyleElement=null,this.context=null}registerMarkSpec(t){t.registerMarkSpec({type:"font",rank:6,attrs:{family:{default:""}},toDOM(t){const e=document.createElement("span"),n=t.attrs?.family??"";return n&&s(e,"fontFamily",n),e},toHTMLString:(t,e,n)=>{const o=String(t.attrs?.family??"");if(!o||!c(o))return e;const r=`font-family: ${i(o)}`;return`<span${n?.styleAttr(r)??` style="${r}"`}>${e}</span>`},toHTMLStyle:t=>{const e=String(t.attrs?.family??"");return e&&c(e)?`font-family: ${i(e)}`:null},parseHTML:[{tag:"span",getAttrs:t=>{const e=t.style.fontFamily;return!!e&&{family:e.replace(/"/g,"'")}}}],sanitize:{tags:["span"]}})}registerCommands(t){t.registerCommand("removeFont",()=>{const e=t.getState();return this.removeFont(t,e)}),t.registerCommand("setFont",()=>!1)}get defaultFont(){if(this.config.defaultFont){const t=this.config.fonts.find(t=>t.name===this.config.defaultFont);if(t)return t}const t=this.config.fonts[0];if(!t)throw new Error("FontPlugin: fonts list is empty");return t}registerToolbarItem(t){t.registerToolbarItem({id:"font",group:"format",label:this.locale.label,tooltip:this.locale.tooltip,command:"removeFont",popupType:"combobox",getLabel:t=>this.resolveFontName(this.getActiveFont(t)),renderPopup:(t,e,n)=>{this.renderFontPopup(t,e,n)},isActive:t=>this.isFontActive(t)})}resolveFontName(t){if(!t)return this.defaultFont.name;const e=this.config.fonts.find(e=>e.family===t);return e?.name??(t.split(",")[0]??"").trim().replace(/['"]/g,"")}isFontActive(e){return t(e,"font")}getActiveFont(t){return e(t,"font",t=>t.attrs.family??null)}applyFont(t,e,o){const i={type:r("font"),attrs:{family:o}},s=n(e,i);return!!s&&(t.dispatch(s),!0)}removeFont(t,e){const n=o(e,r("font"));return!!n&&(t.dispatch(n),!0)}injectFontFaces(){const t=[];for(const o of this.config.fonts)if(o.fontFaces?.length)for(const e of o.fontFaces){const n=[`font-family: '${(o.family.split(",")[0]??"").trim().replace(/['"]/g,"")}'`,`src: ${e.src}`];e.weight&&n.push(`font-weight: ${e.weight}`),e.style&&n.push(`font-style: ${e.style}`),n.push(`font-display: ${e.display??"swap"}`),t.push(`@font-face {\n\t${n.join(";\n\t")};\n}`)}if(0===t.length)return;const e=document.createElement("style");e.setAttribute("data-notectl-fonts","");const n=this.context?a(this.context.getContainer()):void 0;n&&e.setAttribute("nonce",n),e.textContent=t.join("\n\n"),document.head.appendChild(e),this.injectedStyleElement=e}renderFontPopup(t,e,n){t.classList.add("notectl-font-picker");const o=e.getState(),i=this.getActiveFont(o),r=this.defaultFont.family,s=e.getContainer(),a=document.createElement("div");a.className="notectl-font-picker__list",a.setAttribute("role","listbox"),a.setAttribute("aria-label",this.locale.label);for(const c of this.config.fonts){const t=c.family===r,o=t&&!i||i===c.family,l=this.createFontItem(c.name,c.family,o,o=>{o.preventDefault(),o.stopPropagation(),t?e.executeCommand("removeFont"):this.applyFont(e,e.getState(),c.family),n({restoreFocusTo:s})});c.category&&l.setAttribute("data-category",c.category),a.appendChild(l)}t.appendChild(a)}createFontItem(t,e,n,o){const i=document.createElement("button");i.type="button",i.className="notectl-font-picker__item",i.setAttribute("role","option"),i.setAttribute("aria-selected",String(n)),n&&i.classList.add("notectl-font-picker__item--active");const r=document.createElement("span");r.className="notectl-font-picker__check",r.textContent=n?"✓":"",i.appendChild(r);const a=document.createElement("span");return a.className="notectl-font-picker__label",a.textContent=t,e&&s(a,"fontFamily",e),i.appendChild(a),i.addEventListener("mousedown",o),i}}export{m as FONT_LOCALE_EN,h as FontPlugin,f as loadFontLocale};
|
|
2
2
|
//# sourceMappingURL=font.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{G as r}from"../chunks/index-
|
|
1
|
+
import{G as r}from"../chunks/index-Cs9iqxhF.mjs";export{r as GapCursorPlugin};
|
|
2
2
|
//# sourceMappingURL=gap-cursor.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{i as e}from"../chunks/Commands-
|
|
1
|
+
import{i as e}from"../chunks/Commands-D_gMCnVa.mjs";class r{id="hard-break";name="Hard Break";priority=10;init(e){this.registerInlineNodeSpec(e),this.registerCommands(e),this.registerKeymap(e)}registerInlineNodeSpec(e){e.registerInlineNodeSpec({type:"hard_break",toDOM:()=>document.createElement("br"),toHTMLString:()=>"<br>",parseHTML:[{tag:"br"}],sanitize:{tags:["br"]}})}registerCommands(r){r.registerCommand("insertHardBreak",()=>{const t=r.getState(),i=e(t);return!!i&&(r.dispatch(i),!0)})}registerKeymap(r){r.registerKeymap({"Shift-Enter":()=>{const t=r.getState(),i=e(t);return!!i&&(r.dispatch(i),!0)}})}}export{r as HardBreakPlugin};
|
|
2
2
|
//# sourceMappingURL=hard-break.mjs.map
|
package/dist/plugins/heading.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{H as e,a as i,l as s}from"../chunks/HeadingPlugin-
|
|
1
|
+
import{H as e,a as i,l as s}from"../chunks/HeadingPlugin-BmkeUXj8.mjs";import{B as a}from"../chunks/BlockTypePickerRegistry-DcSE6IXB.mjs";export{a as BlockTypePickerRegistry,e as HEADING_LOCALE_EN,i as HeadingPlugin,s as loadHeadingLocale};
|
|
2
2
|
//# sourceMappingURL=heading.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{C as e}from"../chunks/color-picker-Byjl_xr9.mjs";import{a as t}from"../chunks/HTMLUtils-Cxy99Ak2.mjs";import{a as r}from"../chunks/StyleRuntime-BmsLoEa8.mjs";import{r as o,i as s,b as a}from"../chunks/ColorPickerPopup-
|
|
1
|
+
import{C as e}from"../chunks/color-picker-Byjl_xr9.mjs";import{a as t}from"../chunks/HTMLUtils-Cxy99Ak2.mjs";import{a as r}from"../chunks/StyleRuntime-BmsLoEa8.mjs";import{r as o,i as s,b as a}from"../chunks/ColorPickerPopup-D6XjShhv.mjs";import{r as i,i as l}from"../chunks/ColorValidation-DCSKq9B2.mjs";import{r as c}from"../chunks/PluginHelpers-CdPR0MuT.mjs";const f={label:"Highlight",tooltip:"Highlight Color",resetLabel:"None",ariaLabelPrefix:"Highlight color"},n=/* @__PURE__ */Object.assign({"./locales/ar.ts":()=>import("../chunks/ar-iU02mRe5.mjs"),"./locales/de.ts":()=>import("../chunks/de-CjLAdBt2.mjs"),"./locales/es.ts":()=>import("../chunks/es-B9UhsaEI.mjs"),"./locales/fr.ts":()=>import("../chunks/fr-YMiDtWuG.mjs"),"./locales/hi.ts":()=>import("../chunks/hi-C1LhM-oY.mjs"),"./locales/pt.ts":()=>import("../chunks/pt-v1E9u-Jx.mjs"),"./locales/ru.ts":()=>import("../chunks/ru-DjgNdOdJ.mjs"),"./locales/zh.ts":()=>import("../chunks/zh--oNSMazK.mjs")});async function h(e){if("en"===e)return f;const t=n[`./locales/${e}.ts`];if(!t)return f;try{return(await t()).default}catch{return f}}const g=["#fff176","#aed581","#4dd0e1","#64b5f6","#ce93d8","#f48fb1","#ffab91","#ff8a65","#e6ee9c","#80cbc4","#fff9c4","#dcedc8","#e0f7fa","#e3f2fd","#f3e5f5","#fce4ec","#fff3e0","#fbe9e7","#f9fbe7","#e0f2f1","#fff59d","#c5e1a5","#80deea","#90caf9","#e1bee7","#f8bbd0","#ffcc80","#ffab91","#e6ee9c","#a5d6a7","#ffee58","#9ccc65","#26c6da","#42a5f5","#ab47bc","#ec407a","#ffa726","#ff7043","#d4e157","#66bb6a","#ffffff","#fafafa","#f5f5f5","#eeeeee","#e0e0e0","#bdbdbd","#e8eaf6","#efebe9","#eceff1","#fafafa"];class m{id="highlight";name="Highlight";priority=24;config;colors;locale;constructor(e){this.config={...e},this.colors=i(e?.colors,g,"HighlightPlugin")}async init(t){this.locale=await c(t,this.config.locale,f,h),t.registerStyleSheet(e),this.registerMarkSpec(t),this.registerCommands(t),this.registerToolbarItem(t)}registerMarkSpec(e){e.registerMarkSpec({type:"highlight",rank:4,attrs:{color:{default:""}},toDOM(e){const t=document.createElement("span"),o=e.attrs?.color??"";return r(t,"backgroundColor",o),t},toHTMLString:(e,r,o)=>{const s=String(e.attrs?.color??"");if(!s||!l(s))return r;const a=`background-color: ${t(s)}`;return`<span${o?.styleAttr(a)??` style="${a}"`}>${r}</span>`},toHTMLStyle:e=>{const r=String(e.attrs?.color??"");return r&&l(r)?`background-color: ${t(r)}`:null},parseHTML:[{tag:"span",getAttrs:e=>{const t=e.style.backgroundColor;return!(!t||!l(t))&&{color:t}}}],sanitize:{tags:["span"]}})}registerCommands(e){e.registerCommand("removeHighlight",()=>o(e,e.getState(),"highlight"))}registerToolbarItem(e){const t=['<svg xmlns="http://www.w3.org/2000/svg"',' viewBox="0 0 24 24">','<path d="M11 3L5.5 17h2.25l1.12-3h6.25l1.12 3h2.25L13 3h-2zm-1.38 9L12 5.67 14.38 12H9.62z"/>','<rect x="3" y="17" width="18" height="6"',' rx="0.5" fill="#fff176"/>',"</svg>"].join("");e.registerToolbarItem({id:"highlight",group:"format",icon:t,label:this.locale.label,tooltip:this.locale.tooltip,command:"removeHighlight",popupType:"custom",renderPopup:(e,t,r)=>{a(e,t,{markType:"highlight",colors:this.colors,columns:10,resetLabel:this.locale.resetLabel,resetCommand:"removeHighlight",ariaLabelPrefix:this.locale.ariaLabelPrefix,onClose:r})},isActive:e=>s(e,"highlight")})}}export{f as HIGHLIGHT_LOCALE_EN,m as HighlightPlugin,h as loadHighlightLocale};
|
|
2
2
|
//# sourceMappingURL=highlight.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{c as t}from"../chunks/Document-
|
|
1
|
+
import{c as t}from"../chunks/Document-3pNX7ear.mjs";import{j as e,i as r,c as o}from"../chunks/Selection-DhbizDM4.mjs";import{n as s}from"../chunks/TypeBrands-Bp_Z_o5Y.mjs";import{c as i}from"../chunks/DomUtils-CznMAZZg.mjs";import{r as n}from"../chunks/PluginHelpers-CdPR0MuT.mjs";import{f as l}from"../chunks/ShortcutFormatting-BLKS0Gys.mjs";const a={label:"Horizontal Rule",tooltip:t=>`Horizontal Rule (${t})`},c=/* @__PURE__ */Object.assign({"./locales/ar.ts":()=>import("../chunks/ar-Bnc7y8BP.mjs"),"./locales/de.ts":()=>import("../chunks/de-DBbzCQrm.mjs"),"./locales/es.ts":()=>import("../chunks/es-CE8t9fuM.mjs"),"./locales/fr.ts":()=>import("../chunks/fr-BGyF2ym0.mjs"),"./locales/hi.ts":()=>import("../chunks/hi-CbLPPQ0b.mjs"),"./locales/pt.ts":()=>import("../chunks/pt-B_XJ2s9X.mjs"),"./locales/ru.ts":()=>import("../chunks/ru-4S8w6UN_.mjs"),"./locales/zh.ts":()=>import("../chunks/zh-Yd3GNsa0.mjs")});async function u(t){if("en"===t)return a;const e=c[`./locales/${t}.ts`];if(!e)return a;try{return(await e()).default}catch{return a}}const m={};function h(t){const r=t.selection;return e(r)?t.doc.children.findIndex(t=>t.id===r.anchor.blockId):-1}class p{id="horizontal-rule";name="Horizontal Rule";priority=40;config;locale;constructor(t){this.config={...m,...t}}async init(t){this.locale=await n(t,this.config.locale,a,u),this.registerNodeSpec(t),this.registerCommands(t),this.registerKeymap(t),this.registerInputRule(t),this.registerToolbarItem(t)}registerNodeSpec(t){t.registerNodeSpec({type:"horizontal_rule",group:"block",isVoid:!0,toDOM:t=>i("hr",t.id),toHTML:()=>"<hr>",parseHTML:[{tag:"hr"}],sanitize:{tags:["hr"]}})}registerCommands(t){t.registerCommand("insertHorizontalRule",()=>this.insertHorizontalRule(t))}registerKeymap(t){t.registerKeymap({"Mod-Shift-H":()=>t.executeCommand("insertHorizontalRule")})}registerInputRule(i){i.registerInputRule({pattern:/^-{3,} $/,handler(i,n,l,a){const c=i.selection;if(!e(c))return null;if(!r(c))return null;const u=i.getBlock(c.anchor.blockId);if(!u||"paragraph"!==u.type)return null;const m=h(i);if(-1===m)return null;const p=t(s("paragraph"));return i.transaction("input").deleteTextAt(c.anchor.blockId,0,a).setBlockType(c.anchor.blockId,s("horizontal_rule")).insertNode([],m+1,p).setSelection(o(p.id,0)).build()}})}registerToolbarItem(t){t.registerToolbarItem({id:"horizontal-rule",group:"block",icon:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M4 11h16v2H4z"/></svg>',label:this.locale.label,tooltip:this.locale.tooltip(l("Mod-Shift-H")),command:"insertHorizontalRule",isActive:()=>!1})}insertHorizontalRule(r){const i=r.getState();if(!e(i.selection))return!1;const n=h(i);if(-1===n)return!1;const l=t(s("horizontal_rule")),a=t(s("paragraph")),c=i.transaction("command").insertNode([],n+1,l).insertNode([],n+2,a).setSelection(o(a.id,0)).build();return r.dispatch(c),!0}}export{a as HORIZONTAL_RULE_LOCALE_EN,p as HorizontalRulePlugin,u as loadHorizontalRuleLocale};
|
|
2
2
|
//# sourceMappingURL=horizontal-rule.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImageCommands.d.ts","sourceRoot":"","sources":["../../../src/plugins/image/ImageCommands.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"ImageCommands.d.ts","sourceRoot":"","sources":["../../../src/plugins/image/ImageCommands.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD;;;;GAIG;AACH,wBAAgB,WAAW,CAC1B,OAAO,EAAE,aAAa,EACtB,KAAK,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GACnD,OAAO,CAuBT;AA6ED,gFAAgF;AAChF,wBAAgB,WAAW,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAe3D;AAED,gEAAgE;AAChE,wBAAgB,YAAY,CAAC,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,OAAO,CAgBxF;AAED,4DAA4D;AAC5D,eAAO,MAAM,eAAe,KAAK,CAAC;AAElC;;;GAGG;AACH,wBAAgB,kBAAkB,CACjC,OAAO,EAAE,aAAa,EACtB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,GACd,OAAO,CAmBT;AAED,wFAAwF;AACxF,wBAAgB,cAAc,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAmB9D;AAED,0DAA0D;AAC1D,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI,CAQlE"}
|
package/dist/plugins/image.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as t}from"../chunks/HTMLUtils-Cxy99Ak2.mjs";import{h as e,g as n,c as i,b as r}from"../chunks/Selection-DhbizDM4.mjs";import{a as o,g as a,s,b as c}from"../chunks/StyleRuntime-BmsLoEa8.mjs";import{c as l}from"../chunks/DomUtils-CznMAZZg.mjs";import{S as d,r as g}from"../chunks/PluginHelpers-CdPR0MuT.mjs";import{f as u}from"../chunks/ShortcutFormatting-BLKS0Gys.mjs";import{n as m,c as h,g as p}from"../chunks/Document-HC8s50qJ.mjs";import{n as f}from"../chunks/TypeBrands-Bp_Z_o5Y.mjs";import{g as b}from"../chunks/Platform-CU6itXZo.mjs";function v(t,i){const o=t.getState(),a=o.selection,s={src:i.src,alt:i.alt??"",align:i.align??"center",...void 0!==i.width?{width:i.width}:{},...void 0!==i.height?{height:i.height}:{}};if(n(a))return!1;const c=e(a)?a.nodeId:a.anchor.blockId,l=function(t,e){const n=t.getBlock(e);if("table_cell"===n?.type)return e;const i=t.getNodePath(e);if(i)for(const r of i){const e=t.getBlock(r);if("table_cell"===e?.type)return r}}(o,c);return l?function(t,e,n,i){const o=t.getNodePath(n);if(!o)return!1;const a=h(f("image"),[],void 0,i),s=t.getBlock(n);if(!s)return!1;const c=t.transaction("command"),l=p(s);for(let r=l.length-1;r>=0;r--){const t=s.children.findIndex(t=>m(t)&&t.id===l[r]?.id);-1!==t&&c.removeNode(o,t)}return c.insertNode(o,0,a),c.setSelection(r(a.id,[...o,a.id])),e.dispatch(c.build()),!0}(o,t,l,s):function(t,e,n,i){const o=t.doc.children.findIndex(t=>t.id===n);if(-1===o)return!1;const a=h(f("image"),[],void 0,i),s=h(f("paragraph")),c=t.transaction("command").insertNode([],o+1,a).insertNode([],o+2,s).setSelection(r(a.id,[])).build();return e.dispatch(c),!0}(o,t,c,s)}function x(t,n,i){const r=t.getState(),o=r.selection;if(!e(o))return!1;const a=r.getBlock(o.nodeId);if(!a||"image"!==a.type)return!1;const s=a.attrs?.width,c=a.attrs?.height;if(void 0===s||void 0===c)return!1;const l=c>0?s/c:1,d=Math.max(50,Math.min(i,s+n)),g=Math.round(d/l);return(d!==s||g!==c)&&function(t,n){const i=t.getState(),r=i.selection;if(!e(r))return!1;const o=i.getBlock(r.nodeId);if(!o||"image"!==o.type)return!1;const a=i.getNodePath(r.nodeId);if(!a)return!1;const s={...o.attrs??{},...n},c=i.transaction("command").setNodeAttr(a,s).build();return t.dispatch(c),!0}(t,{width:d,height:g})}const w={insertImage:"Insert Image",insertImageTooltip:"Insert Image",uploadFromComputer:"Upload from computer",uploadAria:"Upload image from computer",separator:"or",urlPlaceholder:"https://...",urlAria:"Image URL",insertButton:"Insert",insertAria:"Insert image",imageAria:(t,e,n)=>{const i=[t||"Image"];return void 0!==e&&void 0!==n&&i.push(`${e} by ${n} pixels`),i.join(", ")},resetToNaturalSize:"Image reset to natural size.",uploadFailed:"Upload failed.",uploading:"Uploading...",resizeHandleLabel:t=>`Resize ${t}`,imageSelected:"Image selected.",altTextPrefix:"Alt text: ",imageSizeAnnounce:(t,e)=>`Size: ${t} by ${e} pixels.`,resizeHint:(t,e)=>`${t} / ${e} to resize.`,imageResized:(t,e)=>`Image resized to ${t} by ${e} pixels.`,keyboardResizeHint:(t,e)=>`${t} / ${e} to resize`},z=/* @__PURE__ */Object.assign({"./locales/ar.ts":()=>import("../chunks/ar-C5JEHhw9.mjs"),"./locales/de.ts":()=>import("../chunks/de-xJh5C_pk.mjs"),"./locales/es.ts":()=>import("../chunks/es-DvgH3-WZ.mjs"),"./locales/fr.ts":()=>import("../chunks/fr-Ccaetiwi.mjs"),"./locales/hi.ts":()=>import("../chunks/hi-DVof3w0y.mjs"),"./locales/pt.ts":()=>import("../chunks/pt-DlNdH9pu.mjs"),"./locales/ru.ts":()=>import("../chunks/ru-CrbxCeQf.mjs"),"./locales/zh.ts":()=>import("../chunks/zh-C6YALJZt.mjs")});async function y(t){if("en"===t)return w;const e=z[`./locales/${t}.ts`];if(!e)return w;try{return(await e()).default}catch{return w}}const _={start:"notectl-image--start",center:"notectl-image--center",end:"notectl-image--end"},k={nw:"nwse-resize",ne:"nesw-resize",sw:"nesw-resize",se:"nwse-resize"},S={nw:-1,ne:1,sw:-1,se:1},I={nw:"top-left",ne:"top-right",sw:"bottom-left",se:"bottom-right"},L={nw:"top-right",ne:"top-left",sw:"bottom-right",se:"bottom-left"},A={nw:"nesw-resize",ne:"nwse-resize",sw:"nwse-resize",se:"nesw-resize"};function C(t,e,n=w){const i=(e?L:I)[t];return n.resizeHandleLabel(i)}let N=null;function j(){N&&(N.remove(),N=null)}function E(t,e,n,i=w){return(r,c,l)=>{const d=document.createElement("figure");d.className="notectl-image",d.setAttribute("data-block-id",r.id),d.setAttribute("data-void","true"),d.setAttribute("data-selectable","true");const g=document.createElement("div");g.className="notectl-image__container";const m=document.createElement("img");m.className="notectl-image__img",m.draggable=!1;const h=document.createElement("div");h.className="notectl-image__overlay",g.appendChild(m),g.appendChild(h),d.appendChild(g);let p=r.id,f=null;function v(t){const n=t.attrs?.src??"",r=t.attrs?.alt??"",a=t.attrs?.width,s=t.attrs?.height,c=t.attrs?.align??"center";m.src!==n&&(m.src=n),m.alt=r,o(m,"width",void 0!==a?`${a}px`:""),o(m,"height",void 0!==s?`${s}px`:"");for(const e of Object.values(_))d.classList.remove(e);const l=_[c];l&&d.classList.add(l);const g=e.get(t.id)??"idle",u="uploading"===g;h.classList.toggle("notectl-image__overlay--uploading",u),h.classList.toggle("notectl-image__overlay--error","error"===g),h.textContent=u?i.uploading:"error"===g?i.uploadFailed:"",u?d.setAttribute("aria-busy","true"):d.removeAttribute("aria-busy"),function(t){const e=t.attrs?.alt??"",n=t.attrs?.width,r=t.attrs?.height;d.setAttribute("aria-label",i.imageAria(e,n,r))}(t)}v(r);let x=!1;function w(e,n,i,r){let o=0,g=0,u=1,h=S[n];const p=e=>{const n=e.clientX-o,i=(a=g+n*h,Math.max(50,Math.min(t.maxWidth,a)));var a;const c=Math.round(i/u);s(m,{width:`${i}px`,height:`${c}px`}),r.textContent=`${Math.round(i)} × ${c}`},f=t=>{document.removeEventListener("pointermove",p),document.removeEventListener("pointerup",f),d.classList.remove("notectl-image--resizing"),r.classList.remove("notectl-image__size-indicator--visible"),j();const e=Math.round(m.getBoundingClientRect().width),n=Math.round(e/u);!function(t,e,n){const i=c(),r=i.getBlock(t);if(!r)return;const o=r.attrs?.width,a=r.attrs?.height;if(o===e&&a===n)return;const s=i.getNodePath(t);if(!s)return;const d={...r.attrs??{},width:e,height:n},g=i.transaction("command").setNodeAttr(s,d).build();l(g)}(i,e,n),t.target?.releasePointerCapture?.(t.pointerId)};e.addEventListener("pointerdown",t=>{t.preventDefault(),t.stopPropagation();const e="rtl"===b(d);h=function(t,e){const n=S[t];return e?-n:n}(n,e),o=t.clientX,g=m.getBoundingClientRect().width;const i=m.getBoundingClientRect().height;u=i>0?g/i:1,d.classList.add("notectl-image--resizing"),r.textContent=`${Math.round(g)} × ${Math.round(i)}`,r.classList.add("notectl-image__size-indicator--visible"),function(t,e){j(),N=document.createElement("style");const n=e?a(e):void 0;n&&N.setAttribute("nonce",n),N.textContent=`*{cursor:${t}!important;user-select:none!important}`,document.head.appendChild(N)}(e?A[n]:k[n],d),t.target.setPointerCapture(t.pointerId),document.addEventListener("pointermove",p),document.addEventListener("pointerup",f)})}function z(){j(),f&&(f.remove(),f=null)}return m.addEventListener("load",()=>{if(x)return;const e=c(),n=e.getBlock(p);if(!n||"image"!==n.type)return;const i=void 0!==n.attrs?.width,r=void 0!==n.attrs?.height;if(i&&r)return void(x=!0);const o=m.naturalWidth,a=m.naturalHeight;if(0===o||0===a)return;const s=Math.min(o,t.maxWidth),d=o>0?a/o:1,g=Math.round(s*d),u=e.getNodePath(p);if(!u)return;const h={...n.attrs??{},width:s,height:g},f=e.transaction("command").setNodeAttr(u,h).build();l(f),x=!0}),{dom:d,contentDOM:null,update:t=>"image"===t.type&&(p=t.id,d.setAttribute("data-block-id",t.id),v(t),!0),selectNode(){d.classList.add("notectl-image--selected"),function(e){if(!t.resizable||f)return;f=document.createElement("div"),f.className="notectl-image__resize-overlay",f.setAttribute("data-notectl-no-print","");const r=document.createElement("div");r.className="notectl-image__size-indicator",f.appendChild(r);const o="rtl"===b(d),a=["nw","ne","sw","se"];for(const t of a){const n=document.createElement("div");n.className=`notectl-image__resize-handle notectl-image__resize-handle--${t}`,n.setAttribute("role","separator"),n.setAttribute("aria-label",C(t,o,i)),w(n,t,e,r),f.appendChild(n)}if(n){const t=function(t,e){const n=t.shrinkWidth??null,i=t.growWidth??null;return n&&i?e.keyboardResizeHint(u(n),u(i)):""}(n,i);if(t){const e=document.createElement("div");e.className="notectl-image__keyboard-hint",e.setAttribute("aria-hidden","true"),e.textContent=t,f.appendChild(e)}}g.appendChild(f)}(p)},deselectNode(){d.classList.remove("notectl-image--selected"),z()},destroy(){z()}}}}const $=new d("image:upload"),R={growWidth:"Mod-Shift-ArrowRight",shrinkWidth:"Mod-Shift-ArrowLeft",growWidthLarge:"Mod-Shift-Alt-ArrowRight",shrinkWidthLarge:"Mod-Shift-Alt-ArrowLeft",resetSize:"Mod-Shift-0"},M={maxWidth:800,maxFileSize:10485760,acceptedTypes:["image/png","image/jpeg","image/gif","image/webp","image/svg+xml"],resizable:!0,resizeStep:10,resizeStepLarge:50};class T{id="image";name="Image";priority=45;config;resolvedKeymap;uploadStates=/* @__PURE__ */new Map;blobUrls=/* @__PURE__ */new Set;context=null;locale;constructor(t){this.config={...M,...t},this.resolvedKeymap={...R,...t?.keymap}}async init(t){this.locale=await g(t,this.config.locale,w,y),t.registerStyleSheet('\n/* Image */\n.notectl-image {\n\tmargin: 8px 0;\n\tuser-select: none;\n\tline-height: 0;\n}\n\n.notectl-image--center {\n\ttext-align: center;\n}\n\n.notectl-image--start {\n\ttext-align: start;\n}\n\n.notectl-image--end {\n\ttext-align: end;\n}\n\n.notectl-image__container {\n\tdisplay: inline-block;\n\tposition: relative;\n\tline-height: 0;\n}\n\n.notectl-image__img {\n\tdisplay: block;\n\tmax-width: 100%;\n\tborder-radius: 4px;\n}\n\n.notectl-image--selected .notectl-image__container {\n\toutline: 2px solid var(--notectl-primary);\n\toutline-offset: 2px;\n\tborder-radius: 6px;\n}\n\n/* Alignment toolbar (appears on image selection) */\n.notectl-image__align-toolbar {\n\tdisplay: flex;\n\tgap: 2px;\n\tposition: absolute;\n\ttop: -36px;\n\tleft: 50%;\n\ttransform: translateX(-50%);\n\tbackground: var(--notectl-surface-overlay);\n\tborder: 1px solid var(--notectl-border);\n\tborder-radius: 6px;\n\tpadding: 2px;\n\tbox-shadow: 0 2px 8px var(--notectl-shadow);\n\tz-index: 10;\n}\n\n.notectl-image__align-btn {\n\tdisplay: flex;\n\talign-items: center;\n\tjustify-content: center;\n\twidth: 28px;\n\theight: 28px;\n\tborder: none;\n\tbackground: transparent;\n\tborder-radius: 4px;\n\tcursor: pointer;\n\tcolor: var(--notectl-fg);\n}\n\n.notectl-image__align-btn:hover {\n\tbackground: var(--notectl-hover-bg);\n}\n\n.notectl-image__align-btn--active {\n\tbackground: var(--notectl-active-bg);\n\tcolor: var(--notectl-primary-fg);\n}\n\n.notectl-image__align-btn svg {\n\twidth: 16px;\n\theight: 16px;\n\tfill: currentColor;\n}\n\n/* Upload overlay */\n.notectl-image__overlay {\n\tposition: absolute;\n\tinset: 0;\n\tdisplay: none;\n\talign-items: center;\n\tjustify-content: center;\n\tbackground: rgba(255, 255, 255, 0.8);\n\tborder-radius: 4px;\n\tfont-size: 13px;\n\tcolor: var(--notectl-fg-muted);\n}\n\n.notectl-image__overlay--uploading {\n\tdisplay: flex;\n}\n\n.notectl-image__overlay--error {\n\tdisplay: flex;\n\tbackground: var(--notectl-danger-muted);\n\tcolor: var(--notectl-danger);\n}\n\n/* Resize overlay + handles */\n.notectl-image__resize-overlay {\n\tposition: absolute;\n\tinset: 0;\n\tpointer-events: none;\n}\n\n.notectl-image__resize-handle {\n\tposition: absolute;\n\twidth: 10px;\n\theight: 10px;\n\tbackground: var(--notectl-bg);\n\tborder: 2px solid var(--notectl-primary);\n\tborder-radius: 50%;\n\tpointer-events: all;\n\tz-index: 2;\n\ttransition: transform 0.1s, background 0.1s;\n}\n\n.notectl-image__resize-handle:hover {\n\tbackground: var(--notectl-primary);\n\ttransform: scale(1.3);\n}\n\n.notectl-image--resizing .notectl-image__resize-handle {\n\tbackground: var(--notectl-primary);\n}\n\n.notectl-image__resize-handle--nw {\n\ttop: -5px;\n\tinset-inline-start: -5px;\n\tcursor: nwse-resize;\n}\n\n.notectl-image__resize-handle--ne {\n\ttop: -5px;\n\tinset-inline-end: -5px;\n\tcursor: nesw-resize;\n}\n\n.notectl-image__resize-handle--sw {\n\tbottom: -5px;\n\tinset-inline-start: -5px;\n\tcursor: nesw-resize;\n}\n\n.notectl-image__resize-handle--se {\n\tbottom: -5px;\n\tinset-inline-end: -5px;\n\tcursor: nwse-resize;\n}\n\n/* RTL cursor overrides — flip diagonal cursors when in RTL context */\n[dir="rtl"] .notectl-image__resize-handle--nw {\n\tcursor: nesw-resize;\n}\n\n[dir="rtl"] .notectl-image__resize-handle--ne {\n\tcursor: nwse-resize;\n}\n\n[dir="rtl"] .notectl-image__resize-handle--sw {\n\tcursor: nwse-resize;\n}\n\n[dir="rtl"] .notectl-image__resize-handle--se {\n\tcursor: nesw-resize;\n}\n\n/* Size indicator tooltip */\n.notectl-image__size-indicator {\n\tposition: absolute;\n\tbottom: -28px;\n\tleft: 50%;\n\ttransform: translateX(-50%);\n\tpadding: 2px 8px;\n\tbackground: var(--notectl-tooltip-bg);\n\tcolor: var(--notectl-tooltip-fg);\n\tfont-size: 11px;\n\tfont-weight: 500;\n\tborder-radius: 4px;\n\twhite-space: nowrap;\n\tpointer-events: none;\n\topacity: 0;\n\ttransition: opacity 0.15s;\n\tz-index: 3;\n}\n\n.notectl-image__size-indicator--visible {\n\topacity: 1;\n}\n\n/* Keyboard resize hint (shown on selection, hidden during drag) */\n.notectl-image__keyboard-hint {\n\tdisplay: none;\n\tposition: absolute;\n\tbottom: -28px;\n\tleft: 50%;\n\ttransform: translateX(-50%);\n\tpadding: 2px 8px;\n\tfont-size: 11px;\n\tcolor: var(--notectl-fg-muted);\n\twhite-space: nowrap;\n\tpointer-events: none;\n\tz-index: 3;\n}\n\n.notectl-image--selected .notectl-image__keyboard-hint {\n\tdisplay: block;\n}\n\n.notectl-image--resizing .notectl-image__keyboard-hint {\n\tdisplay: none;\n}\n\n/* Resizing feedback */\n.notectl-image--resizing .notectl-image__img {\n\topacity: 0.85;\n}\n'),this.context=t,this.registerNodeSpec(t),this.registerNodeView(t),function(t){t.registerCommand("insertImage",()=>v(t,{src:""})),t.registerCommand("removeImage",()=>function(t){const n=t.getState(),r=n.selection;if(!e(r))return!1;const o=n.getBlock(r.nodeId);if(!o||"image"!==o.type)return!1;const a=n.getNodePath(r.nodeId);if(!a||0===a.length)return!1;const s=a.slice(0,-1);let c;if(0===s.length)c=n.doc;else{const t=s[s.length-1];c=t?n.getBlock(t):void 0}if(!c)return!1;const l=c.children.findIndex(t=>m(t)&&t.id===r.nodeId);if(-1===l)return!1;const d=function(t,e,n){if(0===e.length){const e=t.doc.children,i=e.findIndex(t=>t.id===n),r=e[i+1]??e[i-1];return r?.id}return e[e.length-1]}(n,s,r.nodeId);if(!d)return!1;const g=n.transaction("command").removeNode(s,l).setSelection(i(d,0)).build();return t.dispatch(g),!0}(t))}(t),this.registerResizeCommands(t),this.registerResizeKeymaps(t),this.registerFileHandler(t),this.registerToolbarItem(t)}destroy(){for(const t of this.blobUrls)URL.revokeObjectURL(t);this.blobUrls.clear(),this.uploadStates.clear(),this.context=null}onStateChange(t,e,n){if(!this.context)return;for(const o of this.uploadStates.keys())e.getBlock(o)||this.uploadStates.delete(o);const i=this.isImageSelected(t),r=this.isImageSelected(e);!i&&r&&this.announceImageSelection(e)}registerNodeSpec(e){const n=this.locale;e.registerNodeSpec({type:"image",group:"block",isVoid:!0,selectable:!0,attrs:{src:{default:""},alt:{default:""},align:{default:"center"}},toDOM(t){const e=l("figure",t.id);e.className="notectl-image",e.setAttribute("data-void","true"),e.setAttribute("data-selectable","true");const i=document.createElement("div");i.className="notectl-image__container";const r=t.attrs?.alt??"",a=t.attrs?.width,s=t.attrs?.height,c=document.createElement("img");c.className="notectl-image__img",c.src=t.attrs?.src??"",c.alt=r,c.draggable=!1,void 0!==a&&o(c,"width",`${a}px`),void 0!==s&&o(c,"height",`${s}px`);const d={start:"notectl-image--start",center:"notectl-image--center",end:"notectl-image--end"}[t.attrs?.align??"center"];return d&&e.classList.add(d),e.setAttribute("aria-label",n.imageAria(r,a,s)),i.appendChild(c),e.appendChild(i),e},toHTML(e){const n=t(e.attrs?.src??""),i=t(e.attrs?.alt??""),r=e.attrs?.width,o=e.attrs?.height;return`<figure><img src="${n}" alt="${i}"${(void 0!==r?` width="${r}"`:"")+(void 0!==o?` height="${o}"`:"")}></figure>`},parseHTML:[{tag:"figure",getAttrs(t){const e=t.querySelector("img");if(!e)return!1;const n={src:e.getAttribute("src")??"",alt:e.getAttribute("alt")??"",align:"center"},i=e.getAttribute("width"),r=e.getAttribute("height");i&&(n.width=Number.parseInt(i,10)),r&&(n.height=Number.parseInt(r,10));const o=t.style?.textAlign??"";return"start"===o||"end"===o||"center"===o?n.align=o:"left"===o?n.align="start":"right"===o?n.align="end":t.classList.contains("notectl-align-start")||t.classList.contains("notectl-align-left")||t.classList.contains("notectl-image--start")||t.classList.contains("notectl-image--left")?n.align="start":t.classList.contains("notectl-align-end")||t.classList.contains("notectl-align-right")||t.classList.contains("notectl-image--end")||t.classList.contains("notectl-image--right")?n.align="end":t.classList.contains("notectl-align-center")&&(n.align="center"),n}},{tag:"img",getAttrs(t){const e={src:t.getAttribute("src")??"",alt:t.getAttribute("alt")??"",align:"center"},n=t.getAttribute("width"),i=t.getAttribute("height");return n&&(e.width=Number.parseInt(n,10)),i&&(e.height=Number.parseInt(i,10)),e}}],sanitize:{tags:["figure","img"],attrs:["src","alt","width","height","class","style"]}})}registerNodeView(t){t.registerNodeView("image",E(this.config,this.uploadStates,this.resolvedKeymap,this.locale))}registerResizeCommands(t){const n=this.config.resizeStep??10,i=this.config.resizeStepLarge??50,r=this.config.maxWidth;t.registerCommand("resizeImageGrow",()=>{const e=x(t,n,r);return e&&this.announceCurrentSize(t),e}),t.registerCommand("resizeImageShrink",()=>{const e=x(t,-n,r);return e&&this.announceCurrentSize(t),e}),t.registerCommand("resizeImageGrowLarge",()=>{const e=x(t,i,r);return e&&this.announceCurrentSize(t),e}),t.registerCommand("resizeImageShrinkLarge",()=>{const e=x(t,-i,r);return e&&this.announceCurrentSize(t),e}),t.registerCommand("resetImageSize",()=>{const n=function(t){const n=t.getState(),i=n.selection;if(!e(i))return!1;const r=n.getBlock(i.nodeId);if(!r||"image"!==r.type)return!1;const o=n.getNodePath(i.nodeId);if(!o)return!1;const a={...r.attrs??{}},s=Object.fromEntries(Object.entries(a).filter(([t])=>"width"!==t&&"height"!==t)),c=n.transaction("command").setNodeAttr(o,s).build();return t.dispatch(c),!0}(t);return n&&t.announce(this.locale.resetToNaturalSize),n})}registerResizeKeymaps(t){const e={},n={growWidth:"resizeImageGrow",shrinkWidth:"resizeImageShrink",growWidthLarge:"resizeImageGrowLarge",shrinkWidthLarge:"resizeImageShrinkLarge",resetSize:"resetImageSize"};for(const[i,r]of Object.entries(n)){const n=this.resolvedKeymap[i]??null;n&&(e[n]=()=>t.executeCommand(r))}Object.keys(e).length>0&&t.registerKeymap(e)}registerFileHandler(t){t.registerFileHandler("image/*",async(e,n)=>!!this.isAcceptedType(e.type)&&(this.handleFileInsert(t,e),!0))}handleFileInsert(t,n){if(n.size>this.config.maxFileSize)return;const i=URL.createObjectURL(n);if(this.blobUrls.add(i),!v(t,{src:i}))return URL.revokeObjectURL(i),void this.blobUrls.delete(i);const r=t.getState().selection;if(!e(r))return;const o=r.nodeId;this.uploadStates.set(o,"uploading"),t.getService($)?this.uploadFile(t,n,o,i):this.uploadStates.set(o,"complete")}async uploadFile(t,e,n,i){const r=t.getService($);if(r)try{const o=await r.upload(e);this.uploadStates.set(n,"complete");const a=t.getState(),s=a.getBlock(n);if(!s)return;const c=a.getNodePath(n);if(!c)return;const l={...s.attrs??{},src:o.url,...void 0!==o.width?{width:o.width}:{},...void 0!==o.height?{height:o.height}:{}},d=a.transaction("command").setNodeAttr(c,l).build();t.dispatch(d),URL.revokeObjectURL(i),this.blobUrls.delete(i)}catch{this.uploadStates.set(n,"error"),t.announce(this.locale.uploadFailed)}}registerToolbarItem(t){t.registerToolbarItem({id:"image",group:"insert",icon:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/></svg>',label:this.locale.insertImage,tooltip:this.locale.insertImageTooltip,command:"insertImage",popupType:"custom",renderPopup:(t,e,n)=>{!function(t,e,n){o(t,"padding","8px"),o(t,"minWidth","240px"),function(t,e,n){const i=document.createElement("input");i.type="file",i.accept=n.acceptedTypes.join(","),c(i,"position:absolute;width:0;height:0;overflow:hidden;opacity:0;");const r=document.createElement("button");r.type="button",r.textContent=n.locale.uploadFromComputer,r.setAttribute("aria-label",n.locale.uploadAria),c(r,"display:block;width:100%;padding:8px 12px;cursor:pointer;text-align:center;box-sizing:border-box;border:1px solid var(--notectl-border);border-radius:4px;background:var(--notectl-surface-raised);color:var(--notectl-fg);"),r.addEventListener("mousedown",t=>{t.preventDefault(),t.stopPropagation(),i.click()}),i.addEventListener("change",()=>{const t=i.files?.[0];t&&(n.onFileInsert(e,t),n.onClose(),e.getContainer().focus())}),t.appendChild(i),t.appendChild(r)}(t,e,n),function(t,e){const n=document.createElement("div");c(n,"display:flex;align-items:center;margin:8px 0;color:var(--notectl-fg-muted);font-size:12px;");const i=document.createElement("span");c(i,"flex:1;height:1px;background:var(--notectl-border);");const r=document.createElement("span");r.textContent=e.separator,c(r,"padding:0 8px;");const o=document.createElement("span");c(o,"flex:1;height:1px;background:var(--notectl-border);"),n.appendChild(i),n.appendChild(r),n.appendChild(o),t.appendChild(n)}(t,n.locale),function(t,e,n){const i=document.createElement("input");i.type="url",i.placeholder=n.locale.urlPlaceholder,i.setAttribute("aria-label",n.locale.urlAria),c(i,"width:100%;padding:6px 8px;box-sizing:border-box;border:1px solid var(--notectl-border);border-radius:4px;background:var(--notectl-bg);color:var(--notectl-fg);");const r=document.createElement("button");r.type="button",r.textContent=n.locale.insertButton,r.setAttribute("aria-label",n.locale.insertAria),c(r,"width:100%;padding:8px 12px;margin-top:4px;cursor:pointer;border:1px solid var(--notectl-border);border-radius:4px;background:var(--notectl-surface-raised);color:var(--notectl-fg);");const o=()=>{const t=i.value.trim();t&&(v(e,{src:t}),n.onClose(),e.getContainer().focus())};r.addEventListener("mousedown",t=>{t.preventDefault(),t.stopPropagation(),o()}),i.addEventListener("keydown",t=>{"Enter"===t.key&&(t.preventDefault(),o())}),t.appendChild(i),t.appendChild(r),requestAnimationFrame(()=>i.focus())}(t,e,n)}(t,e,{acceptedTypes:this.config.acceptedTypes,locale:this.locale,onFileInsert:(t,e)=>this.handleFileInsert(t,e),onClose:n})}})}isAcceptedType(t){return this.config.acceptedTypes.some(e=>e===t||e.endsWith("/*")&&t.startsWith(e.slice(0,-1)))}isImageSelected(t){const n=t.selection;if(!e(n))return!1;const i=t.getBlock(n.nodeId);return"image"===i?.type}announceImageSelection(t){if(!this.context)return;const n=t.selection;if(!e(n))return;const i=t.getBlock(n.nodeId);if(!i||"image"!==i.type)return;const r=i.attrs?.alt??"",o=i.attrs?.width,a=i.attrs?.height,s=[this.locale.imageSelected];r&&s.push(`${this.locale.altTextPrefix}${r}.`),void 0!==o&&void 0!==a&&s.push(this.locale.imageSizeAnnounce(o,a));const c=this.resolvedKeymap.shrinkWidth??null,l=this.resolvedKeymap.growWidth??null;c&&l&&s.push(this.locale.resizeHint(u(c),u(l))),this.context.announce(s.join(" "))}announceCurrentSize(t){const n=t.getState(),i=n.selection;if(!e(i))return;const r=n.getBlock(i.nodeId);if(!r||"image"!==r.type)return;const o=r.attrs?.width,a=r.attrs?.height;void 0!==o&&void 0!==a&&t.announce(this.locale.imageResized(o,a))}}export{R as DEFAULT_IMAGE_KEYMAP,w as IMAGE_LOCALE_EN,$ as IMAGE_UPLOAD_SERVICE,T as ImagePlugin,y as loadImageLocale};
|
|
1
|
+
import{a as t}from"../chunks/HTMLUtils-Cxy99Ak2.mjs";import{h as e,g as n,b as i}from"../chunks/Selection-DhbizDM4.mjs";import{a as r,g as o,s as a,b as s}from"../chunks/StyleRuntime-BmsLoEa8.mjs";import{c as l}from"../chunks/DomUtils-CznMAZZg.mjs";import{S as c,r as d}from"../chunks/PluginHelpers-CdPR0MuT.mjs";import{f as g}from"../chunks/ShortcutFormatting-BLKS0Gys.mjs";import{d as m}from"../chunks/NodeSelectionCommands-CXrOcPtG.mjs";import{c as u,g as p,n as h}from"../chunks/Document-3pNX7ear.mjs";import{n as f}from"../chunks/TypeBrands-Bp_Z_o5Y.mjs";import{g as b}from"../chunks/Platform-CU6itXZo.mjs";function v(t,r){const o=t.getState(),a=o.selection,s={src:r.src,alt:r.alt??"",align:r.align??"center",...void 0!==r.width?{width:r.width}:{},...void 0!==r.height?{height:r.height}:{}};if(n(a))return!1;const l=e(a)?a.nodeId:a.anchor.blockId,c=function(t,e){const n=t.getBlock(e);if("table_cell"===n?.type)return e;const i=t.getNodePath(e);if(i)for(const r of i){const e=t.getBlock(r);if("table_cell"===e?.type)return r}}(o,l);return c?function(t,e,n,r){const o=t.getNodePath(n);if(!o)return!1;const a=u(f("image"),[],void 0,r),s=t.getBlock(n);if(!s)return!1;const l=t.transaction("command"),c=p(s);for(let i=c.length-1;i>=0;i--){const t=s.children.findIndex(t=>h(t)&&t.id===c[i]?.id);-1!==t&&l.removeNode(o,t)}return l.insertNode(o,0,a),l.setSelection(i(a.id,[...o,a.id])),e.dispatch(l.build()),!0}(o,t,c,s):function(t,e,n,r){const o=t.doc.children.findIndex(t=>t.id===n);if(-1===o)return!1;const a=u(f("image"),[],void 0,r),s=u(f("paragraph")),l=t.transaction("command").insertNode([],o+1,a).insertNode([],o+2,s).setSelection(i(a.id,[])).build();return e.dispatch(l),!0}(o,t,l,s)}function x(t,n,i){const r=t.getState(),o=r.selection;if(!e(o))return!1;const a=r.getBlock(o.nodeId);if(!a||"image"!==a.type)return!1;const s=a.attrs?.width,l=a.attrs?.height;if(void 0===s||void 0===l)return!1;const c=l>0?s/l:1,d=Math.max(50,Math.min(i,s+n)),g=Math.round(d/c);return(d!==s||g!==l)&&function(t,n){const i=t.getState(),r=i.selection;if(!e(r))return!1;const o=i.getBlock(r.nodeId);if(!o||"image"!==o.type)return!1;const a=i.getNodePath(r.nodeId);if(!a)return!1;const s={...o.attrs??{},...n},l=i.transaction("command").setNodeAttr(a,s).build();return t.dispatch(l),!0}(t,{width:d,height:g})}const w={insertImage:"Insert Image",insertImageTooltip:"Insert Image",uploadFromComputer:"Upload from computer",uploadAria:"Upload image from computer",separator:"or",urlPlaceholder:"https://...",urlAria:"Image URL",insertButton:"Insert",insertAria:"Insert image",imageAria:(t,e,n)=>{const i=[t||"Image"];return void 0!==e&&void 0!==n&&i.push(`${e} by ${n} pixels`),i.join(", ")},resetToNaturalSize:"Image reset to natural size.",uploadFailed:"Upload failed.",uploading:"Uploading...",resizeHandleLabel:t=>`Resize ${t}`,imageSelected:"Image selected.",altTextPrefix:"Alt text: ",imageSizeAnnounce:(t,e)=>`Size: ${t} by ${e} pixels.`,resizeHint:(t,e)=>`${t} / ${e} to resize.`,imageResized:(t,e)=>`Image resized to ${t} by ${e} pixels.`,keyboardResizeHint:(t,e)=>`${t} / ${e} to resize`},z=/* @__PURE__ */Object.assign({"./locales/ar.ts":()=>import("../chunks/ar-C5JEHhw9.mjs"),"./locales/de.ts":()=>import("../chunks/de-xJh5C_pk.mjs"),"./locales/es.ts":()=>import("../chunks/es-DvgH3-WZ.mjs"),"./locales/fr.ts":()=>import("../chunks/fr-Ccaetiwi.mjs"),"./locales/hi.ts":()=>import("../chunks/hi-DVof3w0y.mjs"),"./locales/pt.ts":()=>import("../chunks/pt-DlNdH9pu.mjs"),"./locales/ru.ts":()=>import("../chunks/ru-CrbxCeQf.mjs"),"./locales/zh.ts":()=>import("../chunks/zh-C6YALJZt.mjs")});async function y(t){if("en"===t)return w;const e=z[`./locales/${t}.ts`];if(!e)return w;try{return(await e()).default}catch{return w}}const _={start:"notectl-image--start",center:"notectl-image--center",end:"notectl-image--end"},k={nw:"nwse-resize",ne:"nesw-resize",sw:"nesw-resize",se:"nwse-resize"},S={nw:-1,ne:1,sw:-1,se:1},I={nw:"top-left",ne:"top-right",sw:"bottom-left",se:"bottom-right"},L={nw:"top-right",ne:"top-left",sw:"bottom-right",se:"bottom-left"},A={nw:"nesw-resize",ne:"nwse-resize",sw:"nwse-resize",se:"nesw-resize"};function C(t,e,n=w){const i=(e?L:I)[t];return n.resizeHandleLabel(i)}let N=null;function j(){N&&(N.remove(),N=null)}function E(t,e,n,i=w){return(s,l,c)=>{const d=document.createElement("figure");d.className="notectl-image",d.setAttribute("data-block-id",s.id),d.setAttribute("data-void","true"),d.setAttribute("data-selectable","true");const m=document.createElement("div");m.className="notectl-image__container";const u=document.createElement("img");u.className="notectl-image__img",u.draggable=!1;const p=document.createElement("div");p.className="notectl-image__overlay",m.appendChild(u),m.appendChild(p),d.appendChild(m);let h=s.id,f=null;function v(t){const n=t.attrs?.src??"",o=t.attrs?.alt??"",a=t.attrs?.width,s=t.attrs?.height,l=t.attrs?.align??"center";u.src!==n&&(u.src=n),u.alt=o,r(u,"width",void 0!==a?`${a}px`:""),r(u,"height",void 0!==s?`${s}px`:"");for(const e of Object.values(_))d.classList.remove(e);const c=_[l];c&&d.classList.add(c);const g=e.get(t.id)??"idle",m="uploading"===g;p.classList.toggle("notectl-image__overlay--uploading",m),p.classList.toggle("notectl-image__overlay--error","error"===g),p.textContent=m?i.uploading:"error"===g?i.uploadFailed:"",m?d.setAttribute("aria-busy","true"):d.removeAttribute("aria-busy"),function(t){const e=t.attrs?.alt??"",n=t.attrs?.width,r=t.attrs?.height;d.setAttribute("aria-label",i.imageAria(e,n,r))}(t)}v(s);let x=!1;function w(e,n,i,r){let s=0,g=0,m=1,p=S[n];const h=e=>{const n=e.clientX-s,i=(o=g+n*p,Math.max(50,Math.min(t.maxWidth,o)));var o;const l=Math.round(i/m);a(u,{width:`${i}px`,height:`${l}px`}),r.textContent=`${Math.round(i)} × ${l}`},f=t=>{document.removeEventListener("pointermove",h),document.removeEventListener("pointerup",f),d.classList.remove("notectl-image--resizing"),r.classList.remove("notectl-image__size-indicator--visible"),j();const e=Math.round(u.getBoundingClientRect().width),n=Math.round(e/m);!function(t,e,n){const i=l(),r=i.getBlock(t);if(!r)return;const o=r.attrs?.width,a=r.attrs?.height;if(o===e&&a===n)return;const s=i.getNodePath(t);if(!s)return;const d={...r.attrs??{},width:e,height:n},g=i.transaction("command").setNodeAttr(s,d).build();c(g)}(i,e,n),t.target?.releasePointerCapture?.(t.pointerId)};e.addEventListener("pointerdown",t=>{t.preventDefault(),t.stopPropagation();const e="rtl"===b(d);p=function(t,e){const n=S[t];return e?-n:n}(n,e),s=t.clientX,g=u.getBoundingClientRect().width;const i=u.getBoundingClientRect().height;m=i>0?g/i:1,d.classList.add("notectl-image--resizing"),r.textContent=`${Math.round(g)} × ${Math.round(i)}`,r.classList.add("notectl-image__size-indicator--visible"),function(t,e){j(),N=document.createElement("style");const n=e?o(e):void 0;n&&N.setAttribute("nonce",n),N.textContent=`*{cursor:${t}!important;user-select:none!important}`,document.head.appendChild(N)}(e?A[n]:k[n],d),t.target.setPointerCapture(t.pointerId),document.addEventListener("pointermove",h),document.addEventListener("pointerup",f)})}function z(){j(),f&&(f.remove(),f=null)}return u.addEventListener("load",()=>{if(x)return;const e=l(),n=e.getBlock(h);if(!n||"image"!==n.type)return;const i=void 0!==n.attrs?.width,r=void 0!==n.attrs?.height;if(i&&r)return void(x=!0);const o=u.naturalWidth,a=u.naturalHeight;if(0===o||0===a)return;const s=Math.min(o,t.maxWidth),d=o>0?a/o:1,g=Math.round(s*d),m=e.getNodePath(h);if(!m)return;const p={...n.attrs??{},width:s,height:g},f=e.transaction("command").setNodeAttr(m,p).build();c(f),x=!0}),{dom:d,contentDOM:null,update:t=>"image"===t.type&&(h=t.id,d.setAttribute("data-block-id",t.id),v(t),!0),selectNode(){d.classList.add("notectl-image--selected"),function(e){if(!t.resizable||f)return;f=document.createElement("div"),f.className="notectl-image__resize-overlay",f.setAttribute("data-notectl-no-print","");const r=document.createElement("div");r.className="notectl-image__size-indicator",f.appendChild(r);const o="rtl"===b(d),a=["nw","ne","sw","se"];for(const t of a){const n=document.createElement("div");n.className=`notectl-image__resize-handle notectl-image__resize-handle--${t}`,n.setAttribute("role","separator"),n.setAttribute("aria-label",C(t,o,i)),w(n,t,e,r),f.appendChild(n)}if(n){const t=function(t,e){const n=t.shrinkWidth??null,i=t.growWidth??null;return n&&i?e.keyboardResizeHint(g(n),g(i)):""}(n,i);if(t){const e=document.createElement("div");e.className="notectl-image__keyboard-hint",e.setAttribute("aria-hidden","true"),e.textContent=t,f.appendChild(e)}}m.appendChild(f)}(h)},deselectNode(){d.classList.remove("notectl-image--selected"),z()},destroy(){z()}}}}const $=new c("image:upload"),R={growWidth:"Mod-Shift-ArrowRight",shrinkWidth:"Mod-Shift-ArrowLeft",growWidthLarge:"Mod-Shift-Alt-ArrowRight",shrinkWidthLarge:"Mod-Shift-Alt-ArrowLeft",resetSize:"Mod-Shift-0"},M={maxWidth:800,maxFileSize:10485760,acceptedTypes:["image/png","image/jpeg","image/gif","image/webp","image/svg+xml"],resizable:!0,resizeStep:10,resizeStepLarge:50};class T{id="image";name="Image";priority=45;config;resolvedKeymap;uploadStates=/* @__PURE__ */new Map;blobUrls=/* @__PURE__ */new Set;context=null;locale;constructor(t){this.config={...M,...t},this.resolvedKeymap={...R,...t?.keymap}}async init(t){this.locale=await d(t,this.config.locale,w,y),t.registerStyleSheet('\n/* Image */\n.notectl-image {\n\tmargin: 8px 0;\n\tuser-select: none;\n\tline-height: 0;\n}\n\n.notectl-image--center {\n\ttext-align: center;\n}\n\n.notectl-image--start {\n\ttext-align: start;\n}\n\n.notectl-image--end {\n\ttext-align: end;\n}\n\n.notectl-image__container {\n\tdisplay: inline-block;\n\tposition: relative;\n\tline-height: 0;\n}\n\n.notectl-image__img {\n\tdisplay: block;\n\tmax-width: 100%;\n\tborder-radius: 4px;\n}\n\n.notectl-image--selected .notectl-image__container {\n\toutline: 2px solid var(--notectl-primary);\n\toutline-offset: 2px;\n\tborder-radius: 6px;\n}\n\n/* Alignment toolbar (appears on image selection) */\n.notectl-image__align-toolbar {\n\tdisplay: flex;\n\tgap: 2px;\n\tposition: absolute;\n\ttop: -36px;\n\tleft: 50%;\n\ttransform: translateX(-50%);\n\tbackground: var(--notectl-surface-overlay);\n\tborder: 1px solid var(--notectl-border);\n\tborder-radius: 6px;\n\tpadding: 2px;\n\tbox-shadow: 0 2px 8px var(--notectl-shadow);\n\tz-index: 10;\n}\n\n.notectl-image__align-btn {\n\tdisplay: flex;\n\talign-items: center;\n\tjustify-content: center;\n\twidth: 28px;\n\theight: 28px;\n\tborder: none;\n\tbackground: transparent;\n\tborder-radius: 4px;\n\tcursor: pointer;\n\tcolor: var(--notectl-fg);\n}\n\n.notectl-image__align-btn:hover {\n\tbackground: var(--notectl-hover-bg);\n}\n\n.notectl-image__align-btn--active {\n\tbackground: var(--notectl-active-bg);\n\tcolor: var(--notectl-primary-fg);\n}\n\n.notectl-image__align-btn svg {\n\twidth: 16px;\n\theight: 16px;\n\tfill: currentColor;\n}\n\n/* Upload overlay */\n.notectl-image__overlay {\n\tposition: absolute;\n\tinset: 0;\n\tdisplay: none;\n\talign-items: center;\n\tjustify-content: center;\n\tbackground: rgba(255, 255, 255, 0.8);\n\tborder-radius: 4px;\n\tfont-size: 13px;\n\tcolor: var(--notectl-fg-muted);\n}\n\n.notectl-image__overlay--uploading {\n\tdisplay: flex;\n}\n\n.notectl-image__overlay--error {\n\tdisplay: flex;\n\tbackground: var(--notectl-danger-muted);\n\tcolor: var(--notectl-danger);\n}\n\n/* Resize overlay + handles */\n.notectl-image__resize-overlay {\n\tposition: absolute;\n\tinset: 0;\n\tpointer-events: none;\n}\n\n.notectl-image__resize-handle {\n\tposition: absolute;\n\twidth: 10px;\n\theight: 10px;\n\tbackground: var(--notectl-bg);\n\tborder: 2px solid var(--notectl-primary);\n\tborder-radius: 50%;\n\tpointer-events: all;\n\tz-index: 2;\n\ttransition: transform 0.1s, background 0.1s;\n}\n\n.notectl-image__resize-handle:hover {\n\tbackground: var(--notectl-primary);\n\ttransform: scale(1.3);\n}\n\n.notectl-image--resizing .notectl-image__resize-handle {\n\tbackground: var(--notectl-primary);\n}\n\n.notectl-image__resize-handle--nw {\n\ttop: -5px;\n\tinset-inline-start: -5px;\n\tcursor: nwse-resize;\n}\n\n.notectl-image__resize-handle--ne {\n\ttop: -5px;\n\tinset-inline-end: -5px;\n\tcursor: nesw-resize;\n}\n\n.notectl-image__resize-handle--sw {\n\tbottom: -5px;\n\tinset-inline-start: -5px;\n\tcursor: nesw-resize;\n}\n\n.notectl-image__resize-handle--se {\n\tbottom: -5px;\n\tinset-inline-end: -5px;\n\tcursor: nwse-resize;\n}\n\n/* RTL cursor overrides — flip diagonal cursors when in RTL context */\n[dir="rtl"] .notectl-image__resize-handle--nw {\n\tcursor: nesw-resize;\n}\n\n[dir="rtl"] .notectl-image__resize-handle--ne {\n\tcursor: nwse-resize;\n}\n\n[dir="rtl"] .notectl-image__resize-handle--sw {\n\tcursor: nwse-resize;\n}\n\n[dir="rtl"] .notectl-image__resize-handle--se {\n\tcursor: nesw-resize;\n}\n\n/* Size indicator tooltip */\n.notectl-image__size-indicator {\n\tposition: absolute;\n\tbottom: -28px;\n\tleft: 50%;\n\ttransform: translateX(-50%);\n\tpadding: 2px 8px;\n\tbackground: var(--notectl-tooltip-bg);\n\tcolor: var(--notectl-tooltip-fg);\n\tfont-size: 11px;\n\tfont-weight: 500;\n\tborder-radius: 4px;\n\twhite-space: nowrap;\n\tpointer-events: none;\n\topacity: 0;\n\ttransition: opacity 0.15s;\n\tz-index: 3;\n}\n\n.notectl-image__size-indicator--visible {\n\topacity: 1;\n}\n\n/* Keyboard resize hint (shown on selection, hidden during drag) */\n.notectl-image__keyboard-hint {\n\tdisplay: none;\n\tposition: absolute;\n\tbottom: -28px;\n\tleft: 50%;\n\ttransform: translateX(-50%);\n\tpadding: 2px 8px;\n\tfont-size: 11px;\n\tcolor: var(--notectl-fg-muted);\n\twhite-space: nowrap;\n\tpointer-events: none;\n\tz-index: 3;\n}\n\n.notectl-image--selected .notectl-image__keyboard-hint {\n\tdisplay: block;\n}\n\n.notectl-image--resizing .notectl-image__keyboard-hint {\n\tdisplay: none;\n}\n\n/* Resizing feedback */\n.notectl-image--resizing .notectl-image__img {\n\topacity: 0.85;\n}\n'),this.context=t,this.registerNodeSpec(t),this.registerNodeView(t),function(t){t.registerCommand("insertImage",()=>v(t,{src:""})),t.registerCommand("removeImage",()=>function(t){const n=t.getState(),r=n.selection;if(!e(r))return!1;const o=n.getBlock(r.nodeId);if(!o||"image"!==o.type)return!1;const a=n.getNodePath(r.nodeId);if(!a||0===a.length)return!1;const s=m(n,i(r.nodeId,a));return!!s&&(t.dispatch(s),!0)}(t))}(t),this.registerResizeCommands(t),this.registerResizeKeymaps(t),this.registerFileHandler(t),this.registerToolbarItem(t)}destroy(){for(const t of this.blobUrls)URL.revokeObjectURL(t);this.blobUrls.clear(),this.uploadStates.clear(),this.context=null}onStateChange(t,e,n){if(!this.context)return;for(const o of this.uploadStates.keys())e.getBlock(o)||this.uploadStates.delete(o);const i=this.isImageSelected(t),r=this.isImageSelected(e);!i&&r&&this.announceImageSelection(e)}registerNodeSpec(e){const n=this.locale;e.registerNodeSpec({type:"image",group:"block",isVoid:!0,selectable:!0,attrs:{src:{default:""},alt:{default:""},align:{default:"center"}},toDOM(t){const e=l("figure",t.id);e.className="notectl-image",e.setAttribute("data-void","true"),e.setAttribute("data-selectable","true");const i=document.createElement("div");i.className="notectl-image__container";const o=t.attrs?.alt??"",a=t.attrs?.width,s=t.attrs?.height,c=document.createElement("img");c.className="notectl-image__img",c.src=t.attrs?.src??"",c.alt=o,c.draggable=!1,void 0!==a&&r(c,"width",`${a}px`),void 0!==s&&r(c,"height",`${s}px`);const d={start:"notectl-image--start",center:"notectl-image--center",end:"notectl-image--end"}[t.attrs?.align??"center"];return d&&e.classList.add(d),e.setAttribute("aria-label",n.imageAria(o,a,s)),i.appendChild(c),e.appendChild(i),e},toHTML(e){const n=t(e.attrs?.src??""),i=t(e.attrs?.alt??""),r=e.attrs?.width,o=e.attrs?.height;return`<figure><img src="${n}" alt="${i}"${(void 0!==r?` width="${r}"`:"")+(void 0!==o?` height="${o}"`:"")}></figure>`},parseHTML:[{tag:"figure",getAttrs(t){const e=t.querySelector("img");if(!e)return!1;const n={src:e.getAttribute("src")??"",alt:e.getAttribute("alt")??"",align:"center"},i=e.getAttribute("width"),r=e.getAttribute("height");i&&(n.width=Number.parseInt(i,10)),r&&(n.height=Number.parseInt(r,10));const o=t.style?.textAlign??"";return"start"===o||"end"===o||"center"===o?n.align=o:"left"===o?n.align="start":"right"===o?n.align="end":t.classList.contains("notectl-align-start")||t.classList.contains("notectl-align-left")||t.classList.contains("notectl-image--start")||t.classList.contains("notectl-image--left")?n.align="start":t.classList.contains("notectl-align-end")||t.classList.contains("notectl-align-right")||t.classList.contains("notectl-image--end")||t.classList.contains("notectl-image--right")?n.align="end":t.classList.contains("notectl-align-center")&&(n.align="center"),n}},{tag:"img",getAttrs(t){const e={src:t.getAttribute("src")??"",alt:t.getAttribute("alt")??"",align:"center"},n=t.getAttribute("width"),i=t.getAttribute("height");return n&&(e.width=Number.parseInt(n,10)),i&&(e.height=Number.parseInt(i,10)),e}}],sanitize:{tags:["figure","img"],attrs:["src","alt","width","height","class","style"]}})}registerNodeView(t){t.registerNodeView("image",E(this.config,this.uploadStates,this.resolvedKeymap,this.locale))}registerResizeCommands(t){const n=this.config.resizeStep??10,i=this.config.resizeStepLarge??50,r=this.config.maxWidth;t.registerCommand("resizeImageGrow",()=>{const e=x(t,n,r);return e&&this.announceCurrentSize(t),e}),t.registerCommand("resizeImageShrink",()=>{const e=x(t,-n,r);return e&&this.announceCurrentSize(t),e}),t.registerCommand("resizeImageGrowLarge",()=>{const e=x(t,i,r);return e&&this.announceCurrentSize(t),e}),t.registerCommand("resizeImageShrinkLarge",()=>{const e=x(t,-i,r);return e&&this.announceCurrentSize(t),e}),t.registerCommand("resetImageSize",()=>{const n=function(t){const n=t.getState(),i=n.selection;if(!e(i))return!1;const r=n.getBlock(i.nodeId);if(!r||"image"!==r.type)return!1;const o=n.getNodePath(i.nodeId);if(!o)return!1;const a={...r.attrs??{}},s=Object.fromEntries(Object.entries(a).filter(([t])=>"width"!==t&&"height"!==t)),l=n.transaction("command").setNodeAttr(o,s).build();return t.dispatch(l),!0}(t);return n&&t.announce(this.locale.resetToNaturalSize),n})}registerResizeKeymaps(t){const e={},n={growWidth:"resizeImageGrow",shrinkWidth:"resizeImageShrink",growWidthLarge:"resizeImageGrowLarge",shrinkWidthLarge:"resizeImageShrinkLarge",resetSize:"resetImageSize"};for(const[i,r]of Object.entries(n)){const n=this.resolvedKeymap[i]??null;n&&(e[n]=()=>t.executeCommand(r))}Object.keys(e).length>0&&t.registerKeymap(e)}registerFileHandler(t){t.registerFileHandler("image/*",async(e,n)=>!!this.isAcceptedType(e.type)&&(this.handleFileInsert(t,e),!0))}handleFileInsert(t,n){if(n.size>this.config.maxFileSize)return;const i=URL.createObjectURL(n);if(this.blobUrls.add(i),!v(t,{src:i}))return URL.revokeObjectURL(i),void this.blobUrls.delete(i);const r=t.getState().selection;if(!e(r))return;const o=r.nodeId;this.uploadStates.set(o,"uploading"),t.getService($)?this.uploadFile(t,n,o,i):this.uploadStates.set(o,"complete")}async uploadFile(t,e,n,i){const r=t.getService($);if(r)try{const o=await r.upload(e);this.uploadStates.set(n,"complete");const a=t.getState(),s=a.getBlock(n);if(!s)return;const l=a.getNodePath(n);if(!l)return;const c={...s.attrs??{},src:o.url,...void 0!==o.width?{width:o.width}:{},...void 0!==o.height?{height:o.height}:{}},d=a.transaction("command").setNodeAttr(l,c).build();t.dispatch(d),URL.revokeObjectURL(i),this.blobUrls.delete(i)}catch{this.uploadStates.set(n,"error"),t.announce(this.locale.uploadFailed)}}registerToolbarItem(t){t.registerToolbarItem({id:"image",group:"insert",icon:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/></svg>',label:this.locale.insertImage,tooltip:this.locale.insertImageTooltip,command:"insertImage",popupType:"custom",renderPopup:(t,e,n)=>{!function(t,e,n){r(t,"padding","8px"),r(t,"minWidth","240px"),function(t,e,n){const i=document.createElement("input");i.type="file",i.accept=n.acceptedTypes.join(","),s(i,"position:absolute;width:0;height:0;overflow:hidden;opacity:0;");const r=document.createElement("button");r.type="button",r.textContent=n.locale.uploadFromComputer,r.setAttribute("aria-label",n.locale.uploadAria),s(r,"display:block;width:100%;padding:8px 12px;cursor:pointer;text-align:center;box-sizing:border-box;border:1px solid var(--notectl-border);border-radius:4px;background:var(--notectl-surface-raised);color:var(--notectl-fg);"),r.addEventListener("mousedown",t=>{t.preventDefault(),t.stopPropagation(),i.click()}),i.addEventListener("change",()=>{const t=i.files?.[0];t&&(n.onFileInsert(e,t),n.onClose(),e.getContainer().focus())}),t.appendChild(i),t.appendChild(r)}(t,e,n),function(t,e){const n=document.createElement("div");s(n,"display:flex;align-items:center;margin:8px 0;color:var(--notectl-fg-muted);font-size:12px;");const i=document.createElement("span");s(i,"flex:1;height:1px;background:var(--notectl-border);");const r=document.createElement("span");r.textContent=e.separator,s(r,"padding:0 8px;");const o=document.createElement("span");s(o,"flex:1;height:1px;background:var(--notectl-border);"),n.appendChild(i),n.appendChild(r),n.appendChild(o),t.appendChild(n)}(t,n.locale),function(t,e,n){const i=document.createElement("input");i.type="url",i.placeholder=n.locale.urlPlaceholder,i.setAttribute("aria-label",n.locale.urlAria),s(i,"width:100%;padding:6px 8px;box-sizing:border-box;border:1px solid var(--notectl-border);border-radius:4px;background:var(--notectl-bg);color:var(--notectl-fg);");const r=document.createElement("button");r.type="button",r.textContent=n.locale.insertButton,r.setAttribute("aria-label",n.locale.insertAria),s(r,"width:100%;padding:8px 12px;margin-top:4px;cursor:pointer;border:1px solid var(--notectl-border);border-radius:4px;background:var(--notectl-surface-raised);color:var(--notectl-fg);");const o=()=>{const t=i.value.trim();t&&(v(e,{src:t}),n.onClose(),e.getContainer().focus())};r.addEventListener("mousedown",t=>{t.preventDefault(),t.stopPropagation(),o()}),i.addEventListener("keydown",t=>{"Enter"===t.key&&(t.preventDefault(),o())}),t.appendChild(i),t.appendChild(r),requestAnimationFrame(()=>i.focus())}(t,e,n)}(t,e,{acceptedTypes:this.config.acceptedTypes,locale:this.locale,onFileInsert:(t,e)=>this.handleFileInsert(t,e),onClose:n})}})}isAcceptedType(t){return this.config.acceptedTypes.some(e=>e===t||e.endsWith("/*")&&t.startsWith(e.slice(0,-1)))}isImageSelected(t){const n=t.selection;if(!e(n))return!1;const i=t.getBlock(n.nodeId);return"image"===i?.type}announceImageSelection(t){if(!this.context)return;const n=t.selection;if(!e(n))return;const i=t.getBlock(n.nodeId);if(!i||"image"!==i.type)return;const r=i.attrs?.alt??"",o=i.attrs?.width,a=i.attrs?.height,s=[this.locale.imageSelected];r&&s.push(`${this.locale.altTextPrefix}${r}.`),void 0!==o&&void 0!==a&&s.push(this.locale.imageSizeAnnounce(o,a));const l=this.resolvedKeymap.shrinkWidth??null,c=this.resolvedKeymap.growWidth??null;l&&c&&s.push(this.locale.resizeHint(g(l),g(c))),this.context.announce(s.join(" "))}announceCurrentSize(t){const n=t.getState(),i=n.selection;if(!e(i))return;const r=n.getBlock(i.nodeId);if(!r||"image"!==r.type)return;const o=r.attrs?.width,a=r.attrs?.height;void 0!==o&&void 0!==a&&t.announce(this.locale.imageResized(o,a))}}export{R as DEFAULT_IMAGE_KEYMAP,w as IMAGE_LOCALE_EN,$ as IMAGE_UPLOAD_SERVICE,T as ImagePlugin,y as loadImageLocale};
|
|
2
2
|
//# sourceMappingURL=image.mjs.map
|