oasis-editor 0.0.138 → 0.0.139

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/dist/{OasisEditorApp-DMI2ZfOd.js → OasisEditorApp-B1x9P0Ua.js} +50 -8
  2. package/dist/adapters/mountController.d.ts +11 -0
  3. package/dist/adapters/react.d.ts +8 -0
  4. package/dist/adapters/ui.d.ts +1 -1
  5. package/dist/adapters/vue.d.ts +10 -0
  6. package/dist/app/bootstrap/createOasisEditorApp.d.ts +9 -0
  7. package/dist/app/bootstrap/createOasisEditorContainer.d.ts +9 -0
  8. package/dist/app/client/OasisEditorClient.d.ts +254 -1
  9. package/dist/app/client/publicDocumentApi.d.ts +223 -0
  10. package/dist/app/controllers/documentIO/DocumentExporter.d.ts +10 -2
  11. package/dist/app/controllers/documentIO/DocumentImporter.d.ts +6 -0
  12. package/dist/app/controllers/useEditorDocumentIO.d.ts +4 -2
  13. package/dist/app/controllers/useEditorFindReplace.d.ts +7 -0
  14. package/dist/app/controllers/useEditorPersistence.d.ts +10 -0
  15. package/dist/app/services/FindReplaceService.d.ts +9 -0
  16. package/dist/app/services/indexedDbPersistence.d.ts +10 -1
  17. package/dist/app/services/tablePropertiesService.d.ts +12 -3
  18. package/dist/app/services/userPreferences.d.ts +4 -0
  19. package/dist/assets/{importDocxWorker-DBjcGf-C.js → importDocxWorker-B1vHeo5L.js} +1 -1
  20. package/dist/core/Editor.d.ts +33 -1
  21. package/dist/core/commands/CommandBus.d.ts +26 -0
  22. package/dist/core/commands/publicCommandTypes.d.ts +53 -0
  23. package/dist/core/model/types/document.d.ts +2 -0
  24. package/dist/core/plugin.d.ts +60 -0
  25. package/dist/import/DocumentFormatImporter.d.ts +20 -4
  26. package/dist/import/documentImporterRegistry.d.ts +6 -2
  27. package/dist/{index-M7h7REmM.js → index-BVWzLonI.js} +1182 -760
  28. package/dist/index.d.ts +3 -1
  29. package/dist/mountController.d.ts +11 -0
  30. package/dist/oasis-editor.js +44 -36
  31. package/dist/oasis-editor.umd.cjs +4 -4
  32. package/dist/react.d.ts +8 -0
  33. package/dist/ui/OasisEditorAppProps.d.ts +8 -4
  34. package/dist/ui/app/connectEditorClientHost.d.ts +12 -2
  35. package/dist/ui/app/createEditorCommandRuntime.d.ts +8 -1
  36. package/dist/ui/app/createEditorDocumentRuntime.d.ts +4 -2
  37. package/dist/ui/canvas/CanvasDebug.d.ts +15 -1
  38. package/dist/ui/components/Menubar/menuRegistry.d.ts +11 -0
  39. package/dist/ui/components/Toolbar/registry/ToolbarRegistry.d.ts +43 -7
  40. package/dist/ui/components/Toolbar/schema/items.d.ts +39 -7
  41. package/dist/ui/components/Toolbar/state/createToolbarApi.d.ts +8 -4
  42. package/dist/ui.d.ts +1 -1
  43. package/dist/ui.js +29 -30
  44. package/dist/vue.d.ts +10 -0
  45. package/package.json +1 -1
@@ -7,7 +7,7 @@ import { OasisEditor, OasisPlugin } from './plugin.js';
7
7
  * Options accepted by the synchronous `new Editor(...)` path. Plugins are
8
8
  * deliberately absent: they need async initialization and so are only valid via
9
9
  * {@link Editor.create}. Encoding that in the type (rather than a runtime throw)
10
- * makes the precondition checkable at compile time (L1).
10
+ * makes the precondition checkable at compile time.
11
11
  */
