pict-section-form 1.3.6 → 1.3.8

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.
@@ -42,6 +42,22 @@ class PictDynamicFormsSolverBehaviors extends libPictProvider
42
42
  /** @type {string} */
43
43
  this.cssHideSectionClass = 'pict-section-form-hidden-section';
44
44
  this.cssHideGroupClass = 'pict-section-form-hidden-group';
45
+
46
+ // #SECTION-<formID> and #GROUP-<formID>-<hash> are both emitted by the section template, so a
47
+ // render() regenerates them without the hide class and the hide silently reverts. Record what
48
+ // was asked for so reapplySectionVisibility can restore it after a render.
49
+ /** @type {Record<string, boolean>} */
50
+ this.sectionVisibilityState = {};
51
+ /** @type {Record<string, boolean>} */
52
+ this.groupVisibilityState = {};
53
+
54
+ // Same story for every solver that decorates the DOM -- highlight classes and inline background
55
+ // colors all land on markup the section template regenerates. Keyed by what the decoration
56
+ // targets so re-applying one overwrites rather than accumulating.
57
+ /** @type {Record<string, {Section: string, Method: string, Arguments: Array<any>}>} */
58
+ this.decorationState = {};
59
+ /** @type {boolean} */
60
+ this.decorationReplayInProgress = false;
45
61
  /** @type {string} */
46
62
  this.cssTabularRowHighlightClass = 'pict-tabular-row-highlight';
47
63
  /** @type {string} */
@@ -367,6 +383,10 @@ class PictDynamicFormsSolverBehaviors extends libPictProvider
367
383
  return false;
368
384
  }
369
385
 
386
+ // Record BEFORE the DOM guard below: the guard short-circuits when the DOM already matches, and
387
+ // the state map has to stay accurate even then so a later render can restore it.
388
+ this.sectionVisibilityState[pSectionHash] = false;
389
+
370
390
  if (this.pict.ContentAssignment.hasClass(this.getSectionSelector(tmpSectionView.formID), this.cssHideSectionClass))
371
391
  {
372
392
  // Already hidden.
@@ -386,6 +406,8 @@ class PictDynamicFormsSolverBehaviors extends libPictProvider
386
406
  return false;
387
407
  }
388
408
 
409
+ this.sectionVisibilityState[pSectionHash] = true;
410
+
389
411
  if (!this.pict.ContentAssignment.hasClass(this.getSectionSelector(tmpSectionView.formID), this.cssHideSectionClass))
390
412
  {
391
413
  // Already visible.
@@ -422,6 +444,8 @@ class PictDynamicFormsSolverBehaviors extends libPictProvider
422
444
  return false;
423
445
  }
424
446
 
447
+ this.groupVisibilityState[this.getGroupVisibilityStateKey(pSectionHash, pGroupHash)] = false;
448
+
425
449
  if (this.pict.ContentAssignment.hasClass(this.getGroupSelector(tmpGroupView.formID, pGroupHash), this.cssHideGroupClass))
426
450
  {
427
451
  // Already hidden.
@@ -441,6 +465,8 @@ class PictDynamicFormsSolverBehaviors extends libPictProvider
441
465
  return false;
442
466
  }
443
467
 
468
+ this.groupVisibilityState[this.getGroupVisibilityStateKey(pSectionHash, pGroupHash)] = true;
469
+
444
470
  if (!this.pict.ContentAssignment.hasClass(this.getGroupSelector(tmpGroupView.formID, pGroupHash), this.cssHideGroupClass))
445
471
  {
446
472
  // Already visible.
@@ -451,6 +477,196 @@ class PictDynamicFormsSolverBehaviors extends libPictProvider
451
477
  return true;
452
478
  }
453
479
 
