@phenix1024/editor 0.0.0-stage → 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.
- package/LICENSE +21 -0
- package/README.md +283 -2
- package/dist/ophx-editor.cjs +59 -0
- package/dist/ophx-editor.css +2 -0
- package/dist/ophx-editor.iife.js +207 -0
- package/dist/ophx-editor.iife.js.map +1 -0
- package/dist/ophx-editor.js +1360 -0
- package/dist/ophx-editor.standalone.js +21084 -0
- package/dist/ophx-editor.standalone.js.map +1 -0
- package/dist/types/editor/extensions.d.ts +30 -0
- package/dist/types/editor/ophx-archive.d.ts +27 -0
- package/dist/types/editor/ophx-editor.d.ts +70 -0
- package/dist/types/editor/ophx.css.d.ts +2 -0
- package/dist/types/editor/template-fields.d.ts +7 -0
- package/dist/types/editor/toolbar.d.ts +6 -0
- package/dist/types/index.d.ts +6 -0
- package/package.json +81 -4
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Extension, Mark, Node } from '@tiptap/core';
|
|
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>;
|
|
5
|
+
/** Inline template field: its textual value stays editable inside the editor. */
|
|
6
|
+
export declare const OphxInlineField: Node<any, any>;
|
|
7
|
+
/** Block template field, accepting the v2 <p> and <div> wrapper forms. */
|
|
8
|
+
export declare const OphxBlockField: Node<any, any>;
|
|
9
|
+
/** Preserves a readonly inline span while allowing editable field descendants. */
|
|
10
|
+
export declare const OphxReadonlyInline: Mark<any, any>;
|
|
11
|
+
/** A readonly block container can still contain nested editable template fields. */
|
|
12
|
+
export declare const OphxReadonlyBlock: Node<any, any>;
|
|
13
|
+
export declare const CollapsibleHeading: Node<import("@tiptap/extension-heading").HeadingOptions, any>;
|
|
14
|
+
type SearchStorage = {
|
|
15
|
+
query: string;
|
|
16
|
+
};
|
|
17
|
+
declare module '@tiptap/core' {
|
|
18
|
+
interface Commands<ReturnType> {
|
|
19
|
+
ophxSearch: {
|
|
20
|
+
setSearchQuery: (query: string) => ReturnType;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export declare const TextSearch: Extension<SearchStorage, any>;
|
|
25
|
+
export declare const WysiwymRules: Extension<any, any>;
|
|
26
|
+
export declare const Indentation: Extension<any, any>;
|
|
27
|
+
/** Retains v2 contenteditable overrides on schema nodes and marks. */
|
|
28
|
+
export declare const OphxEditability: Extension<any, any>;
|
|
29
|
+
export declare function isValidOphxFieldId(value: string): boolean;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface OphxDocument {
|
|
2
|
+
/** Sanitized body HTML ready for the Tiptap schema. */
|
|
3
|
+
html: string;
|
|
4
|
+
title: string;
|
|
5
|
+
/** Basename of the required root-level HTML entry, without extension. */
|
|
6
|
+
filename: string;
|
|
7
|
+
/** Local stylesheet files keyed by their exact archive filename. */
|
|
8
|
+
styles: Record<string, string>;
|
|
9
|
+
/** Convenience alias for the first stylesheet, if present. */
|
|
10
|
+
css: string;
|
|
11
|
+
bodyContentEditable?: 'true' | 'false';
|
|
12
|
+
}
|
|
13
|
+
export interface OphxExportOptions {
|
|
14
|
+
/** Basename used for both the outer .ophx file and the root-level HTML file. */
|
|
15
|
+
filename?: string;
|
|
16
|
+
title?: string;
|
|
17
|
+
/** Flat stylesheet filenames mapped to CSS source. */
|
|
18
|
+
styles?: Record<string, string>;
|
|
19
|
+
/** Files for already-referenced local image names, keyed by exact archive filename. */
|
|
20
|
+
assets?: Record<string, Blob | Uint8Array | ArrayBuffer>;
|
|
21
|
+
bodyContentEditable?: 'true' | 'false';
|
|
22
|
+
}
|
|
23
|
+
/** Creates a v2 .ophx ZIP using only flat, UTF-8-named STORE/DEFLATE entries. */
|
|
24
|
+
export declare function exportOphx(html: string, options?: OphxExportOptions): Promise<Blob>;
|
|
25
|
+
/** Reads only current v2 archives; legacy non-ZIP/XML formats are rejected. */
|
|
26
|
+
export declare function importOphx(file: Blob): Promise<OphxDocument>;
|
|
27
|
+
export declare function downloadBlob(blob: Blob, filename: string): void;
|
|
@@ -0,0 +1,70 @@
|
|
|
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';
|
|
4
|
+
export interface OphxFieldValue {
|
|
5
|
+
id: string;
|
|
6
|
+
label: string | null;
|
|
7
|
+
required: boolean;
|
|
8
|
+
value: string;
|
|
9
|
+
}
|
|
10
|
+
export interface OphxEditorOptions {
|
|
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;
|
|
20
|
+
content?: Content;
|
|
21
|
+
placeholder?: string;
|
|
22
|
+
/** Initial mode when nothing is stored yet. Defaults to true. */
|
|
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;
|
|
29
|
+
onUpdate?: EditorOptions['onUpdate'];
|
|
30
|
+
extensions?: NonNullable<EditorOptions['extensions']>;
|
|
31
|
+
}
|
|
32
|
+
export interface OphxSetContentOptions {
|
|
33
|
+
/** Emit Tiptap's update event after replacing the document. Defaults to false. */
|
|
34
|
+
emitUpdate?: boolean;
|
|
35
|
+
}
|
|
36
|
+
/** A framework-neutral Tiptap editor wrapper. UI is intentionally optional. */
|
|
37
|
+
export declare class OphxEditor {
|
|
38
|
+
readonly editor: Editor;
|
|
39
|
+
private archiveDefaults;
|
|
40
|
+
private readonly editableStorageKey;
|
|
41
|
+
private unmountToolbar;
|
|
42
|
+
constructor(options: OphxEditorOptions);
|
|
43
|
+
getHTML(): string;
|
|
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>>)[]>[]>;
|
|
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>;
|
|
66
|
+
setSearchQuery(query: string): void;
|
|
67
|
+
getFields(): OphxFieldValue[];
|
|
68
|
+
getMissingRequiredFields(): OphxFieldValue[];
|
|
69
|
+
destroy(): void;
|
|
70
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export interface UnderscoreFieldConversion {
|
|
2
|
+
html: string;
|
|
3
|
+
count: number;
|
|
4
|
+
ids: string[];
|
|
5
|
+
}
|
|
6
|
+
/** Replaces each run of two or more underscores in editable text with an empty v2 field. */
|
|
7
|
+
export declare function convertUnderscoresToFields(html: string, prefix?: string): UnderscoreFieldConversion;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Editor } from '@tiptap/core';
|
|
2
|
+
export interface ToolbarOptions {
|
|
3
|
+
onInsertImage?: (file: File) => void;
|
|
4
|
+
}
|
|
5
|
+
/** Mounts an optional accessible toolbar; consumers can provide their own UI instead. */
|
|
6
|
+
export declare function mountToolbar(host: HTMLElement, editor: Editor, options?: ToolbarOptions): () => void;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import './editor/ophx.css';
|
|
2
|
+
export { OphxEditor, type OphxEditorOptions, type OphxFieldValue, type OphxSetContentOptions } from './editor/ophx-editor';
|
|
3
|
+
export { mountToolbar, type ToolbarOptions } from './editor/toolbar';
|
|
4
|
+
export { exportOphx, importOphx, downloadBlob, type OphxDocument, type OphxExportOptions, } from './editor/ophx-archive';
|
|
5
|
+
export { CollapsibleHeading, Indentation, Label, OphxBlockField, OphxEditability, OphxInlineField, OphxReadonlyBlock, OphxReadonlyInline, TextSearch, WysiwymRules, isValidOphxFieldId, } from './editor/extensions';
|
|
6
|
+
export { convertUnderscoresToFields, type UnderscoreFieldConversion } from './editor/template-fields';
|
package/package.json
CHANGED
|
@@ -1,6 +1,83 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phenix1024/editor",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"private": false,
|
|
4
|
+
"version": "0.2.0",
|
|
5
|
+
"description": "Framework-agnostic WYSIWYM document editor and .ophx archive tools, powered by Tiptap",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./dist/ophx-editor.cjs",
|
|
9
|
+
"module": "./dist/ophx-editor.js",
|
|
10
|
+
"types": "./dist/types/index.d.ts",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"README.md",
|
|
14
|
+
"LICENSE"
|
|
15
|
+
],
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/types/index.d.ts",
|
|
19
|
+
"import": "./dist/ophx-editor.js",
|
|
20
|
+
"require": "./dist/ophx-editor.cjs"
|
|
21
|
+
},
|
|
22
|
+
"./style.css": "./dist/ophx-editor.css",
|
|
23
|
+
"./standalone": {
|
|
24
|
+
"import": "./dist/ophx-editor.standalone.js",
|
|
25
|
+
"default": "./dist/ophx-editor.iife.js"
|
|
26
|
+
},
|
|
27
|
+
"./package.json": "./package.json"
|
|
28
|
+
},
|
|
29
|
+
"unpkg": "./dist/ophx-editor.iife.js",
|
|
30
|
+
"jsdelivr": "./dist/ophx-editor.iife.js",
|
|
31
|
+
"sideEffects": [
|
|
32
|
+
"**/*.css"
|
|
33
|
+
],
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
},
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "git+https://github.com/mars102/pluginEditor.git"
|
|
40
|
+
},
|
|
41
|
+
"homepage": "https://github.com/mars102/pluginEditor#readme",
|
|
42
|
+
"bugs": {
|
|
43
|
+
"url": "https://github.com/mars102/pluginEditor/issues"
|
|
44
|
+
},
|
|
45
|
+
"keywords": [
|
|
46
|
+
"tiptap",
|
|
47
|
+
"editor",
|
|
48
|
+
"wysiwyg",
|
|
49
|
+
"wysiwym",
|
|
50
|
+
"ophx",
|
|
51
|
+
"document-editor"
|
|
52
|
+
],
|
|
53
|
+
"author": "mars102",
|
|
54
|
+
"scripts": {
|
|
55
|
+
"dev": "vite",
|
|
56
|
+
"build": "rm -rf dist dist-demo && npm run typecheck && vite build --config vite.config.ts && tsc -p tsconfig.types.json && node scripts/copy-css-types.mjs && vite build --config vite.lib.config.ts && vite build --config vite.standalone.config.ts && rm -f dist/favicon.svg dist/icons.svg",
|
|
57
|
+
"build:demo": "vite build --config vite.config.ts",
|
|
58
|
+
"build:lib": "rm -rf dist && npm run typecheck && tsc -p tsconfig.types.json && node scripts/copy-css-types.mjs && vite build --config vite.lib.config.ts && vite build --config vite.standalone.config.ts && rm -f dist/favicon.svg dist/icons.svg",
|
|
59
|
+
"preview": "vite preview",
|
|
60
|
+
"typecheck": "tsc --noEmit",
|
|
61
|
+
"prepare": "npm run build:lib",
|
|
62
|
+
"prepublishOnly": "npm run build:lib"
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"typescript": "~7.0.2",
|
|
66
|
+
"vite": "^8.3.6"
|
|
67
|
+
},
|
|
68
|
+
"dependencies": {
|
|
69
|
+
"@tiptap/core": "^3.33.0",
|
|
70
|
+
"@tiptap/extension-heading": "^3.33.0",
|
|
71
|
+
"@tiptap/extension-image": "^3.33.0",
|
|
72
|
+
"@tiptap/extension-link": "^3.33.0",
|
|
73
|
+
"@tiptap/extension-placeholder": "^3.33.0",
|
|
74
|
+
"@tiptap/extension-table": "^3.33.0",
|
|
75
|
+
"@tiptap/extension-table-cell": "^3.33.0",
|
|
76
|
+
"@tiptap/extension-table-header": "^3.33.0",
|
|
77
|
+
"@tiptap/extension-table-row": "^3.33.0",
|
|
78
|
+
"@tiptap/extension-underline": "^3.33.0",
|
|
79
|
+
"@tiptap/pm": "^3.33.0",
|
|
80
|
+
"@tiptap/starter-kit": "^3.33.0",
|
|
81
|
+
"jszip": "^3.10.2"
|
|
82
|
+
}
|
|
83
|
+
}
|