@phenix1024/editor 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,7 @@
1
1
  import { Extension, Mark, Node } from '@tiptap/core';
2
2
  export declare const Label: Mark<any, any>;
3
+ /** Image node with portable width and text-wrapping attributes. */
4
+ export declare const OphxImage: Node<import("@tiptap/extension-image").ImageOptions, any>;
3
5
  /** Inline template field: its textual value stays editable inside the editor. */
4
6
  export declare const OphxInlineField: Node<any, any>;
5
7
  /** Block template field, accepting the v2 <p> and <div> wrapper forms. */
@@ -1,4 +1,6 @@
1
1
  import { Editor, type Content, type EditorOptions } from '@tiptap/core';
2
+ import { type ToolbarOptions } from './toolbar';
3
+ import { type OphxDocument, type OphxExportOptions } from './ophx-archive';
2
4
  export interface OphxFieldValue {
3
5
  id: string;
4
6
  label: string | null;
@@ -6,20 +8,61 @@ export interface OphxFieldValue {
6
8
  value: string;
7
9
  }
8
10
  export interface OphxEditorOptions {
9
- element: HTMLElement;
11
+ /** Container for the document: an element or a CSS selector. */
12
+ element: HTMLElement | string;
13
+ /**
14
+ * Built-in toolbar container (element or CSS selector). When set, the toolbar is mounted
15
+ * automatically and removed by destroy().
16
+ */
17
+ toolbar?: HTMLElement | string;
18
+ /** Options for the built-in toolbar, e.g. a custom image upload handler. */
19
+ toolbarOptions?: ToolbarOptions;
10
20
  content?: Content;
11
21
  placeholder?: string;
22
+ /** Initial mode when nothing is stored yet. Defaults to true. */
12
23
  editable?: boolean;
24
+ /**
25
+ * localStorage key used to remember the edit/view mode across reloads.
26
+ * Defaults to 'ophx-editor-editable'. Pass null to disable persistence.
27
+ */
28
+ editableStorageKey?: string | null;
13
29
  onUpdate?: EditorOptions['onUpdate'];
14
30
  extensions?: NonNullable<EditorOptions['extensions']>;
15
31
  }
32
+ export interface OphxSetContentOptions {
33
+ /** Emit Tiptap's update event after replacing the document. Defaults to false. */
34
+ emitUpdate?: boolean;
35
+ }
16
36
  /** A framework-neutral Tiptap editor wrapper. UI is intentionally optional. */
17
37
  export declare class OphxEditor {
18
38
  readonly editor: Editor;
39
+ private archiveDefaults;
40
+ private readonly editableStorageKey;
41
+ private unmountToolbar;
19
42
  constructor(options: OphxEditorOptions);
20
43
  getHTML(): string;
21
44
  getJSON(): import("@tiptap/core").DocumentType<Record<string, any> | undefined, import("@tiptap/core").NodeType<string, Record<string, any> | undefined, any, (import("@tiptap/core").NodeType<any, any, any, any> | import("@tiptap/core").TextType<import("@tiptap/core").MarkType<any, any>>)[]>[]>;
22
- setContent(content: Content): void;
45
+ getText(): string;
46
+ get isEmpty(): boolean;
47
+ get isEditable(): boolean;
48
+ setContent(content: Content, options?: OphxSetContentOptions): void;
49
+ clearContent(options?: OphxSetContentOptions): void;
50
+ focus(position?: 'start' | 'end' | 'all' | number): this;
51
+ blur(): this;
52
+ setEditable(editable: boolean): this;
53
+ private readStoredEditable;
54
+ private writeStoredEditable;
55
+ undo(): boolean;
56
+ redo(): boolean;
57
+ canUndo(): boolean;
58
+ canRedo(): boolean;
59
+ private syncEditableControls;
60
+ /** Parse and load an .ophx archive; the archive's metadata becomes the default for saveOphx(). */
61
+ loadOphx(file: Blob): Promise<OphxDocument>;
62
+ /** Create an .ophx archive Blob; callers can persist it or pass it to downloadBlob(). */
63
+ saveOphx(options?: OphxExportOptions): Promise<Blob>;
64
+ /** Trigger a browser download of the current document as an .ophx archive. */
65
+ downloadOphx(options?: OphxExportOptions): Promise<void>;
23
66
  setSearchQuery(query: string): void;
24
67
  getFields(): OphxFieldValue[];
25
68
  getMissingRequiredFields(): OphxFieldValue[];
@@ -1,4 +1,4 @@
1
- import type { Editor } from '@tiptap/core';
1
+ import { type Editor } from '@tiptap/core';
2
2
  export interface ToolbarOptions {
3
3
  onInsertImage?: (file: File) => void;
4
4
  }
@@ -1,5 +1,5 @@
1
1
  import './editor/ophx.css';
2
- export { OphxEditor, type OphxEditorOptions, type OphxFieldValue } from './editor/ophx-editor';
2
+ export { OphxEditor, type OphxEditorOptions, type OphxFieldValue, type OphxSetContentOptions } from './editor/ophx-editor';
3
3
  export { mountToolbar, type ToolbarOptions } from './editor/toolbar';
4
4
  export { exportOphx, importOphx, downloadBlob, type OphxDocument, type OphxExportOptions, } from './editor/ophx-archive';
5
5
  export { CollapsibleHeading, Indentation, Label, OphxBlockField, OphxEditability, OphxInlineField, OphxReadonlyBlock, OphxReadonlyInline, TextSearch, WysiwymRules, isValidOphxFieldId, } from './editor/extensions';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@phenix1024/editor",
3
3
  "private": false,
4
- "version": "0.1.0",
4
+ "version": "0.2.0",
5
5
  "description": "Framework-agnostic WYSIWYM document editor and .ophx archive tools, powered by Tiptap",
6
6
  "license": "MIT",
7
7
  "type": "module",