pict-section-form 1.3.5 → 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.
- package/CONTRIBUTING.md +1 -1
- package/README.md +2 -2
- package/docs/input_providers/015-diagram.md +33 -2
- package/package.json +1 -1
- package/source/providers/inputs/Pict-Provider-Input-Diagram-CSS.js +21 -6
- package/source/providers/inputs/Pict-Provider-Input-Diagram.js +230 -5
- package/source/providers/layouts/Pict-Layout-Tabular.js +278 -25
- package/test/Pict-Provider-Input-Diagram_tests.js +180 -0
package/CONTRIBUTING.md
CHANGED
|
@@ -47,4 +47,4 @@ When in doubt, match what the surrounding code does.
|
|
|
47
47
|
|
|
48
48
|
## Repository Structure
|
|
49
49
|
|
|
50
|
-
Each module is its own git repository. The [retold](https://github.com/
|
|
50
|
+
Each module is its own git repository. The [retold](https://github.com/fable-retold/retold) repository tracks module organization but does not contain module source code. Direct your pull request to the specific module repository where your change belongs.
|
package/README.md
CHANGED
|
@@ -271,7 +271,7 @@ of data in your application.
|
|
|
271
271
|
|
|
272
272
|
## Documentation
|
|
273
273
|
|
|
274
|
-
The complete documentation - an interactive guide with live examples - is hosted at **[
|
|
274
|
+
The complete documentation - an interactive guide with live examples - is hosted at **[fable-retold.github.io/pict-section-form](https://fable-retold.github.io/pict-section-form/)**:
|
|
275
275
|
|
|
276
276
|
| Document | Description |
|
|
277
277
|
|----------|-------------|
|
|
@@ -365,4 +365,4 @@ MIT
|
|
|
365
365
|
|
|
366
366
|
## Contributing
|
|
367
367
|
|
|
368
|
-
Pull requests are welcome. For details on our code of conduct, contribution process, and testing requirements, see the [Retold Contributing Guide](https://github.com/
|
|
368
|
+
Pull requests are welcome. For details on our code of conduct, contribution process, and testing requirements, see the [Retold Contributing Guide](https://github.com/fable-retold/retold/blob/main/docs/contributing.md).
|
|
@@ -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
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
const libPictSectionGroupLayout = require('../Pict-Provider-DynamicLayout.js');
|
|
2
2
|
|
|
3
|
+
// The resolved --theme-color-* tokens carried onto a column-chooser popover when it is portaled to
|
|
4
|
+
// <body>: off its scoped container it would otherwise fall back to the stylesheet's hex defaults.
|
|
5
|
+
// Mirrors pict-section-picker's PictView-Picker `_THEME_TOKENS`.
|
|
6
|
+
const _COLCHOOSER_THEME_TOKENS =
|
|
7
|
+
[
|
|
8
|
+
'--theme-color-text-primary', '--theme-color-text-secondary', '--theme-color-text-muted',
|
|
9
|
+
'--theme-color-border-default', '--theme-color-border-light', '--theme-color-background-panel',
|
|
10
|
+
'--theme-color-background-tertiary',
|
|
11
|
+
];
|
|
12
|
+
|
|
3
13
|
class TabularLayout extends libPictSectionGroupLayout
|
|
4
14
|
{
|
|
5
15
|
constructor(pFable, pOptions, pServiceHash)
|
|
@@ -39,19 +49,24 @@ class TabularLayout extends libPictSectionGroupLayout
|
|
|
39
49
|
+ ' .pict-tabular-sort-control.pict-tabular-sort-asc, .pict-tabular-sort-control.pict-tabular-sort-desc { opacity: 1; }',
|
|
40
50
|
500);
|
|
41
51
|
|
|
42
|
-
// CSS for the optional ColumnChooser feature: a right-aligned trigger button
|
|
43
|
-
//
|
|
44
|
-
//
|
|
45
|
-
//
|
|
46
|
-
|
|
47
|
-
|
|
52
|
+
// CSS for the optional ColumnChooser feature: a right-aligned trigger button above the
|
|
53
|
+
// table plus a checkbox popover. Anchored the same listener-free way as pict-section-picker:
|
|
54
|
+
// the popover is position:absolute under the (position:relative) bar so it rides page scroll
|
|
55
|
+
// for free, and is portaled to <body> in DOCUMENT coords only when a clipping ancestor would
|
|
56
|
+
// otherwise cut it -- no scroll/resize handlers. The transparent backdrop catches outside
|
|
57
|
+
// clicks. Dark-mode blocks (below, with DARK var() fallbacks) let the widget theme correctly
|
|
58
|
+
// even where the host has not defined the --theme-color-* tokens; a host that HAS defined
|
|
59
|
+
// them still wins, and the token values are carried across when the popover is portaled.
|
|
60
|
+
let tmpColumnChooserBaseCSS = /*css*/`
|
|
61
|
+
.pict-tabular-colchooser-bar { position: relative; display: flex; justify-content: flex-end; margin: 0 0 0.35rem; }
|
|
48
62
|
.pict-tabular-colchooser-trigger { display: inline-flex; align-items: center; gap: 0.35rem; cursor: pointer; font: inherit; font-size: 0.88rem;
|
|
49
63
|
padding: 0.3rem 0.65rem; border: 1px solid var(--theme-color-border-default, #d7dce3); border-radius: 7px;
|
|
50
64
|
background: var(--theme-color-background-panel, #fff); color: var(--theme-color-text-secondary, #45505f); }
|
|
51
65
|
.pict-tabular-colchooser-trigger:hover { background: var(--theme-color-background-tertiary, #eceef2); color: var(--theme-color-text-primary, #1f2733); }
|
|
52
66
|
.pict-tabular-colchooser-count { font-size: 0.8em; color: var(--theme-color-text-muted, #6b7686); }
|
|
53
|
-
.pict-tabular-colchooser-pop { position:
|
|
67
|
+
.pict-tabular-colchooser-pop { position: absolute; top: calc(100% + 6px); right: 0; z-index: 30; min-width: 220px; max-width: 320px; display: none; }
|
|
54
68
|
.pict-tabular-colchooser-pop.open { display: block; }
|
|
69
|
+
.pict-tabular-colchooser-pop.pict-tabular-colchooser-pop-portal { right: auto; }
|
|
55
70
|
.pict-tabular-colchooser-backdrop { position: fixed; inset: 0; z-index: 0; }
|
|
56
71
|
.pict-tabular-colchooser-panel { position: relative; z-index: 1; display: flex; flex-direction: column; max-height: min(70vh, 420px);
|
|
57
72
|
background: var(--theme-color-background-panel, #fff); border: 1px solid var(--theme-color-border-default, #d7dce3);
|
|
@@ -64,7 +79,29 @@ class TabularLayout extends libPictSectionGroupLayout
|
|
|
64
79
|
.pict-tabular-colchooser-footer { flex: 0 0 auto; display: flex; justify-content: flex-end; padding: 0.45rem 0.7rem; border-top: 1px solid var(--theme-color-border-light, #e8ebf0); }
|
|
65
80
|
.pict-tabular-colchooser-reset { font: inherit; font-size: 0.84rem; cursor: pointer; border: none; background: transparent; color: var(--theme-color-text-muted, #6b7686); padding: 0.15rem 0.3rem; border-radius: 5px; }
|
|
66
81
|
.pict-tabular-colchooser-reset:hover { color: var(--theme-color-text-primary, #1f2733); background: var(--theme-color-background-tertiary, #eceef2); }
|
|
67
|
-
|
|
82
|
+
`;
|
|
83
|
+
// Dark-mode overrides: re-declare only the color-bearing rules with DARK var() fallbacks under
|
|
84
|
+
// each of the app's dark signals. Duplicated per selector (explicit [data-theme=dark] and
|
|
85
|
+
// .theme-dark, plus the system preference guarded by html:not([data-theme=light]) so an
|
|
86
|
+
// explicit light choice still wins) exactly as headlight-styles' bulma-*.scss does. Higher
|
|
87
|
+
// specificity than the base rules, so dark wins whenever its selector matches; the [data-theme]
|
|
88
|
+
// signal lives on <html>, so these still apply after a popover is portaled to <body>.
|
|
89
|
+
let fColumnChooserDarkRules = (pScope) => /*css*/`
|
|
90
|
+
${pScope} .pict-tabular-colchooser-trigger { border-color: var(--theme-color-border-default, #3a4250); background: var(--theme-color-background-panel, #242b36); color: var(--theme-color-text-secondary, #c3cad4); }
|
|
91
|
+
${pScope} .pict-tabular-colchooser-trigger:hover { background: var(--theme-color-background-tertiary, #2c3542); color: var(--theme-color-text-primary, #e6e9ee); }
|
|
92
|
+
${pScope} .pict-tabular-colchooser-count { color: var(--theme-color-text-muted, #8b95a4); }
|
|
93
|
+
${pScope} .pict-tabular-colchooser-panel { background: var(--theme-color-background-panel, #242b36); border-color: var(--theme-color-border-default, #3a4250); }
|
|
94
|
+
${pScope} .pict-tabular-colchooser-row { color: var(--theme-color-text-primary, #e6e9ee); }
|
|
95
|
+
${pScope} .pict-tabular-colchooser-row:hover { background: var(--theme-color-background-tertiary, #2c3542); }
|
|
96
|
+
${pScope} .pict-tabular-colchooser-footer { border-top-color: var(--theme-color-border-light, #333b47); }
|
|
97
|
+
${pScope} .pict-tabular-colchooser-reset { color: var(--theme-color-text-muted, #8b95a4); }
|
|
98
|
+
${pScope} .pict-tabular-colchooser-reset:hover { color: var(--theme-color-text-primary, #e6e9ee); background: var(--theme-color-background-tertiary, #2c3542); }
|
|
99
|
+
`;
|
|
100
|
+
this.pict.CSSMap.addCSS('Pict-Layout-Tabular-ColumnChooser-CSS',
|
|
101
|
+
tmpColumnChooserBaseCSS
|
|
102
|
+
+ fColumnChooserDarkRules('[data-theme="dark"]')
|
|
103
|
+
+ fColumnChooserDarkRules('.theme-dark')
|
|
104
|
+
+ `@media (prefers-color-scheme: dark) {` + fColumnChooserDarkRules('html:not([data-theme="light"])') + `}`,
|
|
68
105
|
500);
|
|
69
106
|
}
|
|
70
107
|
}
|
|
@@ -1098,52 +1135,268 @@ class TabularLayout extends libPictSectionGroupLayout
|
|
|
1098
1135
|
tmpPopoverElements[0].classList.toggle('open', !!pOpen);
|
|
1099
1136
|
if (pOpen)
|
|
1100
1137
|
{
|
|
1101
|
-
this.
|
|
1138
|
+
this._applyTabularColumnChooserAnchor(pView, pGroup, tmpPopoverElements[0]);
|
|
1139
|
+
}
|
|
1140
|
+
else
|
|
1141
|
+
{
|
|
1142
|
+
// Bring a portaled popover home on close so a closed chooser never strands a node on <body>.
|
|
1143
|
+
this._restoreTabularColumnChooserPopover(pView, pGroup, tmpPopoverElements[0]);
|
|
1102
1144
|
}
|
|
1103
1145
|
}
|
|
1104
1146
|
|
|
1105
1147
|
/**
|
|
1106
|
-
*
|
|
1107
|
-
*
|
|
1108
|
-
*
|
|
1148
|
+
* Anchor the (open) chooser popover to its trigger with the same listener-free strategy as
|
|
1149
|
+
* pict-section-picker: keep it in the DOM and CSS-absolute under the (position:relative) bar --
|
|
1150
|
+
* which rides page scroll for free -- UNLESS a clipping ancestor would cut it, in which case
|
|
1151
|
+
* portal it to <body> and place it in document coords. No scroll/resize handlers: an absolute
|
|
1152
|
+
* (not fixed) panel tracks the document as it scrolls, so one placement holds.
|
|
1109
1153
|
*
|
|
1110
1154
|
* @param {Object} pView
|
|
1111
1155
|
* @param {Object} pGroup
|
|
1112
1156
|
* @param {HTMLElement} pPopover
|
|
1113
1157
|
*/
|
|
1114
|
-
|
|
1158
|
+
_applyTabularColumnChooserAnchor(pView, pGroup, pPopover)
|
|
1159
|
+
{
|
|
1160
|
+
if (!pPopover || (typeof document === 'undefined') || (typeof window === 'undefined'))
|
|
1161
|
+
{
|
|
1162
|
+
return;
|
|
1163
|
+
}
|
|
1164
|
+
let tmpTrigger = document.getElementById(this._getTabularColumnChooserElementId(pView, pGroup, 'TRIGGER'));
|
|
1165
|
+
if (!tmpTrigger)
|
|
1166
|
+
{
|
|
1167
|
+
return;
|
|
1168
|
+
}
|
|
1169
|
+
// Judge from the trigger (it never moves); a portaled panel has no clipping ancestors, so
|
|
1170
|
+
// testing the panel itself would flip-flop.
|
|
1171
|
+
if (this._tabularColumnChooserShouldPortal(tmpTrigger, pPopover))
|
|
1172
|
+
{
|
|
1173
|
+
this._portalTabularColumnChooserPopover(pPopover, tmpTrigger);
|
|
1174
|
+
}
|
|
1175
|
+
else
|
|
1176
|
+
{
|
|
1177
|
+
this._restoreTabularColumnChooserPopover(pView, pGroup, pPopover);
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
/**
|
|
1182
|
+
* Move the popover to <body> and place it against the trigger in document coords (viewport rect +
|
|
1183
|
+
* scroll), flipping above when the room below is genuinely cramped. Carries the resolved
|
|
1184
|
+
* --theme-color-* tokens across so the panel stays themed off its scoped container.
|
|
1185
|
+
*
|
|
1186
|
+
* @param {HTMLElement} pPopover
|
|
1187
|
+
* @param {HTMLElement} pTrigger
|
|
1188
|
+
*/
|
|
1189
|
+
_portalTabularColumnChooserPopover(pPopover, pTrigger)
|
|
1115
1190
|
{
|
|
1116
|
-
|
|
1117
|
-
if (!tmpTriggerElements.length || (typeof window === 'undefined'))
|
|
1191
|
+
if (!pPopover || !pTrigger || (typeof document === 'undefined') || (typeof window === 'undefined'))
|
|
1118
1192
|
{
|
|
1119
1193
|
return;
|
|
1120
1194
|
}
|
|
1195
|
+
// Adopt this popover onto <body>, sweeping any stale same-id copy a prior re-render left behind.
|
|
1196
|
+
this._sweepPortaledColchooserOrphans(pPopover.getAttribute('id'), pPopover);
|
|
1197
|
+
if (pPopover.parentElement !== document.body)
|
|
1198
|
+
{
|
|
1199
|
+
document.body.appendChild(pPopover);
|
|
1200
|
+
}
|
|
1201
|
+
pPopover.classList.add('pict-tabular-colchooser-pop-portal');
|
|
1202
|
+
// Carry the resolved --theme-color-* tokens across: off its scoped container the panel would
|
|
1203
|
+
// otherwise fall back to the stylesheet hex defaults. Skip empty reads so a token the host never
|
|
1204
|
+
// defined keeps its own var(--token, #hex) fallback (matches pict-section-picker's _portalPop).
|
|
1205
|
+
if (typeof window.getComputedStyle === 'function')
|
|
1206
|
+
{
|
|
1207
|
+
let tmpComputed = window.getComputedStyle(pTrigger);
|
|
1208
|
+
_COLCHOOSER_THEME_TOKENS.forEach((pToken) =>
|
|
1209
|
+
{
|
|
1210
|
+
let tmpValue = tmpComputed.getPropertyValue(pToken);
|
|
1211
|
+
if (tmpValue && tmpValue.trim() !== '')
|
|
1212
|
+
{
|
|
1213
|
+
pPopover.style.setProperty(pToken, tmpValue.trim());
|
|
1214
|
+
}
|
|
1215
|
+
});
|
|
1216
|
+
}
|
|
1121
1217
|
let tmpPanel = pPopover.querySelector('.pict-tabular-colchooser-panel');
|
|
1122
|
-
let tmpRect =
|
|
1218
|
+
let tmpRect = pTrigger.getBoundingClientRect();
|
|
1123
1219
|
let tmpGap = 6;
|
|
1124
1220
|
let tmpMargin = 8;
|
|
1221
|
+
let tmpWidth = pPopover.offsetWidth || 240;
|
|
1125
1222
|
let tmpViewportHeight = window.innerHeight;
|
|
1126
1223
|
let tmpViewportWidth = window.innerWidth;
|
|
1127
|
-
let tmpWidth = pPopover.offsetWidth || 240;
|
|
1128
|
-
// Right-align the popover to the (right-aligned) trigger, clamped into the viewport.
|
|
1129
|
-
pPopover.style.left = `${Math.round(Math.max(tmpMargin, Math.min(tmpRect.right - tmpWidth, tmpViewportWidth - tmpWidth - tmpMargin)))}px`;
|
|
1130
|
-
pPopover.style.right = 'auto';
|
|
1131
1224
|
let tmpSpaceBelow = tmpViewportHeight - tmpRect.bottom - tmpGap - tmpMargin;
|
|
1132
1225
|
let tmpSpaceAbove = tmpRect.top - tmpGap - tmpMargin;
|
|
1133
|
-
|
|
1226
|
+
let tmpBelow = (tmpSpaceBelow >= 220) || (tmpSpaceBelow >= tmpSpaceAbove);
|
|
1227
|
+
// Document coords (viewport rect + scroll): absolute against <body>, so the panel rides page
|
|
1228
|
+
// scroll with no listener. Right-aligned to the trigger, clamped into the viewport.
|
|
1229
|
+
pPopover.style.right = 'auto';
|
|
1230
|
+
pPopover.style.bottom = 'auto';
|
|
1231
|
+
pPopover.style.left = `${Math.round(Math.max(tmpMargin, Math.min(tmpRect.right - tmpWidth, tmpViewportWidth - tmpWidth - tmpMargin)) + window.scrollX)}px`;
|
|
1232
|
+
if (tmpBelow)
|
|
1134
1233
|
{
|
|
1135
|
-
pPopover.style.top = `${Math.round(tmpRect.bottom + tmpGap)}px`;
|
|
1136
|
-
pPopover.style.
|
|
1234
|
+
pPopover.style.top = `${Math.round(tmpRect.bottom + tmpGap + window.scrollY)}px`;
|
|
1235
|
+
pPopover.style.transform = '';
|
|
1137
1236
|
if (tmpPanel) { tmpPanel.style.maxHeight = `${Math.max(160, Math.min(tmpSpaceBelow, 420))}px`; }
|
|
1138
1237
|
}
|
|
1139
1238
|
else
|
|
1140
1239
|
{
|
|
1141
|
-
pPopover.style.top =
|
|
1142
|
-
pPopover.style.
|
|
1240
|
+
pPopover.style.top = `${Math.round(tmpRect.top - tmpGap + window.scrollY)}px`;
|
|
1241
|
+
pPopover.style.transform = 'translateY(-100%)';
|
|
1143
1242
|
if (tmpPanel) { tmpPanel.style.maxHeight = `${Math.max(160, Math.min(tmpSpaceAbove, 420))}px`; }
|
|
1144
1243
|
}
|
|
1145
1244
|
}
|
|
1146
1245
|
|
|
1246
|
+
/**
|
|
1247
|
+
* Re-home a portaled popover into its bar and drop everything the portal wrote. Doubles as the
|
|
1248
|
+
* orphan sweeper: if a re-render already baked a fresh in-bar popover, the portaled one is stale
|
|
1249
|
+
* and gets discarded rather than duplicated.
|
|
1250
|
+
*
|
|
1251
|
+
* @param {Object} pView
|
|
1252
|
+
* @param {Object} pGroup
|
|
1253
|
+
* @param {HTMLElement} pPopover
|
|
1254
|
+
*/
|
|
1255
|
+
_restoreTabularColumnChooserPopover(pView, pGroup, pPopover)
|
|
1256
|
+
{
|
|
1257
|
+
if (!pPopover || (typeof document === 'undefined'))
|
|
1258
|
+
{
|
|
1259
|
+
return;
|
|
1260
|
+
}
|
|
1261
|
+
// Discard any OTHER portaled copy of this popover a prior re-render may have left on <body>.
|
|
1262
|
+
this._sweepPortaledColchooserOrphans(pPopover.getAttribute('id'), pPopover);
|
|
1263
|
+
if (pPopover.parentElement === document.body)
|
|
1264
|
+
{
|
|
1265
|
+
let tmpTrigger = document.getElementById(this._getTabularColumnChooserElementId(pView, pGroup, 'TRIGGER'));
|
|
1266
|
+
let tmpBar = tmpTrigger ? tmpTrigger.parentElement : null;
|
|
1267
|
+
let tmpFreshInBar = tmpBar ? tmpBar.querySelector('.pict-tabular-colchooser-pop') : null;
|
|
1268
|
+
if (tmpBar && (!tmpFreshInBar || tmpFreshInBar === pPopover))
|
|
1269
|
+
{
|
|
1270
|
+
// Re-home the popover next to its trigger, inside the bar.
|
|
1271
|
+
tmpBar.appendChild(pPopover);
|
|
1272
|
+
}
|
|
1273
|
+
else
|
|
1274
|
+
{
|
|
1275
|
+
// A re-render already baked a fresh in-bar popover; this portaled one is a leftover.
|
|
1276
|
+
pPopover.remove();
|
|
1277
|
+
return;
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
pPopover.classList.remove('pict-tabular-colchooser-pop-portal');
|
|
1281
|
+
// Clear the inline offsets/transform, or they'd override the stylesheet and strand the panel.
|
|
1282
|
+
pPopover.style.top = '';
|
|
1283
|
+
pPopover.style.left = '';
|
|
1284
|
+
pPopover.style.right = '';
|
|
1285
|
+
pPopover.style.bottom = '';
|
|
1286
|
+
pPopover.style.transform = '';
|
|
1287
|
+
// Drop the copied tokens so back in the bar it inherits them live again.
|
|
1288
|
+
_COLCHOOSER_THEME_TOKENS.forEach((pToken) => pPopover.style.removeProperty(pToken));
|
|
1289
|
+
let tmpPanel = pPopover.querySelector('.pict-tabular-colchooser-panel');
|
|
1290
|
+
if (tmpPanel) { tmpPanel.style.maxHeight = ''; }
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1293
|
+
/**
|
|
1294
|
+
* Remove any portaled copies of a chooser popover (matched by element id) that are direct children
|
|
1295
|
+
* of <body>, except the one to keep. Iterates body children so no attribute-selector escaping of
|
|
1296
|
+
* the id is needed, and is scoped by id so it never touches another table's portaled popover.
|
|
1297
|
+
*
|
|
1298
|
+
* @param {string} pElementId
|
|
1299
|
+
* @param {HTMLElement} pKeep
|
|
1300
|
+
*/
|
|
1301
|
+
_sweepPortaledColchooserOrphans(pElementId, pKeep)
|
|
1302
|
+
{
|
|
1303
|
+
if (!pElementId || (typeof document === 'undefined') || !document.body)
|
|
1304
|
+
{
|
|
1305
|
+
return;
|
|
1306
|
+
}
|
|
1307
|
+
Array.prototype.slice.call(document.body.children).forEach((pNode) =>
|
|
1308
|
+
{
|
|
1309
|
+
if (pNode !== pKeep && pNode.id === pElementId
|
|
1310
|
+
&& pNode.classList && pNode.classList.contains('pict-tabular-colchooser-pop'))
|
|
1311
|
+
{
|
|
1312
|
+
pNode.remove();
|
|
1313
|
+
}
|
|
1314
|
+
});
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
/**
|
|
1318
|
+
* Portal when ANY clipping ancestor of the trigger would actually cut the popover -- an overflow
|
|
1319
|
+
* ancestor alone isn't enough, but a roomy inner clipper doesn't excuse a tighter one further out.
|
|
1320
|
+
*
|
|
1321
|
+
* @param {HTMLElement} pTrigger
|
|
1322
|
+
* @param {HTMLElement} pPopover
|
|
1323
|
+
* @returns {boolean}
|
|
1324
|
+
*/
|
|
1325
|
+
_tabularColumnChooserShouldPortal(pTrigger, pPopover)
|
|
1326
|
+
{
|
|
1327
|
+
let tmpWidth = (pPopover && pPopover.offsetWidth) ? pPopover.offsetWidth : 240;
|
|
1328
|
+
let tmpClipper = this._tabularColumnChooserClippingAncestor(pTrigger);
|
|
1329
|
+
while (tmpClipper)
|
|
1330
|
+
{
|
|
1331
|
+
if (this._tabularColumnChooserClipBites(pTrigger, tmpClipper, tmpWidth))
|
|
1332
|
+
{
|
|
1333
|
+
return true;
|
|
1334
|
+
}
|
|
1335
|
+
tmpClipper = this._tabularColumnChooserClippingAncestor(tmpClipper);
|
|
1336
|
+
}
|
|
1337
|
+
return false;
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1340
|
+
/**
|
|
1341
|
+
* Nearest ancestor (up to, not including, <body>) with an overflow clip on any axis, or null.
|
|
1342
|
+
* Stops at <body> because the document's own scroll is what the absolute anchoring rides on.
|
|
1343
|
+
*
|
|
1344
|
+
* @param {HTMLElement} pElement
|
|
1345
|
+
* @returns {HTMLElement|null}
|
|
1346
|
+
*/
|
|
1347
|
+
_tabularColumnChooserClippingAncestor(pElement)
|
|
1348
|
+
{
|
|
1349
|
+
if ((typeof window === 'undefined') || (typeof window.getComputedStyle !== 'function'))
|
|
1350
|
+
{
|
|
1351
|
+
return null;
|
|
1352
|
+
}
|
|
1353
|
+
let tmpNode = pElement ? pElement.parentElement : null;
|
|
1354
|
+
while (tmpNode && tmpNode.nodeType === 1 && tmpNode !== document.body)
|
|
1355
|
+
{
|
|
1356
|
+
let tmpStyle = window.getComputedStyle(tmpNode);
|
|
1357
|
+
if (tmpStyle && [ tmpStyle.overflow, tmpStyle.overflowX, tmpStyle.overflowY ].some((pValue) => pValue && pValue !== 'visible'))
|
|
1358
|
+
{
|
|
1359
|
+
return tmpNode;
|
|
1360
|
+
}
|
|
1361
|
+
tmpNode = tmpNode.parentElement;
|
|
1362
|
+
}
|
|
1363
|
+
return null;
|
|
1364
|
+
}
|
|
1365
|
+
|
|
1366
|
+
/**
|
|
1367
|
+
* Would the clipper cut the popover if it opened in place? The CSS path opens downward, right-
|
|
1368
|
+
* aligned to the trigger; project that worst-case box (trigger bottom + gap, up to the max height)
|
|
1369
|
+
* and test whether any edge falls outside the clipper. 1px slack avoids a needless portal on a
|
|
1370
|
+
* flush edge.
|
|
1371
|
+
*
|
|
1372
|
+
* @param {HTMLElement} pTrigger
|
|
1373
|
+
* @param {HTMLElement} pClipper
|
|
1374
|
+
* @param {number} pWidth
|
|
1375
|
+
* @returns {boolean}
|
|
1376
|
+
*/
|
|
1377
|
+
_tabularColumnChooserClipBites(pTrigger, pClipper, pWidth)
|
|
1378
|
+
{
|
|
1379
|
+
if (!pTrigger || !pClipper || (typeof pTrigger.getBoundingClientRect !== 'function')
|
|
1380
|
+
|| (typeof pClipper.getBoundingClientRect !== 'function'))
|
|
1381
|
+
{
|
|
1382
|
+
return true;
|
|
1383
|
+
}
|
|
1384
|
+
let tmpTriggerRect = pTrigger.getBoundingClientRect();
|
|
1385
|
+
let tmpClipRect = pClipper.getBoundingClientRect();
|
|
1386
|
+
let tmpGap = 6;
|
|
1387
|
+
let tmpIdeal = 420;
|
|
1388
|
+
let tmpSlack = 1;
|
|
1389
|
+
let tmpWidthResolved = Math.max(220, pWidth || 220);
|
|
1390
|
+
let tmpPanelTop = tmpTriggerRect.bottom + tmpGap;
|
|
1391
|
+
let tmpPanelBottom = tmpPanelTop + tmpIdeal;
|
|
1392
|
+
let tmpPanelRight = tmpTriggerRect.right;
|
|
1393
|
+
let tmpPanelLeft = tmpTriggerRect.right - tmpWidthResolved;
|
|
1394
|
+
return (tmpPanelBottom > tmpClipRect.bottom + tmpSlack)
|
|
1395
|
+
|| (tmpPanelTop < tmpClipRect.top - tmpSlack)
|
|
1396
|
+
|| (tmpPanelLeft < tmpClipRect.left - tmpSlack)
|
|
1397
|
+
|| (tmpPanelRight > tmpClipRect.right + tmpSlack);
|
|
1398
|
+
}
|
|
1399
|
+
|
|
1147
1400
|
/**
|
|
1148
1401
|
* Rebuild + re-render a tabular view and re-marshal the form data into it.
|
|
1149
1402
|
* Same tail as sortTabularColumn: the rebuild re-bakes the table template
|
|
@@ -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');
|