480
+ /**
481
+ * @param {string} pSectionHash
482
+ * @param {string} pGroupHash
483
+ *
484
+ * @return {string} - The groupVisibilityState key for a section/group pair.
485
+ */
486
+ getGroupVisibilityStateKey(pSectionHash, pGroupHash)
487
+ {
488
+ return `${pSectionHash}::${pGroupHash}`;
489
+ }
490
+
491
+ /**
492
+ * Re-apply a section's recorded visibility (and that of its groups) after a render regenerated its DOM.
493
+ *
494
+ * Every render path -- DynamicColumns rebuild, dependent-view rebuild, row add/delete/move, the
495
+ * group-scoped swap in renderGroupInPlace -- repaints those elements with only their manifest
496
+ * CSSClass, and solvers run BEFORE the marshal that triggers them, so nothing else puts the hide
497
+ * back. Called from the view's onAfterRender so one restore covers them all. A section with no
498
+ * recorded state is left as the template rendered it.
499
+ *
500
+ * @param {string} pSectionHash - The section that was just rendered.
501
+ *
502
+ * @return {void}
503
+ */
504
+ reapplySectionVisibility(pSectionHash)
505
+ {
506
+ if (typeof pSectionHash !== 'string' || pSectionHash.length < 1)
507
+ {
508
+ return;
509
+ }
510
+
511
+ if (pSectionHash in this.sectionVisibilityState)
512
+ {
513
+ this.setSectionVisibility(pSectionHash, this.sectionVisibilityState[pSectionHash] ? 1 : 0);
514
+ }
515
+
516
+ const tmpGroupKeyPrefix = `${pSectionHash}::`;
517
+ const tmpGroupKeys = Object.keys(this.groupVisibilityState);
518
+ for (let i = 0; i < tmpGroupKeys.length; i++)
519
+ {
520
+ if (tmpGroupKeys[i].indexOf(tmpGroupKeyPrefix) !== 0)
521
+ {
522
+ continue;
523
+ }
524
+ const tmpGroupHash = tmpGroupKeys[i].substring(tmpGroupKeyPrefix.length);
525
+ this.setGroupVisibility(pSectionHash, tmpGroupHash, this.groupVisibilityState[tmpGroupKeys[i]] ? 1 : 0);
526
+ }
527
+ }
528
+
529
+ /**
530
+ * Remember a DOM decoration a solver just applied so it can be replayed after a render.
531
+ *
532
+ * @param {string} pSectionHash - The section the decoration targets.
533
+ * @param {string} pKey - Stable identity for what is decorated; a repeat overwrites it.
534
+ * @param {string} pMethod - The method on this provider that applies it.
535
+ * @param {Array<any>} pArguments - The arguments to replay it with.
536
+ *
537
+ * @return {void}
538
+ */
539
+ recordDecoration(pSectionHash, pKey, pMethod, pArguments)
540
+ {
541
+ if (this.decorationReplayInProgress)
542
+ {
543
+ return;
544
+ }
545
+ this.decorationState[`${pSectionHash}::${pKey}`] = { Section: pSectionHash, Method: pMethod, Arguments: pArguments };
546
+ }
547
+
548
+ /**
549
+ * Replay every decoration recorded against a section after a render repainted its markup.
550
+ *
551
+ * Highlight classes and inline colors live on rows, cells and containers that the section
552
+ * template regenerates, exactly like the hide classes. Replay is idempotent: each entry is
553
+ * keyed by its target, and a recorded "remove" simply re-runs a removal against fresh markup.
554
+ *
555
+ * @param {string} pSectionHash - The section that was just rendered.
556
+ *
557
+ * @return {void}
558
+ */
559
+ reapplySectionDecorations(pSectionHash)
560
+ {
561
+ if (typeof pSectionHash !== 'string' || pSectionHash.length < 1)
562
+ {
563
+ return;
564
+ }
565
+
566
+ const tmpKeys = Object.keys(this.decorationState);
567
+ this.decorationReplayInProgress = true;
568
+ try
569
+ {
570
+ for (let i = 0; i < tmpKeys.length; i++)
571
+ {
572
+ const tmpEntry = this.decorationState[tmpKeys[i]];
573
+ if (!tmpEntry || (tmpEntry.Section !== pSectionHash) || (typeof this[tmpEntry.Method] !== 'function'))
574
+ {
575
+ continue;
576
+ }
577
+ this[tmpEntry.Method].apply(this, tmpEntry.Arguments);
578
+ }
579
+ }
580
+ finally
581
+ {
582
+ this.decorationReplayInProgress = false;
583
+ }
584
+ }
585
+
586
+ /**
587
+ * Restore everything a solver put on this section's DOM that a render just wiped -- visibility
588
+ * first, then decorations. This is what the section view calls from its own onAfterRender.
589
+ *
590
+ * @param {string} pSectionHash - The section that was just rendered.
591
+ *
592
+ * @return {void}
593
+ */
594
+ reapplySectionDOMState(pSectionHash)
595
+ {
596
+ this.reapplySectionVisibility(pSectionHash);
597
+ this.reapplySectionDecorations(pSectionHash);
598
+ }
599
+
600
+ /**
601
+ * Re-render a single group in place, leaving the rest of the section's DOM untouched.
602
+ *
603
+ * The section template is one string (wrap/section prefixes + every group's
604
+ * generateGroupLayoutTemplate + postfixes), so a normal render rebuilds all of it.
605
+ * This regenerates just the requested group's slice and swaps that one element.
606
+ *
607
+ * Init is then run the normal way (the view's own post-render pass) rather than being
608
+ * hand-scoped: input providers guard their own re-initialization (a select2 picker
609
+ * checks for an existing instance before creating one), so untouched groups no-op and
610
+ * only the freshly-rendered group actually initializes.
611
+ *
612
+ * @param {import('../views/Pict-View-DynamicForm.js')} pView - The section view.
613
+ * @param {string} pGroupHash - The group to re-render.
614
+ * @return {boolean} - True if the group was rendered in place; false to fall back to a full render.
615
+ */
616
+ renderGroupInPlace(pView, pGroupHash)
617
+ {
618
+ try
619
+ {
620
+ if (!pView || !pView.formID || (typeof pView.getGroupIndexFromHash !== 'function'))
621
+ {
622
+ return false;
623
+ }
624
+ const tmpGroupIndex = pView.getGroupIndexFromHash(pGroupHash);
625
+ if (tmpGroupIndex < 0)
626
+ {
627
+ return false;
628
+ }
629
+ const tmpGroup = pView.getGroup(tmpGroupIndex);
630
+ const tmpGenerator = this.pict.providers.MetatemplateGenerator;
631
+ if (!tmpGroup || !tmpGenerator || (typeof tmpGenerator.getGroupLayoutProvider !== 'function'))
632
+ {
633
+ return false;
634
+ }
635
+ const tmpLayout = tmpGenerator.getGroupLayoutProvider(pView, tmpGroup);
636
+ if (!tmpLayout || (typeof tmpLayout.generateGroupLayoutTemplate !== 'function'))
637
+ {
638
+ return false;
639
+ }
640
+ const tmpElements = this.pict.ContentAssignment.getElement(`#GROUP-${pView.formID}-${tmpGroup.Hash}`);
641
+ const tmpElement = (tmpElements && tmpElements.length) ? tmpElements[0] : null;
642
+ if (!tmpElement || (typeof tmpElement.outerHTML !== 'string'))
643
+ {
644
+ return false;
645
+ }
646
+
647
+ // Same parse shape the view uses for the whole section: the view is Context[0],
648
+ // which the group templates reference for formID/UUID/Hash.
649
+ const tmpTemplateHash = `Pict-Form-Template-Group-InPlace-${pView.options.Hash}-G${tmpGroup.GroupIndex}`;
650
+ this.pict.TemplateProvider.addTemplate(tmpTemplateHash, tmpLayout.generateGroupLayoutTemplate(pView, tmpGroup));
651
+ const tmpRecordAddress = pView.options.DefaultTemplateRecordAddress;
652
+ const tmpRecord = (typeof tmpRecordAddress === 'string') ? this.pict.DataProvider.getDataByAddress(tmpRecordAddress) : undefined;
653
+ const tmpContent = this.pict.parseTemplateByHash(tmpTemplateHash, tmpRecord, null, [ pView ]);
654
+ if (typeof tmpContent !== 'string' || !tmpContent.length)
655
+ {
656
+ return false;
657
+ }
658
+
659
+ tmpElement.outerHTML = tmpContent;
660
+ pView.onAfterRender({ RenderableHash: `GroupInPlace-${tmpGroup.Hash}` });
661
+ return true;
662
+ }
663
+ catch (pError)
664
+ {
665
+ this.log.warn(`renderGroupInPlace failed for group [${pGroupHash}]; falling back to a full section render: ${pError.message || pError}`);
666
+ return false;
667
+ }
668
+ }
669
+
454
670
  /**
455
671
  * Causes a tabular section to refresh its display
456
672
  *
@@ -501,7 +717,15 @@ class PictDynamicFormsSolverBehaviors extends libPictProvider
501
717
  // We expect this view to be in the set.
502
718
  for (let i = 0; i < tmpViewsToRender.length; i++)
503
719
  {
504
- tmpViewsToRender[i].render();
720
+ // Re-render ONLY the group that actually changed when we can. A full
721
+ // section render replaces every group's DOM, which destroys any widget
722
+ // the user is mid-interaction with (select2 pickers blank for ~700ms) and
723
+ // drops layout state. Falls back to the full render when the group-scoped
724
+ // path is not possible, so behaviour is unchanged for anything it cannot handle.
725
+ if (!this.renderGroupInPlace(tmpViewsToRender[i], pGroupHash))
726
+ {
727
+ tmpViewsToRender[i].render();
728
+ }
505
729
  }
506
730
 
507
731
  //NOTE: not running a solve, since this is run from the solver; if you need a solve, call runSolvers()
@@ -601,6 +825,8 @@ class PictDynamicFormsSolverBehaviors extends libPictProvider
601
825
  return true;
602
826
  }
603
827
 
828
+ this.recordDecoration(pSectionHash, 'sectionbackground', 'colorSectionBackground', [ pSectionHash, pColor, pApplyChange ]);
829
+
604
830
  let tmpSectionView = this.pict.views.PictFormMetacontroller.getSectionViewFromHash(pSectionHash)
605
831
  if (!tmpSectionView)
606
832
  {
@@ -630,6 +856,8 @@ class PictDynamicFormsSolverBehaviors extends libPictProvider
630
856
  return true;
631
857
  }
632
858
 
859
+ this.recordDecoration(pSectionHash, `${pGroupHash}::groupbackground`, 'colorGroupBackground', [ pSectionHash, pGroupHash, pColor, pApplyChange ]);
860
+
633
861
  let tmpGroupView = this.pict.views.PictFormMetacontroller.getSectionViewFromHash(pSectionHash)
634
862
  if (!tmpGroupView)
635
863
  {
@@ -667,6 +895,8 @@ class PictDynamicFormsSolverBehaviors extends libPictProvider
667
895
  return true;
668
896
  }
669
897
 
898
+ this.recordDecoration(pSectionHash, `input::${pInputHash}`, 'colorInputBackground', [ pSectionHash, pInputHash, pColor, pApplyChange, pCSSSelector ]);
899
+
670
900
  /** @type {import('../views/Pict-View-DynamicForm.js')} */