12
12
  export interface SynchronousEditorOptions {
13
13
  doc?: EditorDocument;
@@ -20,6 +20,7 @@ export interface SynchronousEditorOptions {
20
20
  export interface EditorCreateOptions extends SynchronousEditorOptions {
21
21
  plugins?: OasisPlugin[];
22
22
  }
23
+ /** Core editor class providing state management, command dispatch, and plugin lifecycle. */
23
24
  export declare class Editor implements OasisEditor {
24
25
  private stateStore;
25
26
  private setState;
@@ -27,14 +28,45 @@ export declare class Editor implements OasisEditor {
27
28
  private listeners;
28
29
  readonly commands: CommandRegistry;
29
30
  readonly ui: PluginUiRegistry;
31
+ /**
32
+ * @param options - Options for synchronous construction (no plugins).
33
+ */
30
34
  constructor(options?: SynchronousEditorOptions);
35
+ /**
36
+ * Creates an editor instance asynchronously, initializing all provided plugins.
37
+ * @param options - Options including plugins to load.
38
+ * @returns A promise that resolves to the initialized editor.
39
+ */
31
40
  static create(options?: EditorCreateOptions): Promise<Editor>;
32
41
  private initializeState;
42
+ /** @returns The current editor state. */
33
43
  get state(): EditorState;
44
+ /**
45
+ * Applies a state updater function and emits a "change:data" event.
46
+ * @param updater - Function that receives the current state and returns the new state.
47
+ */
34
48
  dispatch(updater: (state: EditorState) => EditorState): void;
49
+ /** Destroys the editor, cleaning up plugins, commands, UI, and listeners. */
35
50
  destroy(): Promise<void>;
51
+ /**
52
+ * Subscribes to an event.
53
+ * @param event - The event name.
54
+ * @param callback - The handler to invoke when the event fires.
55
+ * @returns An unsubscribe function.
56
+ */
36
57
  on(event: string, callback: (...args: unknown[]) => void): () => void;
58
+ /**
59
+ * Subscribes to a single emission of an event.
60
+ * @param event - The event name.
61
+ * @param callback - The handler to invoke once.
62
+ * @returns An unsubscribe function.
63
+ */
37
64
  once(event: string, callback: (...args: unknown[]) => void): () => void;
65
+ /**
66
+ * Removes a previously subscribed event handler.
67
+ * @param event - The event name.
68
+ * @param callback - The handler to remove.
69
+ */
38
70
  off(event: string, callback: (...args: unknown[]) => void): void;
39
71
  private emit;
40
72
  private createCommandContext;
@@ -1,9 +1,35 @@
1
1
  import { CommandState, OasisEditor } from '../plugin.js';
2
2
  import { CommandRef } from './CommandRef.js';
3
3
 
4
+ /**
5
+ * Untyped command bus that accepts {@link CommandRef} references. Used
6
+ * internally when command names are known only at runtime.
7
+ * @typeParam TState - The command state type.
8
+ */
4
9
  export interface CommandBus<TState = CommandState> {
10
+ /**
11
+ * Executes a command by reference, with an optional payload override.
12
+ * @param command - The command reference.
13
+ * @param payloadOverride - Optional payload override.
14
+ * @returns The command's result.
15
+ */
5
16
  execute(command: CommandRef, payloadOverride?: unknown): unknown;
17
+ /**
18
+ * @param command - The command reference.
19
+ * @param payloadOverride - Optional payload override.
20
+ * @returns Whether the command can execute.
21
+ */
6
22
  canExecute(command: CommandRef, payloadOverride?: unknown): boolean;
23
+ /**
24
+ * @param command - The command reference.
25
+ * @returns The command's reactive state.
26
+ */
7
27
  state(command: CommandRef): TState;
8
28
  }
29
+ /**
30
+ * Creates a command bus backed by the editor's command registry.
31
+ * The bus resolves command references before delegating to the registry.
32
+ * @param editor - The editor instance.
33
+ * @returns A new CommandBus.
34
+ */
9
35
  export declare function createEditorCommandBus(editor: OasisEditor): CommandBus;
@@ -3,19 +3,27 @@ import { EditorPageMargins } from '../model.js';
3
3
  import { TextCaseMode } from './text.js';
4
4
  import { TableBorderPreset } from './table.js';
5
5
 
6
+ /** Payload for the `insertTable` command. */
6
7
  export interface InsertTablePayload {
7
8
  rows: number;
8
9
  columns: number;
9
10
  }
11
+ /** Payload for the `setFontSize` command. */
10
12
  export interface SetFontSizePayload {
11
13
  size: number | string | null;
12
14
  }
15
+ /** Payload for the `setPageMargins` command. */
13
16
  export interface SetPageMarginsPayload extends Partial<EditorPageMargins> {
14
17
  }
18
+ /** Payload for the `setSpecialIndent` command. */
15
19
  export interface SetSpecialIndentPayload {
16
20
  kind: "none" | "firstLine" | "hanging";
17
21
  value?: number | null;
18
22
  }
23
+ /**
24
+ * Maps every built-in command name to its expected payload type.
25
+ * Commands with `undefined` payload accept no arguments.
26
+ */
19
27
  export interface OasisCommandPayloads {
20
28
  selectAll: undefined;
21
29
  insertFootnote: undefined;
@@ -126,17 +134,62 @@ export interface OasisCommandPayloads {
126
134
  tableDistributeRows: undefined;
127
135
  insertTable: InsertTablePayload;
128
136
  }
137
+ /** Maps commands to their typed return values. Commands not listed return `unknown`. */
129
138
  export interface OasisCommandResults {
130
139
  documentStyles: unknown;
131
140
  [command: string]: unknown;
132
141
  }
142
+ /** A valid built-in command name. */
133
143
  export type OasisCommandName = keyof OasisCommandPayloads & string;
144
+ /**
145
+ * Infers the argument tuple for a typed command based on its payload type.
146
+ * @typeParam TCommand - The command name.
147
+ */
134
148
  export type CommandPayloadArgs<TCommand extends OasisCommandName> = OasisCommandPayloads[TCommand] extends undefined ? [payload?: undefined] : [payload: OasisCommandPayloads[TCommand]];
149
+ /**
150
+ * Typed command bus that provides type-safe execute/canExecute/state methods
151
+ * for built-in commands, while also accepting runtime {@link CommandRef} overloads.
152
+ * @typeParam TState - The command state type.
153
+ */
135
154
  export interface TypedCommandBus<TState> {
155
+ /**
156
+ * Type-safe execute for known commands.
157
+ * @param command - The command name.
158
+ * @param args - The command payload.
159
+ * @returns The command result.
160
+ */
136
161
  execute<TCommand extends OasisCommandName>(command: TCommand, ...args: CommandPayloadArgs<TCommand>): TCommand extends keyof OasisCommandResults ? OasisCommandResults[TCommand] : unknown;
162
+ /**
163
+ * Runtime execute via CommandRef.
164
+ * @param command - The command reference.
165
+ * @param payloadOverride - Optional payload override.
166
+ * @returns The command result.
167
+ */
137
168
  execute(command: CommandRef, payloadOverride?: unknown): unknown;
169
+ /**
170
+ * Type-safe canExecute for known commands.
171
+ * @param command - The command name.
172
+ * @param args - The command payload.
173
+ * @returns Whether the command can execute.
174
+ */
138
175
  canExecute<TCommand extends OasisCommandName>(command: TCommand, ...args: CommandPayloadArgs<TCommand>): boolean;
176
+ /**
177
+ * Runtime canExecute via CommandRef.
178
+ * @param command - The command reference.
179
+ * @param payloadOverride - Optional payload override.
180
+ * @returns Whether the command can execute.
181
+ */
139
182
  canExecute(command: CommandRef, payloadOverride?: unknown): boolean;
183
+ /**
184
+ * Type-safe state for known commands.
185
+ * @param command - The command name.
186
+ * @returns The command state.
187
+ */
140
188
  state<TCommand extends OasisCommandName>(command: TCommand): TState;
189
+ /**
190
+ * Runtime state via CommandRef.
191
+ * @param command - The command reference.
192
+ * @returns The command state.
193
+ */
141
194
  state(command: CommandRef): TState;
142
195
  }
@@ -138,6 +138,8 @@ export interface EditorEndnotes {
138
138
  continuationSeparator?: EditorBlockNode[];
139
139
  }
140
140
  export interface EditorDocument {
141
+ /** Serialized document schema revision. Missing values are treated as v1. */
142
+ schemaVersion?: number;
141
143
  id: string;
142
144
  pageSettings?: EditorPageSettings;
143
145
  sections?: EditorSection[];
@@ -3,7 +3,9 @@ import { EditorState } from './model.js';
3
3
  import { CommandRef } from './commands/CommandRef.js';
4
4
  import { RibbonGroupResizePolicy, RibbonRow, RibbonSize, RibbonTabId } from './pluginUiTypes.js';
5
5
 
6
+ /** Function signature for unsubscribing from a subscription. */
6
7
  export type Unsubscribe = () => void;
8
+ /** Context passed to command execution and refresh callbacks. */
7
9
  export interface OasisCommandContext {
8
10
  editor: OasisEditor;
9
11
  commands: OasisCommandRegistry;
@@ -12,24 +14,62 @@ export interface OasisCommandContext {
12
14
  getDocument(): EditorState["document"];
13
15
  getSelection(): EditorState["selection"];
14
16
  }
17
+ /**
18
+ * A single command — an action that can be executed and optionally refreshed for state.
19
+ * @typeParam TPayload - The command's payload type.
20
+ * @typeParam TResult - The command's result type.
21
+ */
15
22
  export interface OasisCommand<TPayload = unknown, TResult = unknown> {
16
23
  execute: (payload?: TPayload, context?: OasisCommandContext) => TResult;
17
24
  refresh?: (payload?: TPayload, context?: OasisCommandContext) => CommandState;
18
25
  }
26
+ /** Registry for named commands, providing register, lookup, execution, and state queries. */
19
27
  export interface OasisCommandRegistry {
28
+ /**
29
+ * Registers a command by name.
30
+ * @param name - The command name.
31
+ * @param command - The command implementation.
32
+ */
20
33
  register: <TPayload = unknown, TResult = unknown>(name: string, command: OasisCommand<TPayload, TResult>) => void;
34
+ /** @param name - The command name to unregister. */
21
35
  unregister: (name: string) => void;
36
+ /**
37
+ * @param name - The command name.
38
+ * @returns The command implementation, or undefined.
39
+ */
22
40
  get: (name: string) => OasisCommand | undefined;
41
+ /**
42
+ * @param name - The command name.
43
+ * @returns Whether the command is registered.
44
+ */
23
45
  has: (name: string) => boolean;
46
+ /**
47
+ * Executes a registered command.
48
+ * @param name - The command name.
49
+ * @param payload - Optional payload.
50
+ * @returns The command's result.
51
+ */
24
52
  execute: <TPayload = unknown, TResult = unknown>(name: string, payload?: TPayload) => TResult;
53
+ /**
54
+ * @param name - The command name.
55
+ * @param payload - Optional payload.
56
+ * @returns Whether the command can execute in the current state.
57
+ */
25
58
  canExecute: (name: string, payload?: unknown) => boolean;
59
+ /**
60
+ * @param name - The command name.
61
+ * @param payload - Optional payload.
62
+ * @returns The command's reactive state.
63
+ */
26
64
  state: (name: string, payload?: unknown) => CommandState;
27
65
  }
66
+ /** Reactive state of a command: whether it is enabled, active, and any associated value. */
28
67
  export interface CommandState {
29
68
  isEnabled: boolean;
30
69
  isActive?: boolean;
31
70
  value?: unknown;
32
71
  }
72
+ /** Core editor interface exposed to plugins and the runtime. */
33
73
  export interface OasisEditor {
34
74
  readonly state: EditorState;
35
75
  readonly commands: OasisCommandRegistry;
@@ -38,7 +78,13 @@ export interface OasisEditor {
38
78
  once: (event: string, callback: (...args: unknown[]) => void) => Unsubscribe;
39
79
  off: (event: string, callback: (...args: unknown[]) => void) => void;
40
80
  }
81
+ /** A plugin reference — either a plugin name string or a plugin instance. */
41
82
  export type PluginReference = string | OasisPlugin;
83
+ /**
84
+ * Toolbar/menu contribution descriptor. Contributions dispatch exclusively
85
+ * through the command registry — register the command in `commands`, then
86
+ * reference it here by name. There is no inline-callback escape hatch.
87
+ */
42
88
  export interface PluginAction {
43
89
  id: string;
44
90
  command: CommandRef;
@@ -50,14 +96,18 @@ export interface PluginAction {
50
96
  ribbonGroupResize?: RibbonGroupResizePolicy;
51
97
  order?: number;
52
98
  }
99
+ /** Menu item contribution extending {@link PluginAction} with path, shortcut, and separator. */
53
100
  export interface PluginMenuItem extends PluginAction {
54
101
  path: string;
55
102
  shortcut?: string;
56
103
  separator?: boolean;
57
104
  labelKey?: string;
58
105
  }
106
+ /** Whether a floating action is scoped to the editor container or the viewport. */
59
107
  export type FloatingActionScope = "container" | "viewport";
108
+ /** Placement options for floating action buttons. */
60
109
  export type FloatingActionPlacement = "bottom-right" | "bottom-left" | "top-right" | "top-left";
110
+ /** Contribution descriptor for a floating action button. */
61
111
  export interface FloatingActionContribution extends PluginAction {
62
112
  label?: string;
63
113
  labelKey?: string;
@@ -66,11 +116,14 @@ export interface FloatingActionContribution extends PluginAction {
66
116
  placement?: FloatingActionPlacement;
67
117
  order?: number;
68
118
  }
119
+ /** How a side panel is displayed: docked alongside the editor or overlaid on top. */
69
120
  export type SidePanelMode = "dock" | "overlay";
121
+ /** Extended render context passed to UI contributions. */
70
122
  export interface PluginUiRenderContext extends OasisCommandContext {
71
123
  panelId?: string;
72
124
  closePanel?: () => void;
73
125
  }
126
+ /** Contribution descriptor for a side panel added by a plugin. */
74
127
  export interface SidePanelContribution {
75
128
  id: string;
76
129
  title: string;
@@ -81,15 +134,18 @@ export interface SidePanelContribution {
81
134
  order?: number;
82
135
  render: (context: PluginUiRenderContext) => JSX.Element;
83
136
  }
137
+ /** UI contributions a plugin can provide: floating actions and side panels. */
84
138
  export interface OasisPluginUiContributions {
85
139
  floatingActions?: FloatingActionContribution[];
86
140
  sidePanels?: SidePanelContribution[];
87
141
  }
142
+ /** Snapshot of the current plugin UI state. */
88
143
  export interface OasisPluginUiSnapshot {
89
144
  floatingActions: FloatingActionContribution[];
90
145
  sidePanels: SidePanelContribution[];
91
146
  activeSidePanelId: string | null;
92
147
  }
148
+ /** Registry for plugin-contributed UI elements. */
93
149
  export interface OasisPluginUiRegistry {
94
150
  registerFloatingAction(contribution: FloatingActionContribution): Unsubscribe;
95
151
  registerSidePanel(contribution: SidePanelContribution): Unsubscribe;
@@ -99,6 +155,10 @@ export interface OasisPluginUiRegistry {
99
155
  getSnapshot(): OasisPluginUiSnapshot;
100
156
  onChange(callback: () => void): Unsubscribe;
101
157
  }
158
+ /**
159
+ * An Oasis editor plugin. Plugins extend the editor with custom commands,
160
+ * keymaps, toolbar items, menu items, and UI contributions.
161
+ */
102
162
  export interface OasisPlugin {
103
163
  name: string;
104
164
  requires?: PluginReference[];
@@ -6,21 +6,37 @@ import { EditorDocument } from '../core/model.js';
6
6
  * specific file format.
7
7
  */
8
8
  export type ImportStage = "opening" | "parsing" | "finishing";
9
+ /**
10
+ * Callback type for reporting import progress.
11
+ * @param stage - The current import stage.
12
+ * @param progress - Optional progress fraction (0-1).
13
+ */
9
14
  export type ImportProgressReporter = (stage: ImportStage, progress?: number) => void;
10
15
  /**
11
16
  * A pluggable document format importer. Adding support for a new format means
12
17
  * implementing this interface and registering it — no consumer of the import
13
- * pipeline (controller, UI) needs to change (Open/Closed, Dependency Inversion).
18
+ * pipeline (controller, UI) needs to change.
14
19
  */
15
20
  export interface DocumentFormatImporter {
16
21
  /** Stable identifier, e.g. "docx" or "html". */
17
22
  readonly id: string;
18
23
  /** File extensions handled, lowercase and dot-prefixed, e.g. [".html", ".htm"]. */
19
24
  readonly accept: readonly string[];
20
- /** Whether this importer can handle the given file (by extension). */
25
+ /**
26
+ * @param file - The file to check.
27
+ * @returns Whether this importer can handle the given file (by extension).
28
+ */
21
29
  matches(file: File): boolean;
22
- /** Parse the raw bytes into an editor document. */
30
+ /**
31
+ * Parse the raw bytes into an editor document.
32
+ * @param buffer - The file contents as an ArrayBuffer.
33
+ * @param onProgress - Optional progress reporter.
34
+ * @returns The parsed document.
35
+ */
23
36
  import(buffer: ArrayBuffer, onProgress?: ImportProgressReporter): Promise<EditorDocument>;
24
37
  }
25
- /** Returns the lowercase dot-extension of a file name, e.g. ".html". */
38
+ /**
39
+ * @param fileName - The file name.
40
+ * @returns The lowercase dot-extension of a file name, e.g. ".html".
41
+ */
26
42
  export declare function fileExtension(fileName: string): string;
@@ -1,6 +1,10 @@
1
1
  import { DocumentFormatImporter } from './DocumentFormatImporter.js';
2
2
 
3
- /** Finds the importer that can handle the given file, if any. */
3
+ /**
4
+ * Finds the importer that can handle the given file.
5
+ * @param file - The file to check.
6
+ * @returns The matching importer, or undefined.
7
+ */
4
8
  export declare function resolveImporterForFile(file: File): DocumentFormatImporter | undefined;
5
- /** Comma-separated extension list for an `<input type="file" accept>`. */
9
+ /** @returns A comma-separated extension list for an `<input type="file" accept>`. */
6
10
  export declare function importFileAccept(): string;