@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.js CHANGED
@@ -689,9 +689,17 @@ function incrementChar(text) {
689
689
  function changeBlockType(blocks, id, newType) {
690
690
  const currentIndex = blocks.findIndex((b) => b.id === id);
691
691
  if (currentIndex === -1) return blocks;
692
+ const currentBlock = blocks[currentIndex];
692
693
  const newBlock = createNewBlock(newType);
694
+ if (newType === "PARENTHETICAL") {
695
+ const cleanText = currentBlock.text.replace(/[()]/g, "");
696
+ newBlock.text = `(${cleanText})`;
697
+ } else {
698
+ newBlock.text = currentBlock.text;
699
+ }
693
700
  if (newType === "SCENE_HEADING") {
694
701
  newBlock.sceneNumber = generateNextSceneNumber(blocks, currentIndex);
702
+ newBlock.text = newBlock.text.toUpperCase();
695
703
  }
696
704
  return blocks.map((b) => b.id === id ? __spreadProps(__spreadValues({}, newBlock), { id: b.id }) : b);
697
705
  }
@@ -953,11 +961,13 @@ function useScreenplayEditor() {
953
961
  useEffect(() => {
954
962
  blocks.forEach((block) => {
955
963
  const element = refs.current[block.id];
956
- if (element && element.innerText !== block.text && document.activeElement !== element) {
957
- element.innerText = block.text;
964
+ if (element) {
965
+ if (element.innerText !== block.text && document.activeElement !== element) {
966
+ element.innerText = block.text;
967
+ }
958
968
  }
959
969
  });
960
- }, [blocks, isPageSplitEnabled, pageBreaks]);
970
+ }, [blocks]);
961
971
  useEffect(() => {
962
972
  const handleClickOutside = (e) => {
963
973
  const target = e.target;
@@ -1137,17 +1147,15 @@ function useScreenplayEditor() {
1137
1147
  const el = refs.current[focusedBlockId];
1138
1148
  if (el) {
1139
1149
  el.focus();
1140
- const newBlock = createNewBlock(newType);
1141
- el.innerText = newBlock.text;
1142
- if (newType === "PARENTHETICAL") {
1143
- setCaretPosition(el, 1);
1144
- } else {
1145
- setCaretPosition(el, newBlock.text.length);
1150
+ const currentBlock = blocks.find((b) => b.id === focusedBlockId);
1151
+ if (currentBlock) {
1152
+ const pos = newType === "PARENTHETICAL" ? el.innerText.length - 1 : el.innerText.length;
1153
+ setCaretPosition(el, Math.max(0, pos));
1146
1154
  }
1147
1155
  }
1148
- }, 0);
1156
+ }, 10);
1149
1157
  },
1150
- [focusedBlockId]
1158
+ [focusedBlockId, blocks]
1151
1159
  );
1152
1160
  const handleSelectCharacterExtension = useCallback(
1153
1161
  (extension) => {
@@ -1203,8 +1211,6 @@ function useScreenplayEditor() {
1203
1211
  const el = refs.current[id];
1204
1212
  if (el) {
1205
1213
  el.focus();
1206
- const newBlock = createNewBlock(newType);
1207
- el.innerText = newBlock.text;
1208
1214
  if (newType === "PARENTHETICAL") {
1209
1215
  setCaretPosition(el, 1);
1210
1216
  } else {