open-text-editor-latest 1.0.1 → 1.0.3

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 CHANGED
@@ -1,16 +1,93 @@
1
- # React + Vite
1
+ # Open Text Editor
2
2
 
3
- This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
3
+ A lightweight, pluggable React contentEditable rich text editor.
4
4
 
5
- Currently, two official plugins are available:
5
+ Quick start and full usage are in `docs/USAGE.md`. Short summary:
6
6
 
7
- - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) (or [oxc](https://oxc.rs) when used in [rolldown-vite](https://vite.dev/guide/rolldown)) for Fast Refresh
8
- - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
7
+ # Open Text Editor
9
8
 
10
- ## React Compiler
9
+ A lightweight, pluggable React contentEditable rich text editor.
11
10
 
12
- The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
11
+ Quick start and full usage are in [docs/USAGE.md](docs/USAGE.md). Below is a concise summary for using the `OpenTextEditor` component exported by this package.
13
12
 
14
- ## Expanding the ESLint configuration
13
+ **Install**
15
14
 
16
- If you are developing a production application, we recommend using TypeScript with type-aware lint rules enabled. Check out the [TS template](https://github.com/vitejs/vite/tree/main/packages/create-vite/template-react-ts) for information on how to integrate TypeScript and [`typescript-eslint`](https://typescript-eslint.io) in your project.
15
+ ```bash
16
+ npm install open-text-editor-latest
17
+ ```
18
+
19
+ **Peer dependencies**
20
+
21
+ This package requires React as a peer dependency (supported: `^18 || ^19`). Install them if your project doesn't already include React:
22
+
23
+ ```bash
24
+ npm install react@^18 react-dom@^18
25
+ # or for React 19 consumers:
26
+ npm install react@^19 react-dom@^19
27
+ ```
28
+
29
+ **Basic usage**
30
+
31
+ ```jsx
32
+ import React, { useRef } from 'react'
33
+ import OpenTextEditor from 'open-text-editor-latest'
34
+
35
+ function App(){
36
+ const editorRef = useRef(null)
37
+
38
+ return (
39
+ <OpenTextEditor
40
+ ref={editorRef}
41
+ initialValue={`<p>Hello from OpenTextEditor</p>`}
42
+ onChange={(html) => console.log('content changed', html)}
43
+ placeholder="Start typing..."
44
+ />
45
+ )
46
+ }
47
+
48
+ export default App
49
+ ```
50
+
51
+ **Imperative API (via `ref`)**
52
+
53
+ The editor exposes useful helpers when mounted with `ref`:
54
+
55
+ - `focus()` — focus the editor
56
+ - `getHtml()` — return current editor HTML
57
+ - `setHtml(html)` — replace editor content
58
+ - `insertHtml(html)` — insert HTML at the current selection
59
+ - `execCommand(command, value)` — run low-level `document.execCommand`
60
+ - `insertTable(rows, cols)` — insert a table programmatically
61
+ - `tableAction(action)` — run table actions when a table cell is active
62
+
63
+ **Build and publish**
64
+
65
+ To build the library bundles (ESM/CJS/UMD):
66
+
67
+ ```bash
68
+ npm run build:lib
69
+ ```
70
+
71
+ Create a local package tarball for testing:
72
+
73
+ ```bash
74
+ npm pack
75
+ ```
76
+
77
+ Publish to npm (when ready):
78
+
79
+ ```bash
80
+ npm publish --access public
81
+ ```
82
+
83
+ See [docs/USAGE.md](docs/USAGE.md) and [docs/PUBLISH.md](docs/PUBLISH.md) for more details on configuration, plugins and publishing.
84
+
85
+ ---
86
+
87
+ Project files of interest:
88
+
89
+ - `src/editor/OpentextEditor.jsx` — main editor component (default export `OpenTextEditor`).
90
+ - `src/editor/plugins/` — plugin scaffolding and built-in plugin placeholders.
91
+ - `build/vite.lib.config.js` — library build configuration used by `npm run build:lib`.
92
+
93
+ If you'd like, I can wire the plugin registration API into the editor so built-in plugins are auto-registered.
package/docs/PUBLISH.md CHANGED
@@ -1,27 +1,31 @@
1
1
  # Publishing to npm
2
2
 
3
- Steps to publish a new version of `open-text-editor`:
3
+ Steps to publish a new version of `open-text-editor-latest`:
4
4
 
5
- 1. Update version in `package.json` (semver).
6
- 2. Commit your changes and push to the repository.
5
+ 1. Update `version` in `package.json` (follow semver).
6
+ 2. Commit your changes and push to your git repository.
7
7
  3. Ensure you are logged in to npm: `npm login`.
8
- 4. Run the build script (prepare runs automatically for `npm publish`):
8
+ 4. Build the library (the `prepare` step is run automatically by `npm publish`, but you can run it manually to verify):
9
9
 
10
10
  ```bash
11
11
  npm run build:lib
12
12
  ```
13
13
 
14
- 5. Publish:
14
+ 5. Publish to npm (public package):
15
15
 
16
16
  ```bash
17
17
  npm publish --access public
18
18
  ```
19
19
 
20
- Notes:
21
- - The library build externalizes `react` and `react-dom` so they are peer dependencies. Consumers must install React separately.
22
- - If you want to test a local tarball before publishing:
20
+ Notes
21
+ - The library build externalizes `react` and `react-dom`; they are declared as peer dependencies. Consumers must install React separately.
22
+ - To test a local tarball before publishing, run:
23
23
 
24
24
  ```bash
25
25
  npm pack
26
- npm install -g ./open-text-editor-0.1.0.tgz
26
+ # then install the produced tarball in another project (replace <version>):
27
+ npm install ./open-text-editor-latest-<version>.tgz
27
28
  ```
29
+
30
+ - If you encounter npm tag/version errors (for example when attempting to publish a lower version than already published), either bump the package version in `package.json` or publish with an explicit tag: `npm publish --tag next --access public`.
31
+
package/docs/USAGE.md ADDED
@@ -0,0 +1,81 @@
1
+ Open Text Editor — Usage
2
+
3
+ Install
4
+
5
+ ```bash
6
+ npm install open-text-editor-latest
7
+ ```
8
+
9
+ Basic usage
10
+
11
+ ```jsx
12
+ import React, { useRef } from 'react'
13
+ import OpenTextEditor from 'open-text-editor-latest'
14
+
15
+ export default function App(){
16
+ const ref = useRef(null)
17
+
18
+ return (
19
+ <div style={{padding:20}}>
20
+ <OpenTextEditor
21
+ ref={ref}
22
+ initialValue={`<p>Hello</p>`}
23
+ onChange={(html) => console.log('changed', html)}
24
+ />
25
+ </div>
26
+ )
27
+ }
28
+ ```
29
+
30
+ Props
31
+ - `initialValue` (string): optional initial HTML content
32
+ - `onChange` (html: string) => void: optional change handler
33
+ - `className` (string): optional additional class names applied to the editor container
34
+
35
+ Peer dependencies
36
+
37
+ This package expects React as a peer dependency (supported ranges: `^18 || ^19`). Install them if your project doesn't already include React:
38
+
39
+ ```bash
40
+ npm install react@^18 react-dom@^18
41
+ # or for React 19 consumers:
42
+ npm install react@^19 react-dom@^19
43
+ ```
44
+
45
+ Imperative API (via `ref`)
46
+
47
+ When mounted with a `ref`, the editor exposes a small imperative API:
48
+
49
+ - `focus()` — focus the editor
50
+ - `getHtml()` — return current editor HTML
51
+ - `setHtml(html)` — replace editor content
52
+ - `insertHtml(html)` — insert HTML at the current selection
53
+ - `execCommand(command, value)` — run low-level `document.execCommand`
54
+ - `insertTable(rows, cols)` — insert a table programmatically
55
+ - `tableAction(action)` — run table actions when a table cell is active
56
+
57
+ Plugins
58
+
59
+ Built-in plugin placeholders live in the source at `src/editor/plugins`. See [docs/editor/developer.md](editor/developer.md) for the plugin contract and examples.
60
+
61
+ Building from source
62
+
63
+ ```bash
64
+ git clone https://github.com/danu20002/open-text-editor.git
65
+ cd open-text-editor
66
+ npm install
67
+ npm run build:lib
68
+ ```
69
+
70
+ Local test
71
+
72
+ ```bash
73
+ npm pack
74
+ # install the generated tarball (replace <version> with the package version):
75
+ npm install ./open-text-editor-latest-<version>.tgz
76
+ ```
77
+
78
+ Publishing
79
+
80
+ See [docs/PUBLISH.md](PUBLISH.md) for publish steps and notes about peer dependencies.
81
+
@@ -1,31 +1,37 @@
1
- # Developer Guide — Plugins & Extensibility
1
+ **Developer Guide — Plugins & Extensibility**
2
2
 
3
- This document explains how to create and register plugins for `open-text-editor`.
3
+ This document explains the intended plugin contract and where built-in plugin placeholders live in the source tree.
4
4
 
5
5
  Plugin contract
6
- - Export a default function that receives an `editorApi` and returns an object with:
6
+ - A plugin should export a default function that accepts an `editorApi` object and returns an object with:
7
7
  - `name` — plugin id string
8
- - `install(editor)` — called when plugin is enabled; attach commands, buttons, event listeners here
8
+ - `install()` — called when the plugin is enabled; register commands, toolbar buttons, or event listeners here
9
9
 
10
10
  Example plugin skeleton
11
11
  ```js
12
12
  export default function myPlugin(editorApi) {
13
13
  return {
14
14
  name: 'my-plugin',
15
- install(editor) {
16
- // add command
17
- editor.execCommand = editor.execCommand || editorApi.execCommand
18
- // add toolbar button by calling editorApi.addToolbarButton(...)
15
+ install() {
16
+ // Example: add a simple command that inserts a timestamp
17
+ const insertTimestamp = () => editorApi.insertHtml(`<time>${new Date().toISOString()}</time>`)
18
+ // Optionally expose commands or UI wiring via editorApi
19
+ editorApi.registerCommand && editorApi.registerCommand('insert-timestamp', insertTimestamp)
19
20
  }
20
21
  }
21
22
  }
22
23
  ```
23
24
 
24
- Registering plugins
25
- - Built-in plugins live in `src/editor/plugins` and are available through the registry `import plugins from 'open-text-editor/src/editor/plugins'`.
26
- - Consumers can supply plugins by passing them to the editor constructor or mounting API (future API plans). For now, import and compose in your app.
25
+ Built-in plugins
26
+ - Built-in plugin placeholders are in the source at `src/editor/plugins/` (part of this repo). Consumers installing the package get the compiled library; to inspect or extend built-ins, open the repository and edit or copy the plugin files from that folder.
27
+
28
+ Registering plugins (current status)
29
+ - This release provides plugin scaffolding in source. Runtime plugin registration APIs (for consumer-supplied plugins) are planned; for now you can compose plugins in your app by importing their code or by modifying the source plugin folder when building from source.
27
30
 
28
31
  Best practices
29
32
  - Keep plugins small and focused.
30
33
  - Prefer declarative UI for toolbar buttons (icon, tooltip, command).
31
34
  - Clean up event listeners and DOM mutations during uninstall.
35
+
36
+ If you want, I can implement a runtime `editorApi.registerPlugin()` and `editorApi.addToolbarButton()` API in `src/editor/OpentextEditor.jsx` so consumers can register plugins dynamically. Say the word and I will wire it up and add examples.
37
+
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "open-text-editor-latest",
3
3
  "private": false,
4
- "version": "1.0.1",
4
+ "version": "1.0.3",
5
5
  "type": "module",
6
6
  "description": "A lightweight, pluggable React contentEditable rich text editor",
7
7
  "scripts": {
@@ -34,7 +34,7 @@
34
34
  "vite": "^7.2.4"
35
35
  },
36
36
  "main": "dist/index.cjs.js",
37
- "module": "dist/index.esm.js",
37
+ "module": "dist/index.es.js",
38
38
  "files": [
39
39
  "dist/",
40
40
  "src/editor/",
@@ -64,7 +64,7 @@
64
64
  },
65
65
  "exports": {
66
66
  ".": {
67
- "import": "./dist/index.esm.js",
67
+ "import": "./dist/index.es.js",
68
68
  "require": "./dist/index.cjs.js"
69
69
  }
70
70
  }