@vishu1301/script-writing 0.4.3 → 0.4.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.cjs CHANGED
@@ -711,9 +711,17 @@ function incrementChar(text) {
711
711
  function changeBlockType(blocks, id, newType) {
712
712
  const currentIndex = blocks.findIndex((b) => b.id === id);
713
713
  if (currentIndex === -1) return blocks;
714
+ const currentBlock = blocks[currentIndex];
714
715
  const newBlock = createNewBlock(newType);
716
+ if (newType === "PARENTHETICAL") {
717
+ const cleanText = currentBlock.text.replace(/[()]/g, "");
718
+ newBlock.text = `(${cleanText})`;
719
+ } else {
720
+ newBlock.text = currentBlock.text;
721
+ }
715
722
  if (newType === "SCENE_HEADING") {
716
723
  newBlock.sceneNumber = generateNextSceneNumber(blocks, currentIndex);
724
+ newBlock.text = newBlock.text.toUpperCase();
717
725
  }
718
726
  return blocks.map((b) => b.id === id ? __spreadProps(__spreadValues({}, newBlock), { id: b.id }) : b);
719
727
  }
@@ -975,11 +983,13 @@ function useScreenplayEditor() {
975
983
  react.useEffect(() => {
976
984
  blocks.forEach((block) => {
977
985
  const element = refs.current[block.id];
978
- if (element && element.innerText !== block.text && document.activeElement !== element) {
979
- element.innerText = block.text;
986
+ if (element) {
987
+ if (element.innerText !== block.text && document.activeElement !== element) {
988
+ element.innerText = block.text;
989
+ }
980
990
  }
981
991
  });
982
- }, [blocks, isPageSplitEnabled, pageBreaks]);
992
+ }, [blocks]);
983
993
  react.useEffect(() => {
984
994
  const handleClickOutside = (e) => {
985
995
  const target = e.target;
@@ -1159,17 +1169,15 @@ function useScreenplayEditor() {
1159
1169
  const el = refs.current[focusedBlockId];
1160
1170
  if (el) {
1161
1171
  el.focus();
1162
- const newBlock = createNewBlock(newType);
1163
- el.innerText = newBlock.text;
1164
- if (newType === "PARENTHETICAL") {
1165
- setCaretPosition(el, 1);
1166
- } else {
1167
- setCaretPosition(el, newBlock.text.length);
1172
+ const currentBlock = blocks.find((b) => b.id === focusedBlockId);
1173
+ if (currentBlock) {
1174
+ const pos = newType === "PARENTHETICAL" ? el.innerText.length - 1 : el.innerText.length;
1175
+ setCaretPosition(el, Math.max(0, pos));
1168
1176
  }
1169
1177
  }
1170
- }, 0);
1178
+ }, 10);
1171
1179
  },
1172
- [focusedBlockId]
1180
+ [focusedBlockId, blocks]
1173
1181
  );
1174
1182
  const handleSelectCharacterExtension = react.useCallback(
1175
1183
  (extension) => {
@@ -1225,8 +1233,6 @@ function useScreenplayEditor() {
1225
1233
  const el = refs.current[id];
1226
1234
  if (el) {
1227
1235
  el.focus();
1228
- const newBlock = createNewBlock(newType);
1229
- el.innerText = newBlock.text;
1230
1236
  if (newType === "PARENTHETICAL") {
1231
1237
  setCaretPosition(el, 1);
1232
1238
  } else {