@vishu1301/script-writing 1.2.3 → 1.2.4

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.d.cts CHANGED
@@ -123,6 +123,7 @@ interface UseScriptBreakdownSceneOptions {
123
123
  fetchOptions?: RequestInit;
124
124
  onAISummarize?: (scene: any) => void;
125
125
  onTagAdded?: (tag: Tag) => void;
126
+ onTagsBulkAdded?: (tags: Tag[], summary?: string) => Promise<void>;
126
127
  onTagRemoved?: (tagId: string) => void;
127
128
  onTagUpdated?: (tagId: string, categoryId: ElementCategory) => void;
128
129
  preLoadedTags?: Tag[];
package/dist/index.d.ts CHANGED
@@ -123,6 +123,7 @@ interface UseScriptBreakdownSceneOptions {
123
123
  fetchOptions?: RequestInit;
124
124
  onAISummarize?: (scene: any) => void;
125
125
  onTagAdded?: (tag: Tag) => void;
126
+ onTagsBulkAdded?: (tags: Tag[], summary?: string) => Promise<void>;
126
127
  onTagRemoved?: (tagId: string) => void;
127
128
  onTagUpdated?: (tagId: string, categoryId: ElementCategory) => void;
128
129
  preLoadedTags?: Tag[];
package/dist/index.js CHANGED
@@ -2308,9 +2308,122 @@ function useScriptBreakdownScene(options) {
2308
2308
  end_index: aiTag.end_index
2309
2309
  });
2310
2310
  });
