@vishu1301/script-writing 1.1.8 → 1.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/dist/index.cjs +10 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +10 -42
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2304,8 +2304,8 @@ function ScriptBreakdownSceneView({
|
|
|
2304
2304
|
] })
|
|
2305
2305
|
] }) });
|
|
2306
2306
|
}
|
|
2307
|
-
function useScriptBreakdownScene(
|
|
2308
|
-
const [tags, setTags] = react.useState(preLoadedTags || []);
|
|
2307
|
+
function useScriptBreakdownScene(options) {
|
|
2308
|
+
const [tags, setTags] = react.useState(options.preLoadedTags || []);
|
|
2309
2309
|
const [selectionMenu, setSelectionMenu] = react.useState(null);
|
|
2310
2310
|
const autoTaggedSceneRef = react.useRef(null);
|
|
2311
2311
|
const [scene, setScene] = react.useState(null);
|
|
@@ -2320,7 +2320,7 @@ function useScriptBreakdownScene(scene_url, fetchOptions, onAISummarize, onTagAd
|
|
|
2320
2320
|
setIsLoading(true);
|
|
2321
2321
|
const fetchScene = async () => {
|
|
2322
2322
|
try {
|
|
2323
|
-
const response = await fetch(scene_url, fetchOptions);
|
|
2323
|
+
const response = await fetch(options.scene_url, options.fetchOptions);
|
|
2324
2324
|
if (response.ok) {
|
|
2325
2325
|
const text = await response.text();
|
|
2326
2326
|
setScene({ content: text });
|
|
@@ -2377,8 +2377,9 @@ function useScriptBreakdownScene(scene_url, fetchOptions, onAISummarize, onTagAd
|
|
|
2377
2377
|
return [...new Set(chars)];
|
|
2378
2378
|
}, [blocks]);
|
|
2379
2379
|
const handleAISummarize = async () => {
|
|
2380
|
+
var _a;
|
|
2380
2381
|
setIsSummarizing(true);
|
|
2381
|
-
const res = await (onAISummarize == null ? void 0 :
|
|
2382
|
+
const res = await ((_a = options.onAISummarize) == null ? void 0 : _a.call(options, scene.content));
|
|
2382
2383
|
if (res.ok) {
|
|
2383
2384
|
const data = await res.json();
|
|
2384
2385
|
setIsSummarizing(false);
|
|
@@ -2440,45 +2441,10 @@ function useScriptBreakdownScene(scene_url, fetchOptions, onAISummarize, onTagAd
|
|
|
2440
2441
|
setSubLocations((prev) => prev.filter((loc) => loc !== subLocation));
|
|
2441
2442
|
}, []);
|
|
2442
2443
|
react.useEffect(() => {
|
|
2443
|
-
setTags([]);
|
|
2444
2444
|
setSubLocations([]);
|
|
2445
2445
|
setSceneBrief("");
|
|
2446
2446
|
autoTaggedSceneRef.current = null;
|
|
2447
|
-
}, [scene_url]);
|
|
2448
|
-
react.useEffect(() => {
|
|
2449
|
-
if (blocks.length > 0 && characters.length > 0 && autoTaggedSceneRef.current !== scene) {
|
|
2450
|
-
const autoTags = [];
|
|
2451
|
-
const escapeRegExp = (string) => string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2452
|
-
const sortedChars = [...characters].sort((a, b) => b.length - a.length);
|
|
2453
|
-
blocks.forEach((block) => {
|
|
2454
|
-
sortedChars.forEach((char) => {
|
|
2455
|
-
const escapedChar = escapeRegExp(char);
|
|
2456
|
-
const regex = new RegExp(`\\b${escapedChar}\\b`, "gi");
|
|
2457
|
-
let match;
|
|
2458
|
-
while ((match = regex.exec(block.text)) !== null) {
|
|
2459
|
-
const isOverlapping = autoTags.some(
|
|
2460
|
-
(t) => t.block_id === block.id && match.index + char.length > t.start_index && match.index < t.end_index
|
|
2461
|
-
);
|
|
2462
|
-
if (!isOverlapping) {
|
|
2463
|
-
autoTags.push({
|
|
2464
|
-
id: uuid(),
|
|
2465
|
-
block_id: block.id,
|
|
2466
|
-
category_id: "CAST",
|
|
2467
|
-
name: block.text.substring(
|
|
2468
|
-
match.index,
|
|
2469
|
-
match.index + char.length
|
|
2470
|
-
),
|
|
2471
|
-
start_index: match.index,
|
|
2472
|
-
end_index: match.index + char.length
|
|
2473
|
-
});
|
|
2474
|
-
}
|
|
2475
|
-
}
|
|
2476
|
-
});
|
|
2477
|
-
});
|
|
2478
|
-
setTags(autoTags);
|
|
2479
|
-
autoTaggedSceneRef.current = scene;
|
|
2480
|
-
}
|
|
2481
|
-
}, [blocks, characters, scene]);
|
|
2447
|
+
}, [options.scene_url]);
|
|
2482
2448
|
const clearSelection = react.useCallback(() => {
|
|
2483
2449
|
var _a;
|
|
2484
2450
|
setSelectionMenu(null);
|
|
@@ -2566,6 +2532,7 @@ function useScriptBreakdownScene(scene_url, fetchOptions, onAISummarize, onTagAd
|
|
|
2566
2532
|
}
|
|
2567
2533
|
};
|
|
2568
2534
|
const addTag = async (categoryId) => {
|
|
2535
|
+
var _a;
|
|
2569
2536
|
if (!selectionMenu) return;
|
|
2570
2537
|
const newTag = {
|
|
2571
2538
|
id: uuid(),
|
|
@@ -2583,13 +2550,14 @@ function useScriptBreakdownScene(scene_url, fetchOptions, onAISummarize, onTagAd
|
|
|
2583
2550
|
});
|
|
2584
2551
|
clearSelection();
|
|
2585
2552
|
try {
|
|
2586
|
-
await (onTagAdded == null ? void 0 :
|
|
2553
|
+
await ((_a = options.onTagAdded) == null ? void 0 : _a.call(options, newTag));
|
|
2587
2554
|
} catch (error2) {
|
|
2588
2555
|
console.error("Failed to add tag:", error2);
|
|
2589
2556
|
setTags((prev) => prev.filter((t) => t.id !== newTag.id));
|
|
2590
2557
|
}
|
|
2591
2558
|
};
|
|
2592
2559
|
const removeTag = async (e, id) => {
|
|
2560
|
+
var _a;
|
|
2593
2561
|
e.stopPropagation();
|
|
2594
2562
|
e.preventDefault();
|
|
2595
2563
|
const tagToRemove = tags.find((t) => t.id === id);
|
|
@@ -2597,7 +2565,7 @@ function useScriptBreakdownScene(scene_url, fetchOptions, onAISummarize, onTagAd
|
|
|
2597
2565
|
setTags((prev) => prev.filter((t) => t.id !== id));
|
|
2598
2566
|
clearSelection();
|
|
2599
2567
|
try {
|
|
2600
|
-
await (onTagRemoved == null ? void 0 :
|
|
2568
|
+
await ((_a = options.onTagRemoved) == null ? void 0 : _a.call(options, id));
|
|
2601
2569
|
} catch (error2) {
|
|
2602
2570
|
console.error("Failed to remove tag:", error2);
|
|
2603
2571
|
setTags((prev) => [...prev, tagToRemove]);
|