tetrons 2.3.80 → 2.3.83
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/dist/components/tetrons/EditorContent.tsx +22 -36
- package/dist/index.cjs +63 -65
- package/dist/index.d.mts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.mjs +62 -65
- package/package.json +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { MathInline } from "./extensions/MathExtension";
|
|
3
|
-
|
|
4
3
|
import React, { useEffect, useRef, useState } from "react";
|
|
5
4
|
import { useEditor, EditorContent as TiptapEditorContent } from "@tiptap/react";
|
|
6
5
|
import type { AddOn } from "./toolbar/TetronsToolbar";
|
|
6
|
+
import { getActivePlan, Plan } from "../../utils/licenseTracker";
|
|
7
7
|
|
|
8
8
|
import Document from "@tiptap/extension-document";
|
|
9
9
|
import Paragraph from "@tiptap/extension-paragraph";
|
|
@@ -38,7 +38,6 @@ import { createLowlight } from "lowlight";
|
|
|
38
38
|
|
|
39
39
|
import { useTypo } from "../../utils/useTypo";
|
|
40
40
|
import { Spellcheck } from "./extensions/Spellcheck";
|
|
41
|
-
|
|
42
41
|
import { Comment } from "./toolbar/extensions/Comment";
|
|
43
42
|
import { Subscript } from "./toolbar/marks/Subscript";
|
|
44
43
|
import { Superscript } from "./toolbar/marks/Superscript";
|
|
@@ -57,7 +56,6 @@ lowlight.register("ts", ts);
|
|
|
57
56
|
|
|
58
57
|
type EditorContentProps = {
|
|
59
58
|
apiKey: string;
|
|
60
|
-
addOns?: string[];
|
|
61
59
|
};
|
|
62
60
|
|
|
63
61
|
export default function EditorContent({ apiKey }: EditorContentProps) {
|
|
@@ -72,6 +70,7 @@ export default function EditorContent({ apiKey }: EditorContentProps) {
|
|
|
72
70
|
const [currentVersionIndex, setCurrentVersionIndex] = useState<number | null>(
|
|
73
71
|
null
|
|
74
72
|
);
|
|
73
|
+
const [addOns, setAddOns] = useState<AddOn[]>([]);
|
|
75
74
|
|
|
76
75
|
const wrapperRef = useRef<HTMLDivElement>(null);
|
|
77
76
|
|
|
@@ -81,28 +80,35 @@ export default function EditorContent({ apiKey }: EditorContentProps) {
|
|
|
81
80
|
: "https://staging.tetrons.com";
|
|
82
81
|
|
|
83
82
|
useEffect(() => {
|
|
84
|
-
const
|
|
83
|
+
const fetchKeyData = async () => {
|
|
85
84
|
try {
|
|
86
|
-
const res = await fetch(`${API_BASE_URL}/api/
|
|
87
|
-
method: "POST",
|
|
88
|
-
headers: {
|
|
89
|
-
"Content-Type": "application/json",
|
|
90
|
-
},
|
|
91
|
-
body: JSON.stringify({ apiKey }),
|
|
92
|
-
});
|
|
93
|
-
|
|
85
|
+
const res = await fetch(`${API_BASE_URL}/api/api-key?apiKey=${apiKey}`);
|
|
94
86
|
const data = await res.json();
|
|
87
|
+
|
|
95
88
|
if (!res.ok) throw new Error(data.error || "Invalid API Key");
|
|
96
89
|
|
|
90
|
+
const version =
|
|
91
|
+
data.version &&
|
|
92
|
+
["free", "pro", "premium", "platinum"].includes(data.version)
|
|
93
|
+
? (data.version as Plan)
|
|
94
|
+
: "free";
|
|
95
|
+
|
|
96
|
+
const activeVersion = getActivePlan(version);
|
|
97
|
+
|
|
97
98
|
setIsValid(true);
|
|
98
|
-
setUserVersion(
|
|
99
|
+
setUserVersion(activeVersion);
|
|
100
|
+
setAddOns(data.addOn || []);
|
|
101
|
+
|
|
102
|
+
if (activeVersion === "free" && data.version !== "free") {
|
|
103
|
+
setError("Your paid plan has expired. Downgraded to Free version.");
|
|
104
|
+
}
|
|
99
105
|
} catch (err: unknown) {
|
|
100
106
|
setError(err instanceof Error ? err.message : "Invalid API Key");
|
|
101
107
|
setIsValid(false);
|
|
102
108
|
}
|
|
103
109
|
};
|
|
104
110
|
|
|
105
|
-
|
|
111
|
+
fetchKeyData();
|
|
106
112
|
}, [apiKey, API_BASE_URL]);
|
|
107
113
|
|
|
108
114
|
const editor = useEditor({
|
|
@@ -210,20 +216,6 @@ export default function EditorContent({ apiKey }: EditorContentProps) {
|
|
|
210
216
|
return <div className="editor-loading">📖 Loading dictionary...</div>;
|
|
211
217
|
}
|
|
212
218
|
|
|
213
|
-
const versionAddOnsMap: Record<
|
|
214
|
-
"free" | "pro" | "premium" | "platinum",
|
|
215
|
-
AddOn[]
|
|
216
|
-
> = {
|
|
217
|
-
free: [],
|
|
218
|
-
pro: ["code"],
|
|
219
|
-
premium: ["code", "math"],
|
|
220
|
-
platinum: ["code", "math"],
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
const enabledAddOns = (
|
|
224
|
-
userVersion ? versionAddOnsMap[userVersion] || [] : []
|
|
225
|
-
) as AddOn[];
|
|
226
|
-
|
|
227
219
|
return (
|
|
228
220
|
<div className="editor-container">
|
|
229
221
|
{userVersion !== "free" && (
|
|
@@ -246,9 +238,7 @@ export default function EditorContent({ apiKey }: EditorContentProps) {
|
|
|
246
238
|
key={idx}
|
|
247
239
|
type="button"
|
|
248
240
|
onClick={() => restoreVersion(idx)}
|
|
249
|
-
className={`editor-version-btn ${
|
|
250
|
-
idx === currentVersionIndex ? "active" : ""
|
|
251
|
-
}`}
|
|
241
|
+
className={`editor-version-btn ${idx === currentVersionIndex ? "active" : ""}`}
|
|
252
242
|
title={`Restore Version ${idx + 1}`}
|
|
253
243
|
>
|
|
254
244
|
{`V${idx + 1}`}
|
|
@@ -260,11 +250,7 @@ export default function EditorContent({ apiKey }: EditorContentProps) {
|
|
|
260
250
|
)}
|
|
261
251
|
|
|
262
252
|
{editor && userVersion && (
|
|
263
|
-
<TetronsToolbar
|
|
264
|
-
editor={editor}
|
|
265
|
-
version={userVersion}
|
|
266
|
-
addOns={enabledAddOns}
|
|
267
|
-
/>
|
|
253
|
+
<TetronsToolbar editor={editor} version={userVersion} addOns={addOns} />
|
|
268
254
|
)}
|
|
269
255
|
|
|
270
256
|
<div
|
package/dist/index.cjs
CHANGED
|
@@ -195,6 +195,7 @@ var index_exports = {};
|
|
|
195
195
|
__export(index_exports, {
|
|
196
196
|
EditorContent: () => EditorContent,
|
|
197
197
|
default: () => index_default,
|
|
198
|
+
getTetronsAddOns: () => getTetronsAddOns,
|
|
198
199
|
getTetronsVersion: () => getTetronsVersion,
|
|
199
200
|
initializeTetrons: () => initializeTetrons,
|
|
200
201
|
isApiKeyValid: () => isApiKeyValid,
|
|
@@ -262,6 +263,43 @@ var MathInline = import_core.Node.create({
|
|
|
262
263
|
var import_react24 = __toESM(require("react"));
|
|
263
264
|
var import_react25 = require("@tiptap/react");
|
|
264
265
|
|
|
266
|
+
// src/utils/licenseTracker.ts
|
|
267
|
+
var getLicenseKey = (plan) => `__tetrons_license_start_${plan}__`;
|
|
268
|
+
var PLAN_DURATIONS = {
|
|
269
|
+
free: Infinity,
|
|
270
|
+
pro: 30,
|
|
271
|
+
premium: 30,
|
|
272
|
+
platinum: 30
|
|
273
|
+
};
|
|
274
|
+
function initLicenseTracking(plan) {
|
|
275
|
+
if (typeof window === "undefined") return;
|
|
276
|
+
const key = getLicenseKey(plan);
|
|
277
|
+
const now = Date.now();
|
|
278
|
+
const stored = localStorage.getItem(key);
|
|
279
|
+
if (!stored) {
|
|
280
|
+
localStorage.setItem(key, now.toString());
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
function getActivePlan(plan) {
|
|
284
|
+
if (typeof window === "undefined") return plan;
|
|
285
|
+
if (plan === "free") return "free";
|
|
286
|
+
const key = getLicenseKey(plan);
|
|
287
|
+
const stored = localStorage.getItem(key);
|
|
288
|
+
if (!stored) return "free";
|
|
289
|
+
const startedAt = parseInt(stored, 10);
|
|
290
|
+
const now = Date.now();
|
|
291
|
+
const diffDays = Math.floor((now - startedAt) / (1e3 * 60 * 60 * 24));
|
|
292
|
+
const allowedDays = PLAN_DURATIONS[plan];
|
|
293
|
+
if (diffDays > allowedDays) {
|
|
294
|
+
localStorage.removeItem(key);
|
|
295
|
+
return "free";
|
|
296
|
+
}
|
|
297
|
+
return plan;
|
|
298
|
+
}
|
|
299
|
+
function isLicenseValid(plan) {
|
|
300
|
+
return getActivePlan(plan) === plan;
|
|
301
|
+
}
|
|
302
|
+
|
|
265
303
|
// node_modules/@tiptap/extension-document/dist/index.js
|
|
266
304
|
var import_core2 = require("@tiptap/core");
|
|
267
305
|
var Document = import_core2.Node.create({
|
|
@@ -17130,28 +17168,29 @@ function EditorContent({ apiKey }) {
|
|
|
17130
17168
|
const [currentVersionIndex, setCurrentVersionIndex] = (0, import_react24.useState)(
|
|
17131
17169
|
null
|
|
17132
17170
|
);
|
|
17171
|
+
const [addOns, setAddOns] = (0, import_react24.useState)([]);
|
|
17133
17172
|
const wrapperRef = (0, import_react24.useRef)(null);
|
|
17134
17173
|
const API_BASE_URL = typeof process !== "undefined" && process.env?.NEXT_PUBLIC_TETRONS_API_URL ? process.env.NEXT_PUBLIC_TETRONS_API_URL : "https://staging.tetrons.com";
|
|
17135
17174
|
(0, import_react24.useEffect)(() => {
|
|
17136
|
-
const
|
|
17175
|
+
const fetchKeyData = async () => {
|
|
17137
17176
|
try {
|
|
17138
|
-
const res = await fetch(`${API_BASE_URL}/api/
|
|
17139
|
-
method: "POST",
|
|
17140
|
-
headers: {
|
|
17141
|
-
"Content-Type": "application/json"
|
|
17142
|
-
},
|
|
17143
|
-
body: JSON.stringify({ apiKey })
|
|
17144
|
-
});
|
|
17177
|
+
const res = await fetch(`${API_BASE_URL}/api/api-key?apiKey=${apiKey}`);
|
|
17145
17178
|
const data = await res.json();
|
|
17146
17179
|
if (!res.ok) throw new Error(data.error || "Invalid API Key");
|
|
17180
|
+
const version = data.version && ["free", "pro", "premium", "platinum"].includes(data.version) ? data.version : "free";
|
|
17181
|
+
const activeVersion = getActivePlan(version);
|
|
17147
17182
|
setIsValid(true);
|
|
17148
|
-
setUserVersion(
|
|
17183
|
+
setUserVersion(activeVersion);
|
|
17184
|
+
setAddOns(data.addOn || []);
|
|
17185
|
+
if (activeVersion === "free" && data.version !== "free") {
|
|
17186
|
+
setError("Your paid plan has expired. Downgraded to Free version.");
|
|
17187
|
+
}
|
|
17149
17188
|
} catch (err) {
|
|
17150
17189
|
setError(err instanceof Error ? err.message : "Invalid API Key");
|
|
17151
17190
|
setIsValid(false);
|
|
17152
17191
|
}
|
|
17153
17192
|
};
|
|
17154
|
-
|
|
17193
|
+
fetchKeyData();
|
|
17155
17194
|
}, [apiKey, API_BASE_URL]);
|
|
17156
17195
|
const editor = (0, import_react25.useEditor)({
|
|
17157
17196
|
extensions: [
|
|
@@ -17248,13 +17287,6 @@ function EditorContent({ apiKey }) {
|
|
|
17248
17287
|
if (!typo) {
|
|
17249
17288
|
return /* @__PURE__ */ import_react24.default.createElement("div", { className: "editor-loading" }, "\u{1F4D6} Loading dictionary...");
|
|
17250
17289
|
}
|
|
17251
|
-
const versionAddOnsMap = {
|
|
17252
|
-
free: [],
|
|
17253
|
-
pro: ["code"],
|
|
17254
|
-
premium: ["code", "math"],
|
|
17255
|
-
platinum: ["code", "math"]
|
|
17256
|
-
};
|
|
17257
|
-
const enabledAddOns = userVersion ? versionAddOnsMap[userVersion] || [] : [];
|
|
17258
17290
|
return /* @__PURE__ */ import_react24.default.createElement("div", { className: "editor-container" }, userVersion !== "free" && /* @__PURE__ */ import_react24.default.createElement("div", { className: "editor-toolbar" }, /* @__PURE__ */ import_react24.default.createElement(
|
|
17259
17291
|
"button",
|
|
17260
17292
|
{
|
|
@@ -17274,14 +17306,7 @@ function EditorContent({ apiKey }) {
|
|
|
17274
17306
|
title: `Restore Version ${idx + 1}`
|
|
17275
17307
|
},
|
|
17276
17308
|
`V${idx + 1}`
|
|
17277
|
-
)))), editor && userVersion && /* @__PURE__ */ import_react24.default.createElement(
|
|
17278
|
-
TetronsToolbar,
|
|
17279
|
-
{
|
|
17280
|
-
editor,
|
|
17281
|
-
version: userVersion,
|
|
17282
|
-
addOns: enabledAddOns
|
|
17283
|
-
}
|
|
17284
|
-
), /* @__PURE__ */ import_react24.default.createElement(
|
|
17309
|
+
)))), editor && userVersion && /* @__PURE__ */ import_react24.default.createElement(TetronsToolbar, { editor, version: userVersion, addOns }), /* @__PURE__ */ import_react24.default.createElement(
|
|
17285
17310
|
"div",
|
|
17286
17311
|
{
|
|
17287
17312
|
ref: wrapperRef,
|
|
@@ -17292,60 +17317,32 @@ function EditorContent({ apiKey }) {
|
|
|
17292
17317
|
));
|
|
17293
17318
|
}
|
|
17294
17319
|
|
|
17295
|
-
// src/utils/licenseTracker.ts
|
|
17296
|
-
var getLicenseKey = (plan) => `__tetrons_license_start_${plan}__`;
|
|
17297
|
-
var PLAN_DURATIONS = {
|
|
17298
|
-
free: 14,
|
|
17299
|
-
pro: 30,
|
|
17300
|
-
premium: 30,
|
|
17301
|
-
platinum: 30
|
|
17302
|
-
};
|
|
17303
|
-
function initLicenseTracking(plan) {
|
|
17304
|
-
if (typeof window === "undefined") return;
|
|
17305
|
-
const key = getLicenseKey(plan);
|
|
17306
|
-
const now = Date.now();
|
|
17307
|
-
const stored = localStorage.getItem(key);
|
|
17308
|
-
if (!stored) {
|
|
17309
|
-
localStorage.setItem(key, now.toString());
|
|
17310
|
-
}
|
|
17311
|
-
}
|
|
17312
|
-
function isLicenseValid(plan) {
|
|
17313
|
-
if (typeof window === "undefined") return true;
|
|
17314
|
-
const key = getLicenseKey(plan);
|
|
17315
|
-
const stored = localStorage.getItem(key);
|
|
17316
|
-
if (!stored) return false;
|
|
17317
|
-
const startedAt = parseInt(stored, 10);
|
|
17318
|
-
const now = Date.now();
|
|
17319
|
-
const diffDays = Math.floor((now - startedAt) / (1e3 * 60 * 60 * 24));
|
|
17320
|
-
const allowedDays = PLAN_DURATIONS[plan];
|
|
17321
|
-
return diffDays <= allowedDays;
|
|
17322
|
-
}
|
|
17323
|
-
|
|
17324
17320
|
// src/index.ts
|
|
17325
17321
|
var API_VALID = false;
|
|
17326
|
-
var API_VERSION =
|
|
17322
|
+
var API_VERSION = null;
|
|
17323
|
+
var API_ADDONS = [];
|
|
17327
17324
|
async function initializeTetrons(apiKey) {
|
|
17328
|
-
const res = await fetch(
|
|
17329
|
-
|
|
17330
|
-
|
|
17331
|
-
"Content-Type": "application/json"
|
|
17332
|
-
},
|
|
17333
|
-
body: JSON.stringify({ apiKey })
|
|
17334
|
-
});
|
|
17325
|
+
const res = await fetch(
|
|
17326
|
+
`${process.env.NEXT_PUBLIC_TETRONS_API_URL || "https://staging.tetrons.com"}/api/api-key?apiKey=${apiKey}`
|
|
17327
|
+
);
|
|
17335
17328
|
if (!res.ok) {
|
|
17336
17329
|
const error = await res.json();
|
|
17337
17330
|
throw new Error(`API Key validation failed: ${error.error}`);
|
|
17338
17331
|
}
|
|
17339
17332
|
const data = await res.json();
|
|
17340
|
-
API_VALID =
|
|
17341
|
-
API_VERSION = data.version;
|
|
17342
|
-
|
|
17333
|
+
API_VALID = true;
|
|
17334
|
+
API_VERSION = data.version && ["free", "pro", "premium", "platinum"].includes(data.version) ? data.version : "free";
|
|
17335
|
+
API_ADDONS = data.addOn || [];
|
|
17336
|
+
if (typeof window !== "undefined" && API_VERSION) {
|
|
17343
17337
|
initLicenseTracking(API_VERSION);
|
|
17344
17338
|
}
|
|
17345
17339
|
}
|
|
17346
17340
|
function getTetronsVersion() {
|
|
17347
17341
|
return API_VERSION;
|
|
17348
17342
|
}
|
|
17343
|
+
function getTetronsAddOns() {
|
|
17344
|
+
return API_ADDONS;
|
|
17345
|
+
}
|
|
17349
17346
|
function isApiKeyValid() {
|
|
17350
17347
|
return API_VALID;
|
|
17351
17348
|
}
|
|
@@ -17357,6 +17354,7 @@ var index_default = EditorContent;
|
|
|
17357
17354
|
// Annotate the CommonJS export names for ESM import in node:
|
|
17358
17355
|
0 && (module.exports = {
|
|
17359
17356
|
EditorContent,
|
|
17357
|
+
getTetronsAddOns,
|
|
17360
17358
|
getTetronsVersion,
|
|
17361
17359
|
initializeTetrons,
|
|
17362
17360
|
isApiKeyValid,
|
package/dist/index.d.mts
CHANGED
|
@@ -2,13 +2,15 @@ import React from 'react';
|
|
|
2
2
|
|
|
3
3
|
type EditorContentProps = {
|
|
4
4
|
apiKey: string;
|
|
5
|
-
addOns?: string[];
|
|
6
5
|
};
|
|
7
6
|
declare function EditorContent({ apiKey }: EditorContentProps): React.JSX.Element;
|
|
8
7
|
|
|
8
|
+
type Plan = "free" | "pro" | "premium" | "platinum";
|
|
9
|
+
|
|
9
10
|
declare function initializeTetrons(apiKey: string): Promise<void>;
|
|
10
|
-
declare function getTetronsVersion():
|
|
11
|
+
declare function getTetronsVersion(): Plan | null;
|
|
12
|
+
declare function getTetronsAddOns(): string[];
|
|
11
13
|
declare function isApiKeyValid(): boolean;
|
|
12
14
|
declare function isTetronsLicenseValid(): boolean;
|
|
13
15
|
|
|
14
|
-
export { EditorContent, EditorContent as default, getTetronsVersion, initializeTetrons, isApiKeyValid, isTetronsLicenseValid };
|
|
16
|
+
export { EditorContent, EditorContent as default, getTetronsAddOns, getTetronsVersion, initializeTetrons, isApiKeyValid, isTetronsLicenseValid };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,13 +2,15 @@ import React from 'react';
|
|
|
2
2
|
|
|
3
3
|
type EditorContentProps = {
|
|
4
4
|
apiKey: string;
|
|
5
|
-
addOns?: string[];
|
|
6
5
|
};
|
|
7
6
|
declare function EditorContent({ apiKey }: EditorContentProps): React.JSX.Element;
|
|
8
7
|
|
|
8
|
+
type Plan = "free" | "pro" | "premium" | "platinum";
|
|
9
|
+
|
|
9
10
|
declare function initializeTetrons(apiKey: string): Promise<void>;
|
|
10
|
-
declare function getTetronsVersion():
|
|
11
|
+
declare function getTetronsVersion(): Plan | null;
|
|
12
|
+
declare function getTetronsAddOns(): string[];
|
|
11
13
|
declare function isApiKeyValid(): boolean;
|
|
12
14
|
declare function isTetronsLicenseValid(): boolean;
|
|
13
15
|
|
|
14
|
-
export { EditorContent, EditorContent as default, getTetronsVersion, initializeTetrons, isApiKeyValid, isTetronsLicenseValid };
|
|
16
|
+
export { EditorContent, EditorContent as default, getTetronsAddOns, getTetronsVersion, initializeTetrons, isApiKeyValid, isTetronsLicenseValid };
|
package/dist/index.mjs
CHANGED
|
@@ -227,6 +227,43 @@ var MathInline = Node.create({
|
|
|
227
227
|
import React17, { useEffect as useEffect9, useRef as useRef7, useState as useState11 } from "react";
|
|
228
228
|
import { useEditor, EditorContent as TiptapEditorContent } from "@tiptap/react";
|
|
229
229
|
|
|
230
|
+
// src/utils/licenseTracker.ts
|
|
231
|
+
var getLicenseKey = (plan) => `__tetrons_license_start_${plan}__`;
|
|
232
|
+
var PLAN_DURATIONS = {
|
|
233
|
+
free: Infinity,
|
|
234
|
+
pro: 30,
|
|
235
|
+
premium: 30,
|
|
236
|
+
platinum: 30
|
|
237
|
+
};
|
|
238
|
+
function initLicenseTracking(plan) {
|
|
239
|
+
if (typeof window === "undefined") return;
|
|
240
|
+
const key = getLicenseKey(plan);
|
|
241
|
+
const now = Date.now();
|
|
242
|
+
const stored = localStorage.getItem(key);
|
|
243
|
+
if (!stored) {
|
|
244
|
+
localStorage.setItem(key, now.toString());
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
function getActivePlan(plan) {
|
|
248
|
+
if (typeof window === "undefined") return plan;
|
|
249
|
+
if (plan === "free") return "free";
|
|
250
|
+
const key = getLicenseKey(plan);
|
|
251
|
+
const stored = localStorage.getItem(key);
|
|
252
|
+
if (!stored) return "free";
|
|
253
|
+
const startedAt = parseInt(stored, 10);
|
|
254
|
+
const now = Date.now();
|
|
255
|
+
const diffDays = Math.floor((now - startedAt) / (1e3 * 60 * 60 * 24));
|
|
256
|
+
const allowedDays = PLAN_DURATIONS[plan];
|
|
257
|
+
if (diffDays > allowedDays) {
|
|
258
|
+
localStorage.removeItem(key);
|
|
259
|
+
return "free";
|
|
260
|
+
}
|
|
261
|
+
return plan;
|
|
262
|
+
}
|
|
263
|
+
function isLicenseValid(plan) {
|
|
264
|
+
return getActivePlan(plan) === plan;
|
|
265
|
+
}
|
|
266
|
+
|
|
230
267
|
// node_modules/@tiptap/extension-document/dist/index.js
|
|
231
268
|
import { Node as Node2 } from "@tiptap/core";
|
|
232
269
|
var Document = Node2.create({
|
|
@@ -17140,28 +17177,29 @@ function EditorContent({ apiKey }) {
|
|
|
17140
17177
|
const [currentVersionIndex, setCurrentVersionIndex] = useState11(
|
|
17141
17178
|
null
|
|
17142
17179
|
);
|
|
17180
|
+
const [addOns, setAddOns] = useState11([]);
|
|
17143
17181
|
const wrapperRef = useRef7(null);
|
|
17144
17182
|
const API_BASE_URL = typeof process !== "undefined" && process.env?.NEXT_PUBLIC_TETRONS_API_URL ? process.env.NEXT_PUBLIC_TETRONS_API_URL : "https://staging.tetrons.com";
|
|
17145
17183
|
useEffect9(() => {
|
|
17146
|
-
const
|
|
17184
|
+
const fetchKeyData = async () => {
|
|
17147
17185
|
try {
|
|
17148
|
-
const res = await fetch(`${API_BASE_URL}/api/
|
|
17149
|
-
method: "POST",
|
|
17150
|
-
headers: {
|
|
17151
|
-
"Content-Type": "application/json"
|
|
17152
|
-
},
|
|
17153
|
-
body: JSON.stringify({ apiKey })
|
|
17154
|
-
});
|
|
17186
|
+
const res = await fetch(`${API_BASE_URL}/api/api-key?apiKey=${apiKey}`);
|
|
17155
17187
|
const data = await res.json();
|
|
17156
17188
|
if (!res.ok) throw new Error(data.error || "Invalid API Key");
|
|
17189
|
+
const version = data.version && ["free", "pro", "premium", "platinum"].includes(data.version) ? data.version : "free";
|
|
17190
|
+
const activeVersion = getActivePlan(version);
|
|
17157
17191
|
setIsValid(true);
|
|
17158
|
-
setUserVersion(
|
|
17192
|
+
setUserVersion(activeVersion);
|
|
17193
|
+
setAddOns(data.addOn || []);
|
|
17194
|
+
if (activeVersion === "free" && data.version !== "free") {
|
|
17195
|
+
setError("Your paid plan has expired. Downgraded to Free version.");
|
|
17196
|
+
}
|
|
17159
17197
|
} catch (err) {
|
|
17160
17198
|
setError(err instanceof Error ? err.message : "Invalid API Key");
|
|
17161
17199
|
setIsValid(false);
|
|
17162
17200
|
}
|
|
17163
17201
|
};
|
|
17164
|
-
|
|
17202
|
+
fetchKeyData();
|
|
17165
17203
|
}, [apiKey, API_BASE_URL]);
|
|
17166
17204
|
const editor = useEditor({
|
|
17167
17205
|
extensions: [
|
|
@@ -17258,13 +17296,6 @@ function EditorContent({ apiKey }) {
|
|
|
17258
17296
|
if (!typo) {
|
|
17259
17297
|
return /* @__PURE__ */ React17.createElement("div", { className: "editor-loading" }, "\u{1F4D6} Loading dictionary...");
|
|
17260
17298
|
}
|
|
17261
|
-
const versionAddOnsMap = {
|
|
17262
|
-
free: [],
|
|
17263
|
-
pro: ["code"],
|
|
17264
|
-
premium: ["code", "math"],
|
|
17265
|
-
platinum: ["code", "math"]
|
|
17266
|
-
};
|
|
17267
|
-
const enabledAddOns = userVersion ? versionAddOnsMap[userVersion] || [] : [];
|
|
17268
17299
|
return /* @__PURE__ */ React17.createElement("div", { className: "editor-container" }, userVersion !== "free" && /* @__PURE__ */ React17.createElement("div", { className: "editor-toolbar" }, /* @__PURE__ */ React17.createElement(
|
|
17269
17300
|
"button",
|
|
17270
17301
|
{
|
|
@@ -17284,14 +17315,7 @@ function EditorContent({ apiKey }) {
|
|
|
17284
17315
|
title: `Restore Version ${idx + 1}`
|
|
17285
17316
|
},
|
|
17286
17317
|
`V${idx + 1}`
|
|
17287
|
-
)))), editor && userVersion && /* @__PURE__ */ React17.createElement(
|
|
17288
|
-
TetronsToolbar,
|
|
17289
|
-
{
|
|
17290
|
-
editor,
|
|
17291
|
-
version: userVersion,
|
|
17292
|
-
addOns: enabledAddOns
|
|
17293
|
-
}
|
|
17294
|
-
), /* @__PURE__ */ React17.createElement(
|
|
17318
|
+
)))), editor && userVersion && /* @__PURE__ */ React17.createElement(TetronsToolbar, { editor, version: userVersion, addOns }), /* @__PURE__ */ React17.createElement(
|
|
17295
17319
|
"div",
|
|
17296
17320
|
{
|
|
17297
17321
|
ref: wrapperRef,
|
|
@@ -17302,60 +17326,32 @@ function EditorContent({ apiKey }) {
|
|
|
17302
17326
|
));
|
|
17303
17327
|
}
|
|
17304
17328
|
|
|
17305
|
-
// src/utils/licenseTracker.ts
|
|
17306
|
-
var getLicenseKey = (plan) => `__tetrons_license_start_${plan}__`;
|
|
17307
|
-
var PLAN_DURATIONS = {
|
|
17308
|
-
free: 14,
|
|
17309
|
-
pro: 30,
|
|
17310
|
-
premium: 30,
|
|
17311
|
-
platinum: 30
|
|
17312
|
-
};
|
|
17313
|
-
function initLicenseTracking(plan) {
|
|
17314
|
-
if (typeof window === "undefined") return;
|
|
17315
|
-
const key = getLicenseKey(plan);
|
|
17316
|
-
const now = Date.now();
|
|
17317
|
-
const stored = localStorage.getItem(key);
|
|
17318
|
-
if (!stored) {
|
|
17319
|
-
localStorage.setItem(key, now.toString());
|
|
17320
|
-
}
|
|
17321
|
-
}
|
|
17322
|
-
function isLicenseValid(plan) {
|
|
17323
|
-
if (typeof window === "undefined") return true;
|
|
17324
|
-
const key = getLicenseKey(plan);
|
|
17325
|
-
const stored = localStorage.getItem(key);
|
|
17326
|
-
if (!stored) return false;
|
|
17327
|
-
const startedAt = parseInt(stored, 10);
|
|
17328
|
-
const now = Date.now();
|
|
17329
|
-
const diffDays = Math.floor((now - startedAt) / (1e3 * 60 * 60 * 24));
|
|
17330
|
-
const allowedDays = PLAN_DURATIONS[plan];
|
|
17331
|
-
return diffDays <= allowedDays;
|
|
17332
|
-
}
|
|
17333
|
-
|
|
17334
17329
|
// src/index.ts
|
|
17335
17330
|
var API_VALID = false;
|
|
17336
|
-
var API_VERSION =
|
|
17331
|
+
var API_VERSION = null;
|
|
17332
|
+
var API_ADDONS = [];
|
|
17337
17333
|
async function initializeTetrons(apiKey) {
|
|
17338
|
-
const res = await fetch(
|
|
17339
|
-
|
|
17340
|
-
|
|
17341
|
-
"Content-Type": "application/json"
|
|
17342
|
-
},
|
|
17343
|
-
body: JSON.stringify({ apiKey })
|
|
17344
|
-
});
|
|
17334
|
+
const res = await fetch(
|
|
17335
|
+
`${process.env.NEXT_PUBLIC_TETRONS_API_URL || "https://staging.tetrons.com"}/api/api-key?apiKey=${apiKey}`
|
|
17336
|
+
);
|
|
17345
17337
|
if (!res.ok) {
|
|
17346
17338
|
const error = await res.json();
|
|
17347
17339
|
throw new Error(`API Key validation failed: ${error.error}`);
|
|
17348
17340
|
}
|
|
17349
17341
|
const data = await res.json();
|
|
17350
|
-
API_VALID =
|
|
17351
|
-
API_VERSION = data.version;
|
|
17352
|
-
|
|
17342
|
+
API_VALID = true;
|
|
17343
|
+
API_VERSION = data.version && ["free", "pro", "premium", "platinum"].includes(data.version) ? data.version : "free";
|
|
17344
|
+
API_ADDONS = data.addOn || [];
|
|
17345
|
+
if (typeof window !== "undefined" && API_VERSION) {
|
|
17353
17346
|
initLicenseTracking(API_VERSION);
|
|
17354
17347
|
}
|
|
17355
17348
|
}
|
|
17356
17349
|
function getTetronsVersion() {
|
|
17357
17350
|
return API_VERSION;
|
|
17358
17351
|
}
|
|
17352
|
+
function getTetronsAddOns() {
|
|
17353
|
+
return API_ADDONS;
|
|
17354
|
+
}
|
|
17359
17355
|
function isApiKeyValid() {
|
|
17360
17356
|
return API_VALID;
|
|
17361
17357
|
}
|
|
@@ -17367,6 +17363,7 @@ var index_default = EditorContent;
|
|
|
17367
17363
|
export {
|
|
17368
17364
|
EditorContent,
|
|
17369
17365
|
index_default as default,
|
|
17366
|
+
getTetronsAddOns,
|
|
17370
17367
|
getTetronsVersion,
|
|
17371
17368
|
initializeTetrons,
|
|
17372
17369
|
isApiKeyValid,
|