2311
+ if (newTags.length > 0) {
2312
+ const originalTags = tags;
2313
+ setTags((prev) => {
2314
+ const merged = [...prev];
2315
+ newTags.forEach((newTag) => {
2316
+ const isOverlapping = merged.some(
2317
+ (t) => t.block_id === newTag.block_id && newTag.end_index > t.start_index && newTag.start_index < t.end_index
2318
+ );
2319
+ if (!isOverlapping) {
2320
+ merged.push(newTag);
2321
+ }
2322
+ });
2323
+ return merged;
2324
+ });
2325
+ try {
2326
+ if (options.onTagsBulkAdded) {
2327
+ await options.onTagsBulkAdded(newTags, parsedSummaryData.summarise);
2328
+ }
2329
+ } catch (error2) {
2330
+ console.error("Failed to bulk add AI-generated tags:", error2);
2331
+ setTags(originalTags);
2332
+ }
2333
+ }
2334
+ return data;
2335
+ } else {
2336
+ setIsSummarizing(false);
2337
+ console.error("Failed to summarize scene:", res);
2338
+ }
2339
+ };
2340
+ const bulkCreateTags = useCallback(async () => {
2341
+ if (blocks.length === 0) return;
2342
+ const newTags = [];
2343
+ const seenCharacters = /* @__PURE__ */ new Set();
2344
+ const timeOfDays = ["DAY", "NIGHT"];
2345
+ const isTimeOfDay = (str) => timeOfDays.includes(str.toUpperCase());
2346
+ blocks.forEach((block) => {
2347
+ if (block.type === "CHARACTER") {
2348
+ const text = block.text.trim();
2349
+ const parenIndex = text.indexOf("(");
2350
+ const charName = parenIndex > -1 ? text.substring(0, parenIndex).trim() : text;
2351
+ if (charName && !seenCharacters.has(charName.toUpperCase())) {
2352
+ seenCharacters.add(charName.toUpperCase());
2353
+ const startIndex = text.indexOf(charName);
2354
+ if (startIndex !== -1) {
2355
+ newTags.push({
2356
+ id: uuid(),
2357
+ block_id: block.id,
2358
+ category_id: "CAST",
2359
+ name: charName,
2360
+ start_index: startIndex,
2361
+ end_index: startIndex + charName.length
2362
+ });
2363
+ }
2364
+ }
2365
+ } else if (block.type === "SCENE_HEADING") {
2366
+ const text = block.text.trim();
2367
+ const typeMatch = text.match(
2368
+ /^(INT\/EXT|INT\.?\/EXT\.?|INT\.EXT\.?|INT|EXT|I\/E)\.?\s+/i
2369
+ );
2370
+ let remainingText = text;
2371
+ let offset = 0;
2372
+ if (typeMatch) {
2373
+ offset = typeMatch[0].length;
2374
+ remainingText = text.substring(offset);
2375
+ }
2376
+ const parts = remainingText.split(/\s+-\s+/);
2377
+ if (parts.length > 0) {
2378
+ const locationName = parts[0].trim();
2379
+ const locStart = text.indexOf(locationName, offset);
2380
+ if (locStart !== -1 && locationName) {
2381
+ newTags.push({
2382
+ id: uuid(),
2383
+ block_id: block.id,
2384
+ category_id: "LOCATION",
2385
+ name: locationName,
2386
+ start_index: locStart,
2387
+ end_index: locStart + locationName.length
2388
+ });
2389
+ }
2390
+ if (parts.length > 1) {
2391
+ const secondPart = parts[1].trim();
2392
+ const isLast = parts.length === 2;
2393
+ if (!isLast || !isTimeOfDay(secondPart)) {
2394
+ const subLocStart = text.indexOf(
2395
+ secondPart,
2396
+ locStart + locationName.length
2397
+ );
2398
+ if (subLocStart !== -1 && secondPart) {
2399
+ newTags.push({
2400
+ id: uuid(),
2401
+ block_id: block.id,
2402
+ category_id: "SUBLOCATION",
2403
+ name: secondPart,
2404
+ start_index: subLocStart,
2405
+ end_index: subLocStart + secondPart.length
2406
+ });
2407
+ }
2408
+ }
2409
+ }
2410
+ }
2411
+ }
2412
+ });
2413
+ if (newTags.length > 0) {
2414
+ const originalTags = tags;
2311
2415
  setTags((prev) => {
2312
2416
  const merged = [...prev];
2417
+ const existingChars = new Set(
2418
+ merged.filter(
2419
+ (t) => t.category_id === "CHARACTER" || t.category_id === "CAST"
2420
+ ).map((t) => t.name.toUpperCase())
2421
+ );
2313
2422
  newTags.forEach((newTag) => {
2423
+ if (newTag.category_id === "CHARACTER") {
2424
+ if (existingChars.has(newTag.name.toUpperCase())) return;
2425
+ existingChars.add(newTag.name.toUpperCase());
2426
+ }
2314
2427
  const isOverlapping = merged.some(
2315
2428
  (t) => t.block_id === newTag.block_id && newTag.end_index > t.start_index && newTag.start_index < t.end_index
2316
2429
  );
@@ -2320,12 +2433,16 @@ function useScriptBreakdownScene(options) {
2320
2433
  });
2321
2434
  return merged;
2322
2435
  });
2323
- return data;
2324
- } else {
2325
- setIsSummarizing(false);
2326
- console.error("Failed to summarize scene:", res);
2436
+ try {
2437
+ if (options.onTagsBulkAdded) {
2438
+ await options.onTagsBulkAdded(newTags);
2439
+ }
2440
+ } catch (error2) {
2441
+ console.error("Failed to bulk create tags:", error2);
2442
+ setTags(originalTags);
2443
+ }
2327
2444
  }
2328
- };
2445
+ }, [blocks, tags, options.onTagsBulkAdded]);
2329
2446
  useEffect(() => {
2330
2447
  setSceneBrief("");
2331
2448
  autoTaggedSceneRef.current = null;
@@ -2340,6 +2457,18 @@ function useScriptBreakdownScene(options) {
2340
2457
  });
2341
2458
  }
2342
2459
  }, [options.preLoadedTags]);
2460
+ useEffect(() => {
2461
+ const doBulkCreate = async () => {
2462
+ if (blocks.length > 0 && !autoTaggedSceneRef.current) {
2463
+ const hasPreloadedTags = options.preLoadedTags && options.preLoadedTags.length > 0;
2464
+ if (!hasPreloadedTags) {
2465
+ autoTaggedSceneRef.current = options.scene_url;
2466
+ await bulkCreateTags();
2467
+ }
2468
+ }
2469
+ };
2470
+ doBulkCreate();
2471
+ }, [blocks, options.scene_url, options.preLoadedTags, bulkCreateTags]);
2343
2472
  const clearSelection = useCallback(() => {
2344
2473
  var _a;
2345
2474
  setSelectionMenu(null);