671
901
  let tmpInputView = this.pict.views.PictFormMetacontroller.getSectionViewFromHash(pSectionHash);
672
902
 
@@ -719,6 +949,9 @@ class PictDynamicFormsSolverBehaviors extends libPictProvider
719
949
  return true;
720
950
  }
721
951
 
952
+ this.recordDecoration(pSectionHash, `${pGroupHash}::inputcell::${pInputHash}::${pRowIndex}`, 'colorInputBackgroundTabular',
953
+ [ pSectionHash, pGroupHash, pInputHash, pRowIndex, pColor, pApplyChange, pCSSSelector, pElementIDPrefix ]);
954
+
722
955
  /** @type {import('../views/Pict-View-DynamicForm.js')} */
723
956
  let tmpInputView = this.pict.views.PictFormMetacontroller.getSectionViewFromHash(pSectionHash);
724
957
 
@@ -862,6 +1095,8 @@ class PictDynamicFormsSolverBehaviors extends libPictProvider
862
1095
  return false;
863
1096
  }
864
1097
  let tmpClass = (typeof pHighlightClass === 'string' && pHighlightClass.length > 0) ? pHighlightClass : this.cssTabularRowHighlightClass;
1098
+ this.recordDecoration(pSectionHash, `${pGroupHash}::row::${pRowIndex}::${tmpClass}`, 'highlightTabularRow',
1099
+ [ pSectionHash, pGroupHash, pRowIndex, pApplyFlag, pHighlightClass ]);
865
1100
  let tmpRowSelector = `${tmpGroupSelector} tr[data-tabular-row-index="${pRowIndex}"]`;
