writetrack 0.6.1 → 0.8.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.
@@ -0,0 +1,75 @@
1
+ import { WriteTrack } from 'writetrack';
2
+
3
+ export interface WriteTrackLexicalOptions {
4
+ /** WriteTrack license key */
5
+ license?: string;
6
+ /** User identifier for metadata */
7
+ userId?: string;
8
+ /** Content identifier for metadata */
9
+ contentId?: string;
10
+ /** Additional metadata */
11
+ metadata?: Record<string, unknown>;
12
+ /** Auto-start tracking when editor root is available (default: true) */
13
+ autoStart?: boolean;
14
+ /** URL to the WASM binary for analysis. If omitted, uses default loader path. */
15
+ wasmUrl?: string;
16
+ /** Enable IndexedDB session persistence and auto-resume. Requires contentId. */
17
+ persist?: boolean;
18
+ }
19
+
20
+ export interface WriteTrackLexicalHandle {
21
+ /** The underlying WriteTrack instance (null until root element is available) */
22
+ tracker: WriteTrack | null;
23
+ /** Whether tracking is currently active */
24
+ isTracking: boolean;
25
+ /** Stop tracking and clean up resources */
26
+ destroy(): void;
27
+ }
28
+
29
+ /**
30
+ * Attach WriteTrack to a Lexical editor.
31
+ *
32
+ * Uses `editor.registerRootListener()` to discover the contenteditable element.
33
+ * The tracker is created when the root becomes available and destroyed when
34
+ * the root is removed or `destroy()` is called.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * import { createEditor } from 'lexical';
39
+ * import { createWriteTrackLexical } from 'writetrack/lexical';
40
+ *
41
+ * import { createEditor, $getSelection } from 'lexical';
42
+ * import { createWriteTrackLexical } from 'writetrack/lexical';
43
+ *
44
+ * const editor = createEditor({ ... });
45
+ * const handle = createWriteTrackLexical(editor, $getSelection, {
46
+ * license: 'your-license-key',
47
+ * });
48
+ *
49
+ * // Access tracker
50
+ * const data = handle.tracker?.getData();
51
+ *
52
+ * // Clean up
53
+ * handle.destroy();
54
+ * ```
55
+ *
56
+ * @param editor - A Lexical `LexicalEditor` instance
57
+ * @param $getSelection - Lexical's `$getSelection` function for cursor position tracking
58
+ * @param options - WriteTrack configuration options
59
+ * @returns A handle with the tracker instance and a destroy method
60
+ */
61
+ export declare function createWriteTrackLexical(
62
+ editor: {
63
+ registerRootListener(
64
+ listener: (
65
+ rootElement: HTMLElement | null,
66
+ prevRootElement: HTMLElement | null
67
+ ) => void
68
+ ): () => void;
69
+ getEditorState(): {
70
+ read<T>(callback: () => T): T;
71
+ };
72
+ },
73
+ $getSelection: () => { anchor?: { offset: number } } | null,
74
+ options: WriteTrackLexicalOptions
75
+ ): WriteTrackLexicalHandle;
@@ -0,0 +1 @@
1
+ import{WriteTrack as k}from"writetrack";function u(n,c,r){let s=r.autoStart!==!1,e={tracker:null,isTracking:!1,destroy(){e.tracker&&(e.tracker.stop(),e.tracker=null,e.isTracking=!1),o()}};function l(t){e.tracker=new k({target:t,license:r.license,userId:r.userId,contentId:r.contentId,metadata:r.metadata,wasmUrl:r.wasmUrl,persist:r.persist,cursorPositionProvider:()=>{try{return n.getEditorState().read(()=>{let a=c();return a&&typeof a.anchor?.offset=="number"?a.anchor.offset:0})}catch{return 0}}}),s&&(r.persist?e.tracker.ready.then(()=>{e.tracker&&(e.tracker.start(),e.isTracking=!0)}):(e.tracker.start(),e.isTracking=!0))}function i(){e.tracker&&(e.tracker.stop(),e.tracker=null,e.isTracking=!1)}let o=n.registerRootListener(t=>{t?(i(),l(t)):i()});return e}export{u as createWriteTrackLexical};
@@ -0,0 +1,64 @@
1
+ import { WriteTrack } from 'writetrack';
2
+
3
+ export interface WriteTrackSlateOptions {
4
+ /** WriteTrack license key */
5
+ license?: string;
6
+ /** User identifier for metadata */
7
+ userId?: string;
8
+ /** Content identifier for metadata */
9
+ contentId?: string;
10
+ /** Additional metadata */
11
+ metadata?: Record<string, unknown>;
12
+ /** Auto-start tracking when created (default: true) */
13
+ autoStart?: boolean;
14
+ /** URL to the WASM binary for analysis. If omitted, uses default loader path. */
15
+ wasmUrl?: string;
16
+ /** Enable IndexedDB session persistence and auto-resume. Requires contentId. */
17
+ persist?: boolean;
18
+ }
19
+
20
+ export interface WriteTrackSlateHandle {
21
+ /** The underlying WriteTrack instance */
22
+ tracker: WriteTrack | null;
23
+ /** Whether tracking is currently active */
24
+ isTracking: boolean;
25
+ /** Stop tracking and clean up resources */
26
+ destroy(): void;
27
+ }
28
+
29
+ /**
30
+ * Attach WriteTrack to a Slate editor.
31
+ *
32
+ * Slate is React-based and does not provide a built-in destroy lifecycle,
33
+ * so `destroy()` must be called manually (e.g. in a useEffect cleanup).
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * import { createEditor } from 'slate';
38
+ * import { createWriteTrackSlate } from 'writetrack/slate';
39
+ *
40
+ * const editor = createEditor();
41
+ * const editableRef = document.querySelector('[data-slate-editor]');
42
+ * const handle = createWriteTrackSlate(editor, editableRef, {
43
+ * license: 'your-license-key',
44
+ * });
45
+ *
46
+ * // Access tracker
47
+ * const data = handle.tracker?.getData();
48
+ *
49
+ * // Clean up
50
+ * handle.destroy();
51
+ * ```
52
+ *
53
+ * @param editor - A Slate `Editor` instance
54
+ * @param element - The contenteditable DOM element (e.g. from a ref on `<Editable>`)
55
+ * @param options - WriteTrack configuration options
56
+ * @returns A handle with the tracker instance and a destroy method
57
+ */
58
+ export declare function createWriteTrackSlate(
59
+ editor: {
60
+ selection: { anchor: { offset: number }; focus: { offset: number } } | null;
61
+ },
62
+ element: HTMLElement,
63
+ options: WriteTrackSlateOptions
64
+ ): WriteTrackSlateHandle;
@@ -0,0 +1 @@
1
+ import{WriteTrack as c}from"writetrack";function i(t,a,e){let n=e.autoStart!==!1,r={tracker:null,isTracking:!1,destroy(){r.tracker&&(r.tracker.stop(),r.tracker=null,r.isTracking=!1)}};return r.tracker=new c({target:a,license:e.license,userId:e.userId,contentId:e.contentId,metadata:e.metadata,wasmUrl:e.wasmUrl,persist:e.persist,cursorPositionProvider:()=>t.selection?.anchor.offset??0}),n&&(e.persist?r.tracker.ready.then(()=>{r.tracker&&(r.tracker.start(),r.isTracking=!0)}):(r.tracker.start(),r.isTracking=!0)),r}export{i as createWriteTrackSlate};
@@ -0,0 +1,69 @@
1
+ import { WriteTrack } from 'writetrack';
2
+
3
+ export interface WriteTrackTinyMCEOptions {
4
+ /** WriteTrack license key */
5
+ license?: string;
6
+ /** User identifier for metadata */
7
+ userId?: string;
8
+ /** Content identifier for metadata */
9
+ contentId?: string;
10
+ /** Additional metadata */
11
+ metadata?: Record<string, unknown>;
12
+ /** Auto-start tracking when editor initializes (default: true) */
13
+ autoStart?: boolean;
14
+ /** URL to the WASM binary for analysis. If omitted, uses default loader path. */
15
+ wasmUrl?: string;
16
+ /** Enable IndexedDB session persistence and auto-resume. Requires contentId. */
17
+ persist?: boolean;
18
+ }
19
+
20
+ export interface WriteTrackTinyMCEHandle {
21
+ /** The underlying WriteTrack instance (null until editor init fires) */
22
+ tracker: WriteTrack | null;
23
+ /** Whether tracking is currently active */
24
+ isTracking: boolean;
25
+ /** Stop tracking and clean up resources */
26
+ destroy(): void;
27
+ }
28
+
29
+ /**
30
+ * Attach WriteTrack to a TinyMCE editor.
31
+ *
32
+ * Hooks into TinyMCE's `init` and `remove` lifecycle events.
33
+ * Uses `editor.getBody()` as the target element.
34
+ *
35
+ * **Note:** Only inline mode (`inline: true`) is fully supported.
36
+ * In iframe mode (default), window/document-level listeners attach to the
37
+ * host page rather than the iframe, resulting in degraded tracking.
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * import tinymce from 'tinymce';
42
+ * import { createWriteTrackTinyMCE } from 'writetrack/tinymce';
43
+ *
44
+ * tinymce.init({
45
+ * selector: '#editor',
46
+ * inline: true,
47
+ * setup: (editor) => {
48
+ * const handle = createWriteTrackTinyMCE(editor, {
49
+ * license: 'your-license-key',
50
+ * });
51
+ * },
52
+ * });
53
+ * ```
54
+ *
55
+ * @param editor - A TinyMCE `Editor` instance
56
+ * @param options - WriteTrack configuration options
57
+ * @returns A handle with the tracker instance and a destroy method
58
+ */
59
+ export declare function createWriteTrackTinyMCE(
60
+ editor: {
61
+ getBody(): HTMLElement;
62
+ selection: {
63
+ getRng(): { startOffset: number };
64
+ };
65
+ on(event: string, handler: () => void): void;
66
+ off(event: string, handler: () => void): void;
67
+ },
68
+ options: WriteTrackTinyMCEOptions
69
+ ): WriteTrackTinyMCEHandle;
@@ -0,0 +1 @@
1
+ import{WriteTrack as s}from"writetrack";function o(t,e){let i=e.autoStart!==!1,r={tracker:null,isTracking:!1,destroy(){r.tracker&&(r.tracker.stop(),r.tracker=null,r.isTracking=!1),t.off("init",n),t.off("remove",a)}};function n(){let c=t.getBody();r.tracker=new s({target:c,license:e.license,userId:e.userId,contentId:e.contentId,metadata:e.metadata,wasmUrl:e.wasmUrl,persist:e.persist,cursorPositionProvider:()=>{try{return t.selection.getRng().startOffset}catch{return 0}}}),i&&(e.persist?r.tracker.ready.then(()=>{r.tracker&&(r.tracker.start(),r.isTracking=!0)}):(r.tracker.start(),r.isTracking=!0))}function a(){r.destroy()}return t.on("init",n),t.on("remove",a),r}export{o as createWriteTrackTinyMCE};