@june-ai/june-ui 0.2.4 → 0.2.5

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,174 +0,0 @@
1
- // src/components/document-editor/document-engine.ts
2
- import { Editor } from "@tiptap/core";
3
-
4
- // src/errors/errors.ts
5
- var JuneError = class _JuneError extends Error {
6
- constructor(code, message, options = {}) {
7
- super(message);
8
- Object.setPrototypeOf(this, _JuneError.prototype);
9
- this.name = "JuneError";
10
- this.code = code;
11
- this.details = options.details;
12
- if (options.cause !== void 0) {
13
- this.cause = options.cause;
14
- }
15
- }
16
- };
17
- function isJuneError(value) {
18
- return value instanceof JuneError;
19
- }
20
- function toJuneError(error, fallbackCode, message) {
21
- if (error instanceof JuneError) return error;
22
- const text = message ?? (error instanceof Error ? error.message : String(error));
23
- return new JuneError(fallbackCode, text, { cause: error });
24
- }
25
-
26
- // src/components/document-editor/document-extensions.ts
27
- import { TableKit } from "@tiptap/extension-table";
28
- import TextAlign from "@tiptap/extension-text-align";
29
- import { Markdown } from "@tiptap/markdown";
30
- import StarterKit from "@tiptap/starter-kit";
31
- function createDocumentExtensions() {
32
- return [
33
- StarterKit.configure({
34
- heading: { levels: [1, 2, 3] },
35
- // Tiptap v3 StarterKit already includes Link and Underline
36
- link: { openOnClick: false, autolink: true, defaultProtocol: "https" }
37
- }),
38
- TextAlign.configure({ types: ["heading", "paragraph"] }),
39
- TableKit,
40
- Markdown
41
- ];
42
- }
43
-
44
- // src/components/document-editor/document-utils.ts
45
- var emptyDoc = () => ({ type: "doc", content: [{ type: "paragraph" }] });
46
- function isDocJSON(value) {
47
- if (!value || typeof value !== "object") return false;
48
- const v = value;
49
- return v.type === "doc" && (v.content === void 0 || Array.isArray(v.content));
50
- }
51
- function looksLikeDocJSON(text) {
52
- return /^\s*\{\s*"type"\s*:\s*"doc"/.test(text);
53
- }
54
- function tryParseDocJSON(text) {
55
- try {
56
- const value = JSON.parse(text);
57
- return isDocJSON(value) ? value : null;
58
- } catch {
59
- return null;
60
- }
61
- }
62
- var keyCache = /* @__PURE__ */ new WeakMap();
63
- function docKey(doc) {
64
- let key = keyCache.get(doc);
65
- if (key === void 0) {
66
- key = JSON.stringify(doc);
67
- keyCache.set(doc, key);
68
- }
69
- return key;
70
- }
71
- function plainText(node) {
72
- const n = node;
73
- if (typeof n.text === "string") return n.text;
74
- return (n.content ?? []).map(plainText).join(" ");
75
- }
76
- function countWords(text) {
77
- const trimmed = text.trim();
78
- return trimmed ? trimmed.split(/\s+/).length : 0;
79
- }
80
- var wordCache = /* @__PURE__ */ new WeakMap();
81
- function wordCountOf(doc) {
82
- let count = wordCache.get(doc);
83
- if (count === void 0) {
84
- count = countWords(plainText(doc));
85
- wordCache.set(doc, count);
86
- }
87
- return count;
88
- }
89
- function slugify(value) {
90
- return value.toLowerCase().normalize("NFKD").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60);
91
- }
92
- function debounce(fn, wait) {
93
- let timer = null;
94
- const run = () => {
95
- timer = null;
96
- fn();
97
- };
98
- const debounced = (() => {
99
- if (timer !== null) clearTimeout(timer);
100
- timer = setTimeout(run, wait);
101
- });
102
- debounced.cancel = () => {
103
- if (timer !== null) {
104
- clearTimeout(timer);
105
- timer = null;
106
- }
107
- };
108
- debounced.flush = () => {
109
- if (timer !== null) {
110
- clearTimeout(timer);
111
- run();
112
- }
113
- };
114
- return debounced;
115
- }
116
- function sanitizeHref(input) {
117
- const value = input.trim();
118
- if (!value) return null;
119
- if (/^(https?:|mailto:|tel:)/i.test(value)) return value;
120
- if (/^[a-z][a-z0-9+.-]*:/i.test(value)) return null;
121
- if (value.startsWith("/") || value.startsWith("#")) return value;
122
- return `https://${value}`;
123
- }
124
-
125
- // src/components/document-editor/document-engine.ts
126
- var scratch = null;
127
- function scratchEditor() {
128
- if (!scratch || scratch.isDestroyed) {
129
- scratch = new Editor({ extensions: createDocumentExtensions(), content: "" });
130
- }
131
- return scratch;
132
- }
133
- function parseDocumentContent(text) {
134
- const editor = scratchEditor();
135
- const trimmed = text.trim();
136
- try {
137
- if (looksLikeDocJSON(trimmed)) {
138
- const json = tryParseDocJSON(trimmed);
139
- if (!json) throw new Error("The document JSON could not be parsed");
140
- editor.schema.nodeFromJSON(json).check();
141
- editor.commands.setContent(json, { emitUpdate: false });
142
- } else {
143
- editor.commands.setContent(trimmed, { contentType: "markdown", emitUpdate: false });
144
- }
145
- return editor.getJSON();
146
- } catch (error) {
147
- throw toJuneError(error, "DOCUMENT_ERROR", "The document content is invalid");
148
- }
149
- }
150
- function load(doc) {
151
- const editor = scratchEditor();
152
- editor.commands.setContent(doc, { emitUpdate: false });
153
- return editor;
154
- }
155
- var docToHtml = (doc) => load(doc).getHTML();
156
- var docToMarkdown = (doc) => load(doc).getMarkdown();
157
- var docToText = (doc) => load(doc).getText({ blockSeparator: "\n\n" });
158
-
159
- export {
160
- JuneError,
161
- isJuneError,
162
- toJuneError,
163
- createDocumentExtensions,
164
- emptyDoc,
165
- docKey,
166
- wordCountOf,
167
- slugify,
168
- debounce,
169
- sanitizeHref,
170
- parseDocumentContent,
171
- docToHtml,
172
- docToMarkdown,
173
- docToText
174
- };