866
1101
  if (this.isSolverFlagEnabled(pApplyFlag))
867
1102
  {
@@ -894,6 +1129,8 @@ class PictDynamicFormsSolverBehaviors extends libPictProvider
894
1129
  return false;
895
1130
  }
896
1131
  let tmpClass = (typeof pHighlightClass === 'string' && pHighlightClass.length > 0) ? pHighlightClass : this.cssTabularColumnHighlightClass;
1132
+ this.recordDecoration(pSectionHash, `${pGroupHash}::column::${pColumnIndex}::${tmpClass}`, 'highlightTabularColumn',
1133
+ [ pSectionHash, pGroupHash, pColumnIndex, pApplyFlag, pHighlightClass ]);
897
1134
  let tmpColumnSelector = `${tmpGroupSelector} [data-tabular-column-index="${pColumnIndex}"]`;
898
1135
  if (this.isSolverFlagEnabled(pApplyFlag))
899
1136
  {
@@ -928,6 +1165,8 @@ class PictDynamicFormsSolverBehaviors extends libPictProvider
928
1165
  return false;
929
1166
  }
930
1167
  let tmpApply = this.isSolverFlagEnabled(pApplyFlag) && (typeof pColor === 'string') && (pColor.length > 0);
1168
+ this.recordDecoration(pSectionHash, `${pGroupHash}::rowcolor::${pRowIndex}`, 'colorTabularRow',
1169
+ [ pSectionHash, pGroupHash, pRowIndex, pColor, pApplyFlag ]);
931
1170
  let tmpElementSet = this.pict.ContentAssignment.getElement(`${tmpGroupSelector} tr[data-tabular-row-index="${pRowIndex}"] td`);
