@oh-just-another/state 0.63.0 → 0.65.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/editor.js CHANGED
@@ -2717,6 +2717,50 @@ export class Editor {
2717
2717
  tx.commit();
2718
2718
  this.notify();
2719
2719
  }
2720
+ /**
2721
+ * Text-carrier routing for mixed selections: merge a partial text style
2722
+ * into the element style of text elements and into the label style of
2723
+ * labelable shapes (seeding the label when missing); other elements are
2724
+ * skipped. One undo step. The selection toolbar writes through this so a
2725
+ * shape + text selection shares one text-colour / decoration control
2726
+ * instead of choosing between `updateStyle` and `updateLabelStyle`.
2727
+ */
2728
+ updateTextStyle(ids, partial) {
2729
+ if (this.readOnly)
2730
+ return;
2731
+ const tx = this._history.transaction();
2732
+ let changed = false;
2733
+ for (const id of ids) {
2734
+ const shape = getElement(this._scene, id);
2735
+ if (shape === undefined)
2736
+ continue;
2737
+ let r;
2738
+ if (isText(shape)) {
2739
+ r = updateElement(this._scene, id, (raw) => ({
2740
+ ...raw,
2741
+ style: { ...raw.style, ...partial },
2742
+ }));
2743
+ }
2744
+ else if (withLabel(shape).label !== undefined) {
2745
+ r = updateElement(this._scene, id, (raw) => {
2746
+ const l = withLabel(raw);
2747
+ return l.label === undefined
2748
+ ? l
2749
+ : { ...l, label: { ...l.label, style: { ...l.label.style, ...partial } } };
2750
+ });
2751
+ }
2752
+ else {
2753
+ continue;
2754
+ }
2755
+ this._scene = r.scene;
2756
+ tx.add(r.patch);
2757
+ changed = true;
2758
+ }
2759
+ if (!changed)
2760
+ return;
2761
+ tx.commit();
2762
+ this.notify();
2763
+ }
2720
2764
  /**
2721
2765
  * Merge font family / size into the embedded label. Picking an
2722
2766
  * explicit `fontSize` also leaves auto-fit mode (reference behaviour —
@@ -3714,17 +3758,58 @@ export class Editor {
3714
3758
  }
3715
3759
  /**
3716
3760
  * Update non-style text properties (`fontSize`, `fontFamily`,
3717
- * `maxWidth`) on every selected text shape. Non-text shapes are
3718
- * skipped. Single undo step. Used by the text contextual panel.
3761
+ * `maxWidth`) on every text shape in `ids`; labelable shapes route
3762
+ * `fontSize` / `fontFamily` to their embedded label instead (as
3763
+ * `updateLabelProps` — an explicit size leaves auto-fit). Anything else is
3764
+ * skipped. Single undo step. Used by the selection toolbar, so a mixed
3765
+ * text + shape selection shares one font control.
3719
3766
  */
3720
3767
  updateTextProps(ids, partial) {
3721
3768
  if (this.readOnly)
3722
3769
  return;
3723
- const result = computeUpdateTextProps(this._scene, ids, partial);
3724
- if (!result)
3770
+ const textIds = [];
3771
+ const labelIds = [];
3772
+ for (const id of ids) {
3773
+ const el = getElement(this._scene, id);
3774
+ if (el === undefined)
3775
+ continue;
3776
+ if (isText(el))
3777
+ textIds.push(id);
3778
+ else if (withLabel(el).label !== undefined)
3779
+ labelIds.push(id);
3780
+ }
3781
+ const tx = this._history.transaction();
3782
+ let changed = false;
3783
+ const text = computeUpdateTextProps(this._scene, textIds, partial);
3784
+ if (text) {
3785
+ this._scene = text.scene;
3786
+ tx.add(text.patch);
3787
+ changed = true;
3788
+ }
3789
+ const { fontFamily, fontSize } = partial;
3790
+ if (fontFamily !== undefined || fontSize !== undefined) {
3791
+ const labelPartial = {
3792
+ ...(fontFamily !== undefined ? { fontFamily } : {}),
3793
+ ...(fontSize !== undefined ? { fontSize } : {}),
3794
+ };
3795
+ for (const id of labelIds) {
3796
+ const r = updateElement(this._scene, id, (raw) => {
3797
+ const l = withLabel(raw);
3798
+ if (l.label === undefined)
3799
+ return l;
3800
+ const label = { ...l.label, ...labelPartial };
3801
+ if (fontSize !== undefined)
3802
+ delete label.autoFit;
3803
+ return { ...l, label };
3804
+ });
3805
+ this._scene = r.scene;
3806
+ tx.add(r.patch);
3807
+ changed = true;
3808
+ }
3809
+ }
3810
+ if (!changed)
3725
3811
  return;
3726
- this._scene = result.scene;
3727
- this._history.push(result.patch);
3812
+ tx.commit();
3728
3813
  this.notify();
3729
3814
  }
3730
3815
  /**