@rohal12/spindle 0.64.15 → 0.64.16

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.
@@ -16913,7 +16913,7 @@ var SETTABLE_NAME = /^[A-Za-z_:][\w:.-]*$/;
16913
16913
  */
16914
16914
  function setRawAttribute(el, name, value) {
16915
16915
  if (SETTABLE_NAME.test(name)) {
16916
- el.setAttribute(name, value);
16916
+ if (el.getAttribute(name) !== value) el.setAttribute(name, value);
16917
16917
  return;
16918
16918
  }
16919
16919
  const parsed = parseHtmlInert(`<i ${name}=""></i>`).firstChild.attributes[0];
@@ -16941,7 +16941,10 @@ function isNativeDefault(tag, name) {
16941
16941
  * loads, also drops an empty `class` and `translate="no"`.
16942
16942
  *
16943
16943
  * On HTML elements an upper-case prop name avoids all of these, and
16944
- * setAttribute lower-cases it back. Names compat matches in any case
16944
+ * setAttribute lower-cases it back. Native tags also pass lowercase `is`
16945
+ * so customized built-ins initialize when Preact creates them (#733),
16946
+ * and set its attribute directly in case the component owns an `is` property.
16947
+ * Names compat matches in any case
16945
16948
  * (`on…`, `translate`), names setAttribute rejects, and on SVG elements,
16946
16949
  * whose names are case-sensitive, Preact's reserved names and the `class`
16947
16950
  * and `className` compat rewrites (dropping an empty `class`, turning
@@ -16954,7 +16957,10 @@ function splitAttributes(attributes, foreign, tag) {
16954
16957
  for (const [name, value, written, bound] of attributes) {
16955
16958
  const lower = name.toLowerCase();
16956
16959
  if (BOOLEAN_ATTRIBUTES.has(lower) && written !== "" && value === "") continue;
16957
- else if (!foreign && LIVE_PROPERTIES.has(lower)) {
16960
+ else if (!foreign && lower === "is" && !tag.includes("-")) {
16961
+ props.is = value;
16962
+ direct.push([name, value]);
16963
+ } else if (!foreign && LIVE_PROPERTIES.has(lower)) {
16958
16964
  if (!bound && isNativeDefault(tag, lower)) defaults.push([name.toUpperCase(), lower === "value" ? value : ""]);
16959
16965
  else props[lower] = lower !== "value" && written === "" ? true : value;
16960
16966
  } else if (!SETTABLE_NAME.test(name) || lower.startsWith("on") || lower === "translate" || foreign && (FOREIGN_DIRECT.has(name) || name === "__proto__")) direct.push([name, value]);
@@ -16973,13 +16979,15 @@ function splitAttributes(attributes, foreign, tag) {
16973
16979
  */
16974
16980
  function useDirectAttributes(direct) {
16975
16981
  const elementRef = useRef(null);
16982
+ const currentDirect = useRef(direct);
16983
+ currentDirect.current = direct;
16976
16984
  const directKey = JSON.stringify(direct);
16977
16985
  useLayoutEffect(() => {
16978
16986
  const el = elementRef.current;
16979
16987
  if (!el || direct.length === 0) return;
16980
16988
  for (const [name, value] of direct) setRawAttribute(el, name, value);
16981
16989
  return () => {
16982
- for (const [name] of direct) el.removeAttribute(name);
16990
+ for (const [name] of direct) if (!currentDirect.current.some(([next]) => next === name)) el.removeAttribute(name);
16983
16991
  };
16984
16992
  }, [directKey]);
16985
16993
  return direct.length > 0 ? elementRef : void 0;
@@ -19507,7 +19515,7 @@ function replacesState(fn) {
19507
19515
  */
19508
19516
  function moveInHistory(get, set, step) {
19509
19517
  const { historyIndex, history } = get();
19510
- const target = historyIndex + step;
19518
+ let target = historyIndex + step;
19511
19519
  if (target < 0 || target >= history.length) return;
19512
19520
  finishEnteredMoment(get, set);
19513
19521
  const previousPassage = get().currentPassage;
@@ -19515,9 +19523,11 @@ function moveInHistory(get, set, step) {
19515
19523
  const navigation = get().navigationId;
19516
19524
  emit("beforenavigate", targetPassage);
19517
19525
  if (get().navigationId !== navigation) return;
19526
+ target = get().historyIndex + step;
19527
+ if (target < 0 || target >= get().history.length) return;
19518
19528
  const restoredVars = deepClone(reconstructVarsAt(target));
19519
19529
  set((state) => {
19520
- state.historyIndex += step;
19530
+ state.historyIndex = target;
19521
19531
  state.currentPassage = state.history[state.historyIndex].passage;
19522
19532
  state.navigationId++;
19523
19533
  state.variables = restoredVars;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rohal12/spindle",
3
- "version": "0.64.15",
3
+ "version": "0.64.16",
4
4
  "type": "module",
5
5
  "description": "A Preact-based story format for Twine 2.",
6
6
  "license": "Unlicense",
@@ -108,7 +108,7 @@
108
108
  "@vitest/coverage-v8": "^5.0.3",
109
109
  "codemirror": "^5.65.21",
110
110
  "fake-indexeddb": "^6.2.5",
111
- "fallow": "3.36.0",
111
+ "fallow": "3.38.1",
112
112
  "fast-check": "^4.10.2",
113
113
  "happy-dom": "^21.0.4",
114
114
  "husky": "^9.1.7",
@@ -540,7 +540,8 @@ const SETTABLE_NAME = /^[A-Za-z_:][\w:.-]*$/;
540
540
  */
541
541
  function setRawAttribute(el: Element, name: string, value: string) {
542
542
  if (SETTABLE_NAME.test(name)) {
543
- el.setAttribute(name, value);
543
+ // Preact may already have set it; avoid firing custom-element callbacks twice.
544
+ if (el.getAttribute(name) !== value) el.setAttribute(name, value);
544
545
  return;
545
546
  }
546
547
  const parsed = (parseHtmlInert(`<i ${name}=""></i>`).firstChild as Element)
@@ -571,7 +572,10 @@ function isNativeDefault(tag: string, name: string): boolean {
571
572
  * loads, also drops an empty `class` and `translate="no"`.
572
573
  *
573
574
  * On HTML elements an upper-case prop name avoids all of these, and
574
- * setAttribute lower-cases it back. Names compat matches in any case
575
+ * setAttribute lower-cases it back. Native tags also pass lowercase `is`
576
+ * so customized built-ins initialize when Preact creates them (#733),
577
+ * and set its attribute directly in case the component owns an `is` property.
578
+ * Names compat matches in any case
575
579
  * (`on…`, `translate`), names setAttribute rejects, and on SVG elements,
576
580
  * whose names are case-sensitive, Preact's reserved names and the `class`
577
581
  * and `className` compat rewrites (dropping an empty `class`, turning
@@ -591,6 +595,9 @@ function splitAttributes(
591
595
  const lower = name.toLowerCase();
592
596
  if (BOOLEAN_ATTRIBUTES.has(lower) && written !== '' && value === '') {
593
597
  continue;
598
+ } else if (!foreign && lower === 'is' && !tag.includes('-')) {
599
+ props.is = value;
600
+ direct.push([name, value]);
594
601
  } else if (!foreign && LIVE_PROPERTIES.has(lower)) {
595
602
  if (!bound && isNativeDefault(tag, lower)) {
596
603
  defaults.push([name.toUpperCase(), lower === 'value' ? value : '']);
@@ -621,13 +628,20 @@ function useDirectAttributes(
621
628
  direct: [string, string][],
622
629
  ): RefObject<Element | null> | undefined {
623
630
  const elementRef = useRef<Element>(null);
631
+ const currentDirect = useRef(direct);
632
+ currentDirect.current = direct;
624
633
  const directKey = JSON.stringify(direct);
625
634
  useLayoutEffect(() => {
626
635
  const el = elementRef.current;
627
636
  if (!el || direct.length === 0) return;
628
637
  for (const [name, value] of direct) setRawAttribute(el, name, value);
629
638
  return () => {
630
- for (const [name] of direct) el.removeAttribute(name);
639
+ for (const [name] of direct) {
640
+ // Keep retained attributes through updates without remove/add callbacks.
641
+ if (!currentDirect.current.some(([next]) => next === name)) {
642
+ el.removeAttribute(name);
643
+ }
644
+ }
631
645
  };
632
646
  }, [directKey]);
633
647
  return direct.length > 0 ? elementRef : undefined;
package/src/store.ts CHANGED
@@ -509,7 +509,7 @@ function replacesState(fn: () => void): boolean {
509
509
  */
510
510
  function moveInHistory(get: StoreGet, set: StoreSet, step: -1 | 1): void {
511
511
  const { historyIndex, history } = get();
512
- const target = historyIndex + step;
512
+ let target = historyIndex + step;
513
513
  if (target < 0 || target >= history.length) return;
514
514
  finishEnteredMoment(get, set);
515
515
 
@@ -523,10 +523,15 @@ function moveInHistory(get: StoreGet, set: StoreSet, step: -1 | 1): void {
523
523
  emit('beforenavigate', targetPassage);
524
524
  if (get().navigationId !== navigation) return;
525
525
 
526
+ // Lowering maxHistory in the callback can trim either end without a new
527
+ // navigation. The retained moments stay adjacent to the current one;
528
+ // resolve the target again, or cancel if it was removed (#732).
529
+ target = get().historyIndex + step;
530
+ if (target < 0 || target >= get().history.length) return;
526
531
  const restoredVars = deepClone(reconstructVarsAt(target));
527
532
 
528
533
  set((state) => {
529
- state.historyIndex += step;
534
+ state.historyIndex = target;
530
535
  state.currentPassage = state.history[state.historyIndex]!.passage;
531
536
  state.navigationId++;
532
537
  state.variables = restoredVars;