932
1171
  for (let i = 0; i < tmpElementSet.length; i++)
933
1172
  {
@@ -962,6 +1201,8 @@ class PictDynamicFormsSolverBehaviors extends libPictProvider
962
1201
  return false;
963
1202
  }
964
1203
  let tmpApply = this.isSolverFlagEnabled(pApplyFlag) && (typeof pColor === 'string') && (pColor.length > 0);
1204
+ this.recordDecoration(pSectionHash, `${pGroupHash}::columncolor::${pColumnIndex}`, 'colorTabularColumn',
1205
+ [ pSectionHash, pGroupHash, pColumnIndex, pColor, pApplyFlag ]);
965
1206
  let tmpElementSet = this.pict.ContentAssignment.getElement(`${tmpGroupSelector} [data-tabular-column-index="${pColumnIndex}"]`);
966
1207
  for (let i = 0; i < tmpElementSet.length; i++)
967
1208
  {
@@ -56,28 +56,43 @@ module.exports = /*css*/`
56
56
  height: auto;
57
57
  }
58
58
 
59
+ /* Open-editor sizing.
60
+ *
61
+ * The height is a variable so the provider can drive it from the descriptor's Diagram.Height (and
62
+ * from a height the user dragged to) without inlining a whole style block. The default clears
63
+ * Excalidraw's own 500px "this is a phone" breakpoint AND leaves the shape-properties island room to
64
+ * render unscrolled — below that the island is clipped to a scrolling sliver and the property
65
+ * buttons become miserable to hit.
66
+ *
67
+ * The resize:vertical rule is the drag grip, the same affordance a textarea has; it needs a
68
+ * non-visible overflow to show up at all. The floor is deliberately a small absolute value rather than the
69
+ * configured height, or the grip could not drag below whatever the field was configured to. */
59
70
  .pict-section-form-diagram-edit
60
71
  {
61
72
  padding: 0;
62
- min-height: 420px;
73
+ height: var(--pict-diagram-height, 560px);
74
+ min-height: 180px;
63
75
  display: flex;
76
+ resize: vertical;
77
+ overflow: hidden;
64
78
  }
65
79
 
66
- /* The Excalidraw view brings its own chrome inside the slot. Force the wrap
67
- * and the Excalidraw root to fill so the canvas doesn't collapse to 0
68
- * height inside the form slot. */
80
+ /* The Excalidraw view brings its own chrome inside the slot. Force the wrap and the Excalidraw root
81
+ * to FILL rather than to floor: a min-height in here would fight the grip on the way down and pin
82
+ * the canvas taller than the box the user just dragged. */
69
83
  .pict-section-form-diagram-edit > .pict-excalidraw-wrap,
70
84
  .pict-section-form-diagram-edit > .pict-excalidraw-wrap > .pict-excalidraw-mount
71
85
  {
72
86
  flex: 1 1 auto;
73
- min-height: 420px;
87
+ min-height: 0;
88
+ height: 100%;
74
89
  }
75
90
 
76
91
  .pict-section-form-diagram-edit .excalidraw
77
92
  {
78
93
  width: 100%;
79
94
  height: 100%;
80
- min-height: 420px;
95
+ min-height: 0;
81
96
  }
82
97
 
83
98
  .pict-section-form-diagram-toggle
@@ -21,7 +21,8 @@
21
21
  * "InputType": "Diagram",
22
22
  * "Diagram": {
23
23
  * "ThemeColors": true,
24
- * "Height": "500px",
24
+ * "Height": "640px",
25
+ * "FormFactor": "pointer",
25
26
  * "EditorImplementation": "react",
26
27
  * "EditorOptions": { ... }
27
28
  * }
@@ -197,6 +198,17 @@ class PictInputDiagram extends libPictSectionInputExtension
197
198
  }
198
199
 
199
200
  /**
201
+ * Flag edit/view mode on the DISPLAY SLOT so the scoped CSS (sizing, the resize grip, the toggle
202
+ * chip pseudo) has something to key off.
203
+ *
204
+ * The slot is resolved FIRST and the RawHTMLID element is only a fallback. That order is
205
+ * load-bearing: a host template is free to put `id="{RawHTMLID}"` on the hidden <input> (it has
206
+ * to, if it wants the provider's value write-back to find it), and when it does,
207
+ * `getElementById(RawHTMLID)` returns that hidden input — so every mode class, and with it every
208
+ * sizing rule keyed off `.pict-section-form-diagram-edit`, lands on an invisible element and the
209
+ * editor silently falls back to the embed's own min-height. Our own default template omits that
210
+ * id, so this reordering is a no-op there.
211
+ *
200
212
  * @param {Object} pInput - The input definition object.
201
213
  * @param {string} pMode - The mode to set ('edit' or 'view').
202
214
  */
@@ -204,8 +216,8 @@ class PictInputDiagram extends libPictSectionInputExtension
204
216
  {
205
217
  if (typeof document === 'undefined') return;
206
218
  let tmpRawHTMLID = pInput.Macro.RawHTMLID;
207
- let tmpOuter = document.getElementById(tmpRawHTMLID) ||
208
- document.querySelector(this.getContentDisplayHTMLID(tmpRawHTMLID));
219
+ let tmpOuter = document.querySelector(this.getContentDisplayHTMLID(tmpRawHTMLID)) ||
220
+ document.getElementById(tmpRawHTMLID);
209
221
  if (!tmpOuter || !tmpOuter.classList) return;
210
222
  tmpOuter.classList.remove('mode-edit', 'mode-view', 'pict-section-form-diagram-edit');
211
223
  if (pMode === 'edit')
@@ -218,6 +230,204 @@ class PictInputDiagram extends libPictSectionInputExtension
218
230
  }
219
231
  }
220
232
 
233
+ // ----------------------------------------------------------------------------
234
+ // Editor height
235
+ // ----------------------------------------------------------------------------
236
+
237
+ /**
238
+ * @param {Object} pInput - The input definition object.
239
+ * @returns {Element} The display slot element for this input, or null when it isn't in the DOM.
240
+ */
241
+ _getSlotElement(pInput)
242
+ {
243
+ if ((typeof document === 'undefined') || !pInput || !pInput.Macro) return null;
244
+ return document.querySelector(this.getContentDisplayHTMLID(pInput.Macro.RawHTMLID));
245
+ }
246
+
247
+ /**
248
+ * Coerce a configured height into a CSS length. Bare numbers (and numeric strings) are treated as
249
+ * pixels so a descriptor can say 640 or "640" as readily as "640px".
250
+ *
251
+ * @param {any} pValue - The configured height.
252
+ * @returns {string} A CSS length, or '' when the value isn't usable.
253
+ */
254
+ _normalizeHeight(pValue)
255
+ {
256
+ if (typeof pValue === 'number')
257
+ {
258
+ return (isFinite(pValue) && pValue > 0) ? `${pValue}px` : '';
259
+ }
260
+ if (typeof pValue !== 'string') return '';
261
+ let tmpValue = pValue.trim();
262
+ if (tmpValue.length < 1) return '';
263
+ if (/^[0-9]+(\.[0-9]+)?$/.test(tmpValue)) return `${tmpValue}px`;
264
+ // Anything else is passed through as authored (px/rem/vh/calc()/…) — the browser ignores a
265
+ // value it can't parse, which degrades to the stylesheet default rather than breaking layout.
266
+ return tmpValue;
267
+ }
268
+
269
+ /**
270
+ * @param {Object} pInput - The input definition object.
271
+ * @returns {string} The localStorage key this input's user-dragged height is remembered under.
272
+ */
273
+ _heightStorageKey(pInput)
274
+ {
275
+ return `pict-input-diagram:height:${(pInput && pInput.Hash) || ''}`;
276
+ }
277
+
278
+ /**
279
+ * @param {Object} pInput - The input definition object.
280
+ * @returns {string} The remembered height for this input, or '' if there isn't one.
281
+ */
282
+ _readStoredHeight(pInput)
283
+ {
284
+ try
285
+ {
286
+ if ((typeof window === 'undefined') || !window.localStorage) return '';
287
+ return this._normalizeHeight(window.localStorage.getItem(this._heightStorageKey(pInput)));
288
+ }
289
+ catch (pErr)
290
+ {
291
+ // Storage can throw outright (Safari private mode, blocked site data) — a forgotten height
292
+ // is not worth a broken editor.
293
+ return '';
294
+ }
295
+ }
296
+
297
+ /**
298
+ * @param {Object} pInput - The input definition object.
299
+ * @param {string} pHeight - The height to remember.
300
+ * @returns {boolean} True if it was written.
301
+ */
302
+ _writeStoredHeight(pInput, pHeight)
303
+ {
304
+ try
305
+ {
306
+ if ((typeof window === 'undefined') || !window.localStorage) return false;
307
+ window.localStorage.setItem(this._heightStorageKey(pInput), pHeight);
308
+ return true;
309
+ }
310
+ catch (pErr)
311
+ {
312
+ return false;
313
+ }
314
+ }
315
+
316
+ /**
317
+ * Resolve the editor height for an input: a height the user dragged to wins over the descriptor's
318
+ * configured Height, which wins over the stylesheet default (signalled by '').
319
+ *
320
+ * @param {Object} pInput - The input definition object.
321
+ * @returns {string} A CSS length, or '' to leave the stylesheet in charge.
322
+ */
323
+ _resolveEditorHeight(pInput)
324
+ {
325
+ let tmpStored = this._readStoredHeight(pInput);
326
+ if (tmpStored) return tmpStored;
327
+ let tmpDiagramOpts = (pInput.PictForm && pInput.PictForm.Diagram) || {};
328
+ return this._normalizeHeight(tmpDiagramOpts.Height);
329
+ }
330
+
331
+ /**
332
+ * Push the resolved height onto the slot as `--pict-diagram-height`, which the scoped CSS reads.
333
+ * Any inline height left behind by an earlier drag is dropped first so the variable is what
334
+ * actually applies on a fresh mount.
335
+ *
336
+ * @param {Object} pInput - The input definition object.
337
+ */
338
+ _applyEditorHeight(pInput)
339
+ {
340
+ let tmpSlot = this._getSlotElement(pInput);
341
+ if (!tmpSlot || !tmpSlot.style) return;
342
+ tmpSlot.style.removeProperty('height');
343
+ let tmpHeight = this._resolveEditorHeight(pInput);
344
+ if (tmpHeight)
345
+ {
346
+ tmpSlot.style.setProperty('--pict-diagram-height', tmpHeight);
347
+ }
348
+ else
349
+ {
350
+ tmpSlot.style.removeProperty('--pict-diagram-height');
351
+ }
352
+ }
353
+
354
+ /**
355
+ * Strip the edit-mode sizing when dropping back to view. The resize grip writes an INLINE height
356
+ * onto the slot, and that would otherwise pin the static SVG view to whatever the canvas was
357
+ * dragged to.
358
+ *
359
+ * @param {Object} pInput - The input definition object.
360
+ */
361
+ _clearEditorHeight(pInput)
362
+ {
363
+ let tmpSlot = this._getSlotElement(pInput);
364
+ if (!tmpSlot || !tmpSlot.style) return;
365
+ tmpSlot.style.removeProperty('height');
366
+ tmpSlot.style.removeProperty('width');
367
+ tmpSlot.style.removeProperty('--pict-diagram-height');
368
+ }
369
+
370
+ /**
371
+ * Remember whatever height the slot is currently sitting at. Only an INLINE height counts — that is
372
+ * what the native resize grip writes; a height coming from the stylesheet or the descriptor is not
373
+ * a user decision and must not be frozen into storage.
374
+ *
375
+ * @param {Object} pInput - The input definition object.
376
+ * @returns {boolean} True if a height was remembered.
377
+ */
378
+ _captureEditorHeight(pInput)
379
+ {
380
+ let tmpSlot = this._getSlotElement(pInput);
381
+ if (!tmpSlot || !tmpSlot.style || !tmpSlot.style.height) return false;
382
+ return this._writeStoredHeight(pInput, tmpSlot.style.height);
383
+ }
384
+
385
+ /**
386
+ * Watch the slot so a height the user drags to is remembered for next time. The grip is native CSS
387
+ * `resize` (no drag handling of our own), so a ResizeObserver is the only signal that it moved.
388
+ * Debounced — a drag fires continuously.
389
+ *
390
+ * @param {Object} pInput - The input definition object.
391
+ * @param {Object} pInstance - The instance record to hang the observer off.
392
+ */
393
+ _observeEditorResize(pInput, pInstance)
394
+ {
395
+ if (typeof ResizeObserver === 'undefined') return;
396
+ let tmpSlot = this._getSlotElement(pInput);
397
+ if (!tmpSlot || pInstance.resizeObserver) return;
398
+ let tmpProvider = this;
399
+ pInstance.resizeObserver = new ResizeObserver(() =>
400
+ {
401
+ if (pInstance.resizeTimer) clearTimeout(pInstance.resizeTimer);
402
+ pInstance.resizeTimer = setTimeout(() =>
403
+ {
404
+ pInstance.resizeTimer = null;
405
+ tmpProvider._captureEditorHeight(pInput);
406
+ }, 300);
407
+ });
408
+ try { pInstance.resizeObserver.observe(tmpSlot); }
409
+ catch (pErr) { pInstance.resizeObserver = null; }
410
+ }
411
+
412
+ /**
413
+ * @param {Object} pInstance - The instance record whose resize watcher should be torn down.
414
+ */
415
+ _unobserveEditorResize(pInstance)
416
+ {
417
+ if (!pInstance) return;
418
+ if (pInstance.resizeTimer)
419
+ {
420
+ clearTimeout(pInstance.resizeTimer);
421
+ pInstance.resizeTimer = null;
422
+ }
423
+ if (pInstance.resizeObserver)
424
+ {
425
+ try { pInstance.resizeObserver.disconnect(); }
426
+ catch (pErr) { /* already gone */ }
427
+ pInstance.resizeObserver = null;
428
+ }
429
+ }
430
+
221
431
  // ----------------------------------------------------------------------------
222
432
  // View mode
223
433
  // ----------------------------------------------------------------------------
@@ -230,6 +440,7 @@ class PictInputDiagram extends libPictSectionInputExtension
230
440
 
231
441
  this._assignSlotContent(tmpSlotID, this._buildViewHTML(tmpValue));
232
442
  this._setSlotModeClass(pInput, 'view');
443
+ this._clearEditorHeight(pInput);
233
444
 
234
445
  let tmpInst = this._instances[pInput.Hash] || {};
235
446
  tmpInst.mode = 'view';
@@ -299,7 +510,12 @@ class PictInputDiagram extends libPictSectionInputExtension
299
510
  ViewIdentifier: `Pict-Input-Diagram-Editor-${pInput.Hash}`,
300
511
  TargetElementAddress: this.getContentDisplayHTMLID(tmpRawHTMLID),
301
512
  DrawingDataAddress: tmpDrawingAddr,
302
- EditorImplementation: tmpDiagramOpts.EditorImplementation || 'react'
513
+ EditorImplementation: tmpDiagramOpts.EditorImplementation || 'react',
514
+ // Excalidraw picks its UI density from the CONTAINER's box, so an embedded canvas — which is
515
+ // short by definition — reads as a phone and buries the shape properties behind a popover.
516
+ // 'pointer' asks the embed to classify by input device instead: desktop chrome for a mouse,
517
+ // Excalidraw's own detection on a touch screen. See pict-section-excalidraw's FormFactor.
518
+ FormFactor: tmpDiagramOpts.FormFactor || 'pointer'
303
519
  });
304
520
 
305
521
  return tmpOptions;
@@ -391,6 +607,8 @@ class PictInputDiagram extends libPictSectionInputExtension
391
607
  }
392
608
 
393
609
  this._setSlotModeClass(pInput, 'edit');
610
+ this._applyEditorHeight(pInput);
611
+ this._observeEditorResize(pInput, tmpInst);
394
612
 
395
613
  tmpInst.mode = 'edit';
396
614
  tmpInst.slotID = tmpSlotID;
@@ -426,7 +644,14 @@ class PictInputDiagram extends libPictSectionInputExtension
426
644
  _destroyEdit(pInput)
427
645
  {
428
646
  let tmpInst = this._instances[pInput.Hash];
429
- if (!tmpInst || !tmpInst.viewInstance) return;
647
+ if (!tmpInst) return;
648
+ // Capture BEFORE teardown: ResizeObserver is frame-driven and never fires in a backgrounded or
649
+ // headless context, so closing the editor is the one commit point we can rely on.
650
+ this._captureEditorHeight(pInput);
651
+ // Ahead of the viewInstance guard — a slot can be watched without a live editor view (a mount
652
+ // that failed part way), and a leaked ResizeObserver would keep the detached slot alive.
653
+ this._unobserveEditorResize(tmpInst);
654
+ if (!tmpInst.viewInstance) return;
430
655
 
431
656
  let tmpView = tmpInst.viewInstance;
432
657
  try