pict-section-form 1.3.6 → 1.3.7
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.
|
@@ -45,7 +45,8 @@ pict.addProvider(
|
|
|
45
45
|
"InputType": "Diagram",
|
|
46
46
|
"Diagram": {
|
|
47
47
|
"ThemeColors": true,
|
|
48
|
-
"Height": "
|
|
48
|
+
"Height": "640px",
|
|
49
|
+
"FormFactor": "pointer",
|
|
49
50
|
"EditorImplementation": "react"
|
|
50
51
|
}
|
|
51
52
|
}
|
|
@@ -72,7 +73,37 @@ so the SVG re-opens cleanly in any Excalidraw-aware viewer.
|
|
|
72
73
|
|
|
73
74
|
### Height
|
|
74
75
|
|
|
75
|
-
|
|
76
|
+
Starting height of the canvas while the field is in **edit mode**. A CSS length
|
|
77
|
+
(`"640px"`, `"40rem"`) or a bare number, which is read as pixels (`640` and
|
|
78
|
+
`"640"` both mean `640px`). Defaults to `560px`.
|
|
79
|
+
|
|
80
|
+
Height is worth setting deliberately, because Excalidraw scales its own UI to
|
|
81
|
+
the box it is given: below roughly 500px it decides it is on a phone and folds
|
|
82
|
+
the shape properties away behind a popover, and the left-hand properties island
|
|
83
|
+
starts to clip into a scrolling sliver. `560px` is the smallest height that
|
|
84
|
+
avoids both.
|
|
85
|
+
|
|
86
|
+
Users can also drag the bottom-right grip to resize the canvas (the same
|
|
87
|
+
affordance a `textarea` has). A height they drag to is remembered per field in
|
|
88
|
+
`localStorage` and wins over `Height` on the next open; the field falls back to
|
|
89
|
+
`Height` wherever storage is unavailable. Read and Print themes are unaffected —
|
|
90
|
+
they render the static SVG at its natural size.
|
|
91
|
+
|
|
92
|
+
### FormFactor
|
|
93
|
+
|
|
94
|
+
How Excalidraw should classify the editor when picking how dense its UI is.
|
|
95
|
+
|
|
96
|
+
| Value | Behaviour |
|
|
97
|
+
|---|---|
|
|
98
|
+
| `"pointer"` *(default)* | Desktop chrome on a mouse; Excalidraw's own answer on a touch screen. |
|
|
99
|
+
| `"auto"` | Excalidraw decides, from the size of the container. |
|
|
100
|
+
| `"desktop"` / `"tablet"` / `"phone"` | Pin it. |
|
|
101
|
+
|
|
102
|
+
Excalidraw's own detection reads the **container's** box — right for
|
|
103
|
+
excalidraw.com, where the container is the viewport, and wrong for a form field,
|
|
104
|
+
where a 560px-tall box on a 27" monitor is not a phone. `"pointer"` classifies
|
|
105
|
+
by input device instead, so the full properties island stays put at any field
|
|
106
|
+
width. Set `"auto"` to opt back out.
|
|
76
107
|
|
|
77
108
|
### EditorImplementation
|
|
78
109
|
|
package/package.json
CHANGED
|
@@ -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
|
-
|
|
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
|
-
*
|
|
68
|
-
*
|
|
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:
|
|
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:
|
|
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": "
|
|
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.
|
|
208
|
-
document.
|
|
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
|
|
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
|
|
@@ -45,6 +45,34 @@ function buildPictWithStubs()
|
|
|
45
45
|
return new libPict();
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Swap window.localStorage for an in-memory shim. jsdom runs on an opaque origin where merely
|
|
50
|
+
* READING window.localStorage throws, so a real round-trip can't be exercised without this.
|
|
51
|
+
*
|
|
52
|
+
* @param {Object} pStore - Backing object for the shim.
|
|
53
|
+
* @return {Function} Restores the original descriptor.
|
|
54
|
+
*/
|
|
55
|
+
function withStubbedStorage(pStore)
|
|
56
|
+
{
|
|
57
|
+
let tmpOriginal = Object.getOwnPropertyDescriptor(window, 'localStorage');
|
|
58
|
+
Object.defineProperty(window, 'localStorage',
|
|
59
|
+
{
|
|
60
|
+
configurable: true,
|
|
61
|
+
writable: true,
|
|
62
|
+
value:
|
|
63
|
+
{
|
|
64
|
+
getItem: (pKey) => ((pKey in pStore) ? pStore[pKey] : null),
|
|
65
|
+
setItem: (pKey, pValue) => { pStore[pKey] = String(pValue); },
|
|
66
|
+
removeItem: (pKey) => { delete pStore[pKey]; }
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
return () =>
|
|
70
|
+
{
|
|
71
|
+
if (tmpOriginal) Object.defineProperty(window, 'localStorage', tmpOriginal);
|
|
72
|
+
else delete window.localStorage;
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
48
76
|
suite('Pict-Provider-Input-Diagram', () =>
|
|
49
77
|
{
|
|
50
78
|
test('module loads — class + default_configuration exposed', () =>
|
|
@@ -172,6 +200,158 @@ suite('Pict-Provider-Input-Diagram', () =>
|
|
|
172
200
|
});
|
|
173
201
|
});
|
|
174
202
|
|
|
203
|
+
// --- slot targeting -------------------------------------------------------------------------
|
|
204
|
+
// A host template that gives the hidden <input> id="{RawHTMLID}" (it has to, if it wants the
|
|
205
|
+
// provider's value write-back to find it) used to steal every mode class off the display slot,
|
|
206
|
+
// which silently killed the open editor's sizing. The slot must win.
|
|
207
|
+
|
|
208
|
+
test('_setSlotModeClass flags the DISPLAY SLOT, not a same-id hidden input', () =>
|
|
209
|
+
{
|
|
210
|
+
let tmpPict = buildPictWithStubs();
|
|
211
|
+
let tmpProvider = new libDiagramInput(tmpPict, {}, 'Pict-Input-Diagram');
|
|
212
|
+
|
|
213
|
+
document.body.innerHTML =
|
|
214
|
+
'<input type="hidden" id="ArchDiagram-input">' +
|
|
215
|
+
'<div id="DISPLAY-FOR-ArchDiagram-input" class="pict-section-form-diagram"></div>';
|
|
216
|
+
|
|
217
|
+
tmpProvider._setSlotModeClass(_StubInput, 'edit');
|
|
218
|
+
|
|
219
|
+
let tmpSlot = document.getElementById('DISPLAY-FOR-ArchDiagram-input');
|
|
220
|
+
let tmpHidden = document.getElementById('ArchDiagram-input');
|
|
221
|
+
Expect(tmpSlot.classList.contains('pict-section-form-diagram-edit')).to.equal(true);
|
|
222
|
+
Expect(tmpSlot.classList.contains('mode-edit')).to.equal(true);
|
|
223
|
+
Expect(tmpHidden.classList.contains('pict-section-form-diagram-edit')).to.equal(false);
|
|
224
|
+
|
|
225
|
+
tmpProvider._setSlotModeClass(_StubInput, 'view');
|
|
226
|
+
Expect(tmpSlot.classList.contains('mode-view')).to.equal(true);
|
|
227
|
+
Expect(tmpSlot.classList.contains('pict-section-form-diagram-edit')).to.equal(false);
|
|
228
|
+
document.body.innerHTML = '';
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
// --- editor height --------------------------------------------------------------------------
|
|
232
|
+
|
|
233
|
+
test('_normalizeHeight coerces numbers and numeric strings to px, passes CSS lengths through', () =>
|
|
234
|
+
{
|
|
235
|
+
let tmpProvider = new libDiagramInput(buildPictWithStubs(), {}, 'Pict-Input-Diagram');
|
|
236
|
+
Expect(tmpProvider._normalizeHeight(640)).to.equal('640px');
|
|
237
|
+
Expect(tmpProvider._normalizeHeight('640')).to.equal('640px');
|
|
238
|
+
Expect(tmpProvider._normalizeHeight('640px')).to.equal('640px');
|
|
239
|
+
Expect(tmpProvider._normalizeHeight(' 40rem ')).to.equal('40rem');
|
|
240
|
+
Expect(tmpProvider._normalizeHeight('')).to.equal('');
|
|
241
|
+
Expect(tmpProvider._normalizeHeight(null)).to.equal('');
|
|
242
|
+
Expect(tmpProvider._normalizeHeight(0)).to.equal('');
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
test('storage access that throws degrades to the descriptor Height', () =>
|
|
246
|
+
{
|
|
247
|
+
// jsdom serves an opaque origin, so even READING window.localStorage throws a SecurityError —
|
|
248
|
+
// the same shape as Safari private mode. Nothing here may propagate that.
|
|
249
|
+
let tmpProvider = new libDiagramInput(buildPictWithStubs(), {}, 'Pict-Input-Diagram');
|
|
250
|
+
let tmpInput = JSON.parse(JSON.stringify(_StubInput));
|
|
251
|
+
tmpInput.PictForm.Diagram.Height = '480px';
|
|
252
|
+
|
|
253
|
+
Expect(tmpProvider._readStoredHeight(tmpInput)).to.equal('');
|
|
254
|
+
Expect(tmpProvider._writeStoredHeight(tmpInput, '720px')).to.equal(false);
|
|
255
|
+
Expect(tmpProvider._resolveEditorHeight(tmpInput)).to.equal('480px');
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
test('_resolveEditorHeight prefers a stored height over the descriptor Height', () =>
|
|
259
|
+
{
|
|
260
|
+
let tmpProvider = new libDiagramInput(buildPictWithStubs(), {}, 'Pict-Input-Diagram');
|
|
261
|
+
let tmpInput = JSON.parse(JSON.stringify(_StubInput));
|
|
262
|
+
tmpInput.PictForm.Diagram.Height = '480px';
|
|
263
|
+
|
|
264
|
+
let tmpStore = {};
|
|
265
|
+
let tmpRestore = withStubbedStorage(tmpStore);
|
|
266
|
+
try
|
|
267
|
+
{
|
|
268
|
+
Expect(tmpProvider._resolveEditorHeight(tmpInput)).to.equal('480px');
|
|
269
|
+
|
|
270
|
+
tmpProvider._writeStoredHeight(tmpInput, '720px');
|
|
271
|
+
Expect(tmpProvider._resolveEditorHeight(tmpInput)).to.equal('720px');
|
|
272
|
+
|
|
273
|
+
// and with neither, the stylesheet stays in charge
|
|
274
|
+
delete tmpInput.PictForm.Diagram.Height;
|
|
275
|
+
window.localStorage.removeItem(tmpProvider._heightStorageKey(tmpInput));
|
|
276
|
+
Expect(tmpProvider._resolveEditorHeight(tmpInput)).to.equal('');
|
|
277
|
+
}
|
|
278
|
+
finally { tmpRestore(); }
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
test('_applyEditorHeight sets the CSS variable and _clearEditorHeight strips edit sizing', () =>
|
|
282
|
+
{
|
|
283
|
+
let tmpProvider = new libDiagramInput(buildPictWithStubs(), {}, 'Pict-Input-Diagram');
|
|
284
|
+
let tmpInput = JSON.parse(JSON.stringify(_StubInput));
|
|
285
|
+
tmpInput.PictForm.Diagram.Height = '600px';
|
|
286
|
+
|
|
287
|
+
document.body.innerHTML = '<div id="DISPLAY-FOR-ArchDiagram-input"></div>';
|
|
288
|
+
let tmpSlot = document.getElementById('DISPLAY-FOR-ArchDiagram-input');
|
|
289
|
+
|
|
290
|
+
// jsdom's CSSStyleDeclaration silently DROPS custom properties, so read them off a spy rather
|
|
291
|
+
// than off the element — the assertion is about what the provider asks for.
|
|
292
|
+
let tmpSet = [];
|
|
293
|
+
let tmpRemoved = [];
|
|
294
|
+
tmpSlot.style.setProperty = (pName, pValue) => tmpSet.push([pName, pValue]);
|
|
295
|
+
tmpSlot.style.removeProperty = (pName) => tmpRemoved.push(pName);
|
|
296
|
+
|
|
297
|
+
tmpProvider._applyEditorHeight(tmpInput);
|
|
298
|
+
Expect(tmpSet).to.deep.equal([['--pict-diagram-height', '600px']]);
|
|
299
|
+
// any inline height left by an earlier drag has to go, or the variable never applies
|
|
300
|
+
Expect(tmpRemoved).to.deep.equal(['height']);
|
|
301
|
+
|
|
302
|
+
// dropping to view must not leave the static view pinned to the dragged size
|
|
303
|
+
tmpRemoved.length = 0;
|
|
304
|
+
tmpProvider._clearEditorHeight(tmpInput);
|
|
305
|
+
Expect(tmpRemoved).to.deep.equal(['height', 'width', '--pict-diagram-height']);
|
|
306
|
+
document.body.innerHTML = '';
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
test('_captureEditorHeight remembers a dragged height, and ONLY a dragged one', () =>
|
|
310
|
+
{
|
|
311
|
+
let tmpProvider = new libDiagramInput(buildPictWithStubs(), {}, 'Pict-Input-Diagram');
|
|
312
|
+
let tmpInput = JSON.parse(JSON.stringify(_StubInput));
|
|
313
|
+
tmpInput.PictForm.Diagram.Height = '480px';
|
|
314
|
+
|
|
315
|
+
document.body.innerHTML = '<div id="DISPLAY-FOR-ArchDiagram-input"></div>';
|
|
316
|
+
let tmpSlot = document.getElementById('DISPLAY-FOR-ArchDiagram-input');
|
|
317
|
+
|
|
318
|
+
let tmpStore = {};
|
|
319
|
+
let tmpRestore = withStubbedStorage(tmpStore);
|
|
320
|
+
try
|
|
321
|
+
{
|
|
322
|
+
// No inline height — the descriptor's value is not the user's decision and must not stick.
|
|
323
|
+
Expect(tmpProvider._captureEditorHeight(tmpInput)).to.equal(false);
|
|
324
|
+
Expect(tmpProvider._resolveEditorHeight(tmpInput)).to.equal('480px');
|
|
325
|
+
|
|
326
|
+
// The grip writes an inline height; that IS a decision.
|
|
327
|
+
tmpSlot.style.height = '820px';
|
|
328
|
+
Expect(tmpProvider._captureEditorHeight(tmpInput)).to.equal(true);
|
|
329
|
+
Expect(tmpProvider._resolveEditorHeight(tmpInput)).to.equal('820px');
|
|
330
|
+
}
|
|
331
|
+
finally { tmpRestore(); document.body.innerHTML = ''; }
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
test('_buildEditorOptions defaults FormFactor to pointer and honours a descriptor override', () =>
|
|
335
|
+
{
|
|
336
|
+
let tmpPict = buildPictWithStubs();
|
|
337
|
+
let tmpProvider = new libDiagramInput(tmpPict, {}, 'Pict-Input-Diagram');
|
|
338
|
+
let tmpInput = JSON.parse(JSON.stringify(_StubInput));
|
|
339
|
+
|
|
340
|
+
Expect(tmpProvider._buildEditorOptions(tmpInput, '', {}).FormFactor).to.equal('pointer');
|
|
341
|
+
|
|
342
|
+
tmpInput.PictForm.Diagram.FormFactor = 'auto';
|
|
343
|
+
Expect(tmpProvider._buildEditorOptions(tmpInput, '', {}).FormFactor).to.equal('auto');
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
test('the open-editor CSS drives height from a variable and ships the resize grip', () =>
|
|
347
|
+
{
|
|
348
|
+
let tmpCSS = require('../source/providers/inputs/Pict-Provider-Input-Diagram-CSS.js');
|
|
349
|
+
Expect(tmpCSS).to.contain('--pict-diagram-height');
|
|
350
|
+
Expect(tmpCSS).to.contain('resize: vertical');
|
|
351
|
+
// a min-height on the inner chain would fight the grip on the way down
|
|
352
|
+
Expect(/\.pict-section-form-diagram-edit[^{]*\{[^}]*min-height:\s*420px/.test(tmpCSS)).to.equal(false);
|
|
353
|
+
});
|
|
354
|
+
|
|
175
355
|
test('themeifySVG re-export is callable from the main module entry', () =>
|
|
176
356
|
{
|
|
177
357
|
Expect(typeof libFormMain.themeifySVG).to.equal('function');
|