@txstate-mws/svelte-components 1.2.7 → 1.2.10

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.
@@ -1,140 +1,128 @@
1
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
- };
6
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
7
- if (kind === "m") throw new TypeError("Private method is not writable");
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
9
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
- };
12
- var _ElementQueries_instances, _ElementQueries_watchlist, _ElementQueries_busy, _ElementQueries_hasInit, _ElementQueries_mutationobserver, _ElementQueries_boundRefresh, _ElementQueries_subscribers, _ElementQueries_stores, _ElementQueries_processwidths, _ElementQueries_finddepth, _ElementQueries_collecttargets, _ElementQueries_gotoanchor, _ElementQueries_activate, _ElementQueries_activateRaw, _ElementQueries_deactivate;
13
1
  class ElementQueries {
14
- constructor() {
15
- _ElementQueries_instances.add(this);
16
- _ElementQueries_watchlist.set(this, []);
17
- _ElementQueries_busy.set(this, false);
18
- _ElementQueries_hasInit.set(this, false);
19
- _ElementQueries_mutationobserver.set(this, void 0);
20
- _ElementQueries_boundRefresh.set(this, this.refresh.bind(this));
21
- _ElementQueries_subscribers.set(this, 0);
22
- _ElementQueries_stores.set(this, new Map());
2
+ #watchlist = [];
3
+ #busy = false;
4
+ #hasInit = false;
5
+ #mutationobserver;
6
+ #boundRefresh = this.refresh.bind(this);
7
+ #subscribers = 0;
8
+ #stores = new Map();
9
+ #processwidths() {
10
+ for (let i = 0; i < this.#watchlist.length; i++) {
11
+ const widths = [];
12
+ const attrs = [];
13
+ for (let j = 0; j < this.#watchlist[i].length; j++) {
14
+ widths.push(this.#watchlist[i][j].offsetWidth);
15
+ attrs.push(this.#watchlist[i][j].getAttribute('data-eq'));
16
+ }
17
+ for (let j = 0; j < this.#watchlist[i].length; j++) {
18
+ const el = this.#watchlist[i][j];
19
+ const w = widths[j];
20
+ let attrstr = '';
21
+ let finalw = 1600;
22
+ for (let k = 1600; k >= w && k > 700; k -= 100) {
23
+ attrstr += `${k}px `;
24
+ finalw = k;
25
+ }
26
+ for (let k = 700; k >= w; k -= 50) {
27
+ attrstr += `${k}px `;
28
+ finalw = k;
29
+ }
30
+ if (attrstr !== attrs[j])
31
+ el.setAttribute('data-eq', attrstr);
32
+ if (this.#stores.has(el)) {
33
+ this.#stores.get(el).update(v => v.width === finalw ? v : { ...v, width: finalw });
34
+ }
35
+ }
36
+ }
37
+ this.#busy = false;
38
+ }
39
+ #finddepth(target, currentdepth = 0) {
40
+ const closest = target.parentElement?.closest('.eq-parent');
41
+ if (!closest)
42
+ return currentdepth;
43
+ return this.#finddepth(closest, currentdepth + 1);
44
+ }
45
+ #collecttargets() {
46
+ this.#watchlist = [];
47
+ const targets = Array.from(document.querySelectorAll('.eq-parent'));
48
+ for (const target of targets) {
49
+ const depth = this.#finddepth(target);
50
+ if (!this.#watchlist[depth])
51
+ this.#watchlist[depth] = [target];
52
+ else
53
+ this.#watchlist[depth].push(target);
54
+ }
23
55
  }
24
56
  refresh() {
25
- if (!__classPrivateFieldGet(this, _ElementQueries_busy, "f") && __classPrivateFieldGet(this, _ElementQueries_watchlist, "f").length > 0) {
26
- __classPrivateFieldSet(this, _ElementQueries_busy, true, "f");
27
- requestAnimationFrame(__classPrivateFieldGet(this, _ElementQueries_instances, "m", _ElementQueries_processwidths).bind(this));
57
+ if (!this.#busy && this.#watchlist.length > 0) {
58
+ this.#busy = true;
59
+ requestAnimationFrame(this.#processwidths.bind(this));
60
+ }
61
+ }
62
+ #gotoanchor() {
63
+ // since we are dramatically resizing, we need to scroll to the proper place for an
64
+ // anchor tag
65
+ const m = document.location.hash.match(/^#([a-z][\w:.-]*)$/i);
66
+ if (m) {
67
+ const id = m[1];
68
+ requestAnimationFrame(() => document.getElementById(id) || document.querySelector(`[name="${id}"]`).scrollIntoView(true));
28
69
  }
29
70
  }
30
71
  fullresync() {
31
- __classPrivateFieldGet(this, _ElementQueries_instances, "m", _ElementQueries_collecttargets).call(this);
72
+ this.#collecttargets();
32
73
  this.refresh();
33
74
  }
75
+ #activate() {
76
+ this.fullresync();
77
+ window.addEventListener('resize', this.#boundRefresh);
78
+ this.#mutationobserver = new MutationObserver(() => this.fullresync());
79
+ this.#mutationobserver.observe(document.body, {
80
+ subtree: true,
81
+ childList: true,
82
+ attributeFilter: ['class', 'style']
83
+ });
84
+ }
85
+ #activateRaw() {
86
+ if (typeof window === 'undefined' || this.#hasInit)
87
+ return;
88
+ this.#hasInit = true;
89
+ if (['interactive', 'complete'].includes(document.readyState)) {
90
+ this.#activate();
91
+ }
92
+ else {
93
+ window.addEventListener('DOMContentLoaded', () => {
94
+ this.#activate();
95
+ this.#gotoanchor();
96
+ });
97
+ }
98
+ }
34
99
  // if someone uses the library without svelte, they may just activate it once
35
100
  // instead of faithfully subscribing and unsubscribing, so we'll add a subscriber that can't be
36
101
  // decremented and it will stay activated forever
37
102
  activate() {
38
- var _a;
39
- __classPrivateFieldSet(this, _ElementQueries_subscribers, (_a = __classPrivateFieldGet(this, _ElementQueries_subscribers, "f"), _a++, _a), "f");
40
- __classPrivateFieldGet(this, _ElementQueries_instances, "m", _ElementQueries_activateRaw).call(this);
103
+ this.#subscribers++;
104
+ this.#activateRaw();
105
+ }
106
+ #deactivate() {
107
+ if (this.#subscribers > 0 || typeof window === 'undefined')
108
+ return;
109
+ window.removeEventListener('resize', this.#boundRefresh);
110
+ this.#mutationobserver?.disconnect();
111
+ this.#hasInit = false;
41
112
  }
42
113
  subscribe(el, store) {
43
- var _a;
44
- __classPrivateFieldSet(this, _ElementQueries_subscribers, (_a = __classPrivateFieldGet(this, _ElementQueries_subscribers, "f"), _a++, _a), "f");
114
+ this.#subscribers++;
45
115
  if (store)
46
- __classPrivateFieldGet(this, _ElementQueries_stores, "f").set(el, store);
116
+ this.#stores.set(el, store);
47
117
  else
48
- __classPrivateFieldGet(this, _ElementQueries_stores, "f").delete(el);
49
- __classPrivateFieldGet(this, _ElementQueries_instances, "m", _ElementQueries_activateRaw).call(this);
118
+ this.#stores.delete(el);
119
+ this.#activateRaw();
50
120
  return () => {
51
- var _a;
52
- if (__classPrivateFieldSet(this, _ElementQueries_subscribers, (_a = __classPrivateFieldGet(this, _ElementQueries_subscribers, "f"), --_a), "f") === 0)
53
- __classPrivateFieldGet(this, _ElementQueries_instances, "m", _ElementQueries_deactivate).call(this);
121
+ if (--this.#subscribers === 0)
122
+ this.#deactivate();
54
123
  };
55
124
  }
56
125
  }
57
- _ElementQueries_watchlist = new WeakMap(), _ElementQueries_busy = new WeakMap(), _ElementQueries_hasInit = new WeakMap(), _ElementQueries_mutationobserver = new WeakMap(), _ElementQueries_boundRefresh = new WeakMap(), _ElementQueries_subscribers = new WeakMap(), _ElementQueries_stores = new WeakMap(), _ElementQueries_instances = new WeakSet(), _ElementQueries_processwidths = function _ElementQueries_processwidths() {
58
- for (let i = 0; i < __classPrivateFieldGet(this, _ElementQueries_watchlist, "f").length; i++) {
59
- const widths = [];
60
- const attrs = [];
61
- for (let j = 0; j < __classPrivateFieldGet(this, _ElementQueries_watchlist, "f")[i].length; j++) {
62
- widths.push(__classPrivateFieldGet(this, _ElementQueries_watchlist, "f")[i][j].offsetWidth);
63
- attrs.push(__classPrivateFieldGet(this, _ElementQueries_watchlist, "f")[i][j].getAttribute('data-eq'));
64
- }
65
- for (let j = 0; j < __classPrivateFieldGet(this, _ElementQueries_watchlist, "f")[i].length; j++) {
66
- const el = __classPrivateFieldGet(this, _ElementQueries_watchlist, "f")[i][j];
67
- const w = widths[j];
68
- let attrstr = '';
69
- let finalw = 1600;
70
- for (let k = 1600; k >= w && k > 700; k -= 100) {
71
- attrstr += `${k}px `;
72
- finalw = k;
73
- }
74
- for (let k = 700; k >= w; k -= 50) {
75
- attrstr += `${k}px `;
76
- finalw = k;
77
- }
78
- if (attrstr !== attrs[j])
79
- el.setAttribute('data-eq', attrstr);
80
- if (__classPrivateFieldGet(this, _ElementQueries_stores, "f").has(el)) {
81
- __classPrivateFieldGet(this, _ElementQueries_stores, "f").get(el).update(v => v.width === finalw ? v : { ...v, width: finalw });
82
- }
83
- }
84
- }
85
- __classPrivateFieldSet(this, _ElementQueries_busy, false, "f");
86
- }, _ElementQueries_finddepth = function _ElementQueries_finddepth(target, currentdepth = 0) {
87
- const closest = target.parentElement?.closest('.eq-parent');
88
- if (!closest)
89
- return currentdepth;
90
- return __classPrivateFieldGet(this, _ElementQueries_instances, "m", _ElementQueries_finddepth).call(this, closest, currentdepth + 1);
91
- }, _ElementQueries_collecttargets = function _ElementQueries_collecttargets() {
92
- __classPrivateFieldSet(this, _ElementQueries_watchlist, [], "f");
93
- const targets = Array.from(document.querySelectorAll('.eq-parent'));
94
- for (const target of targets) {
95
- const depth = __classPrivateFieldGet(this, _ElementQueries_instances, "m", _ElementQueries_finddepth).call(this, target);
96
- if (!__classPrivateFieldGet(this, _ElementQueries_watchlist, "f")[depth])
97
- __classPrivateFieldGet(this, _ElementQueries_watchlist, "f")[depth] = [target];
98
- else
99
- __classPrivateFieldGet(this, _ElementQueries_watchlist, "f")[depth].push(target);
100
- }
101
- }, _ElementQueries_gotoanchor = function _ElementQueries_gotoanchor() {
102
- // since we are dramatically resizing, we need to scroll to the proper place for an
103
- // anchor tag
104
- const m = document.location.hash.match(/^#([a-z][\w:.-]*)$/i);
105
- if (m) {
106
- const id = m[1];
107
- requestAnimationFrame(() => document.getElementById(id) || document.querySelector(`[name="${id}"]`).scrollIntoView(true));
108
- }
109
- }, _ElementQueries_activate = function _ElementQueries_activate() {
110
- this.fullresync();
111
- window.addEventListener('resize', __classPrivateFieldGet(this, _ElementQueries_boundRefresh, "f"));
112
- __classPrivateFieldSet(this, _ElementQueries_mutationobserver, new MutationObserver(() => this.fullresync()), "f");
113
- __classPrivateFieldGet(this, _ElementQueries_mutationobserver, "f").observe(document.body, {
114
- subtree: true,
115
- childList: true,
116
- attributeFilter: ['class', 'style']
117
- });
118
- }, _ElementQueries_activateRaw = function _ElementQueries_activateRaw() {
119
- if (typeof window === 'undefined' || __classPrivateFieldGet(this, _ElementQueries_hasInit, "f"))
120
- return;
121
- __classPrivateFieldSet(this, _ElementQueries_hasInit, true, "f");
122
- if (['interactive', 'complete'].includes(document.readyState)) {
123
- __classPrivateFieldGet(this, _ElementQueries_instances, "m", _ElementQueries_activate).call(this);
124
- }
125
- else {
126
- window.addEventListener('DOMContentLoaded', () => {
127
- __classPrivateFieldGet(this, _ElementQueries_instances, "m", _ElementQueries_activate).call(this);
128
- __classPrivateFieldGet(this, _ElementQueries_instances, "m", _ElementQueries_gotoanchor).call(this);
129
- });
130
- }
131
- }, _ElementQueries_deactivate = function _ElementQueries_deactivate() {
132
- if (__classPrivateFieldGet(this, _ElementQueries_subscribers, "f") > 0 || typeof window === 'undefined')
133
- return;
134
- window.removeEventListener('resize', __classPrivateFieldGet(this, _ElementQueries_boundRefresh, "f"));
135
- __classPrivateFieldGet(this, _ElementQueries_mutationobserver, "f")?.disconnect();
136
- __classPrivateFieldSet(this, _ElementQueries_hasInit, false, "f");
137
- };
138
126
  export const elementqueries = new ElementQueries();
139
127
  export function eq(el, opts) {
140
128
  el.classList.add('eq-parent');
@@ -1,4 +1,4 @@
1
- <script >export let className = '';
1
+ <script>export let className = '';
2
2
  import { getContext } from 'svelte';
3
3
  import { resize } from '../actions';
4
4
  import { CARDLAYOUT } from '../types';
@@ -1,4 +1,4 @@
1
- <script >import { onDestroy, tick, setContext, onMount } from 'svelte';
1
+ <script>import { onDestroy, tick, setContext, onMount } from 'svelte';
2
2
  import { writable } from 'svelte/store';
3
3
  import { resize } from '../actions';
4
4
  import { CARDLAYOUT } from '../types';
@@ -1,4 +1,4 @@
1
- <script >import { Store } from '@txstate-mws/svelte-store';
1
+ <script>import { Store } from '@txstate-mws/svelte-store';
2
2
  import { derived } from 'svelte/store';
3
3
  import { classes } from '../util';
4
4
  import DefaultPopupMenu from './PopupMenu.svelte';
@@ -1,4 +1,4 @@
1
- <script >export let condition;
1
+ <script>export let condition;
2
2
  export let component = undefined;
3
3
  export let a = false;
4
4
  export let span = false;
@@ -1,7 +1,7 @@
1
- <script context="module" >const FocusLockStack = [];
1
+ <script context="module">const FocusLockStack = [];
2
2
  </script>
3
3
 
4
- <script >export let returnfocusto = undefined;
4
+ <script>export let returnfocusto = undefined;
5
5
  export let initialfocus = undefined;
6
6
  export let hidefocus = true;
7
7
  export let hidefocuslabel = 'focus is above modal dialog, start tabbing';
@@ -1,13 +1,23 @@
1
- <script >import ScreenReaderOnly from './ScreenReaderOnly.svelte';
1
+ <script>import { afterUpdate } from 'svelte';
2
+ import ScreenReaderOnly from './ScreenReaderOnly.svelte';
2
3
  import { resize, ResizeStore } from '../actions';
3
4
  export let loading;
4
5
  export let height = undefined;
5
6
  const store = new ResizeStore();
7
+ let containerelement;
8
+ let parentScrolls;
9
+ afterUpdate(() => {
10
+ if (height || !containerelement)
11
+ return;
12
+ const parent = containerelement.offsetParent;
13
+ const overflowY = window.getComputedStyle(parent).overflowY;
14
+ parentScrolls = overflowY === 'scroll' || overflowY === 'auto';
15
+ });
6
16
  </script>
7
17
 
8
18
  {#if loading}
9
- <div class="container" style:height={height} style:position={height ? 'relative' : 'absolute'}>
10
- <div use:resize={{ store }} class="loader" style:border-width="{$store.offsetWidth * 0.1}px"><ScreenReaderOnly>Loading</ScreenReaderOnly></div>
19
+ <div bind:this={containerelement} class="container" class:parentScrolls style:height={height} style:position={height ? 'relative' : undefined}>
20
+ <div use:resize={{ store }} class="loader" style:border-width="{$store.offsetWidth ? $store.offsetWidth * 0.1 : 0}px"><ScreenReaderOnly>Loading</ScreenReaderOnly></div>
11
21
  </div>
12
22
  {:else}
13
23
  <slot />
@@ -15,16 +25,21 @@ const store = new ResizeStore();
15
25
 
16
26
  <style>
17
27
  .container {
18
- position: fixed;
28
+ position: absolute;
19
29
  top: 0;
20
30
  left: 0;
21
31
  width: 100%;
22
32
  height: 100%;
33
+ z-index: 2;
23
34
  background-color: var(--loading-bg, var(--modal-bg, rgba(0, 0, 0, 0.7)));
24
35
  display: flex;
25
36
  align-items: center;
26
37
  justify-content: center;
27
38
  }
39
+ .container.parentScrolls {
40
+ position: sticky;
41
+ margin-bottom: -100%;
42
+ }
28
43
  .loader {
29
44
  box-sizing: content-box;
30
45
  width: var(--loading-size, 10%);
@@ -1,4 +1,4 @@
1
- <script >export let escapable = true;
1
+ <script>export let escapable = true;
2
2
  export let hidefocus = true;
3
3
  export let hidefocuslabel = undefined;
4
4
  export let returnfocusto = undefined;
@@ -37,7 +37,7 @@ onMount(() => {
37
37
  width: 100vw;
38
38
  height: 100vh;
39
39
  background-color: var(--modal-bg, rgba(0, 0, 0, 0.7));
40
- z-index: 2147483000;
40
+ z-index: var(--modal-z, 3000);
41
41
  display: flex;
42
42
  justify-content: center;
43
43
  align-items: center
@@ -1,4 +1,4 @@
1
- <script >import { createEventDispatcher } from 'svelte';
1
+ <script>import { createEventDispatcher } from 'svelte';
2
2
  import { randomid, sleep } from 'txstate-utils';
3
3
  import ScreenReaderOnly from './ScreenReaderOnly.svelte';
4
4
  import DefaultPopupMenu from './PopupMenu.svelte';
@@ -1,4 +1,4 @@
1
- <script >import { createEventDispatcher, onDestroy, tick } from 'svelte';
1
+ <script>import { createEventDispatcher, onDestroy, tick } from 'svelte';
2
2
  import { randomid } from 'txstate-utils';
3
3
  import { Store } from '@txstate-mws/svelte-store';
4
4
  import { glue, portal } from '../actions';
@@ -229,7 +229,7 @@ $: hasSelected = showSelected && items.some(itm => itm.value === value);
229
229
  <style>
230
230
  div {
231
231
  position: absolute !important;
232
- z-index: 2147483647;
232
+ z-index: var(--popup-z, calc(var(--modal-z) + 1));
233
233
  }
234
234
  ul {
235
235
  list-style: none;
@@ -1,4 +1,4 @@
1
- <script >export let id = undefined;
1
+ <script>export let id = undefined;
2
2
  export let arialive = undefined;
3
3
  export let ariaatomic = undefined;
4
4
  </script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@txstate-mws/svelte-components",
3
- "version": "1.2.7",
3
+ "version": "1.2.10",
4
4
  "description": "Svelte components that are generically useful.",
5
5
  "dependencies": {
6
6
  "@txstate-mws/svelte-store": "^1.0.3",
@@ -11,6 +11,7 @@
11
11
  "@playwright/test": "^1.18.1",
12
12
  "@sveltejs/adapter-auto": "next",
13
13
  "@sveltejs/kit": "next",
14
+ "@sveltejs/package": "next",
14
15
  "@types/tabbable": "^3.1.2",
15
16
  "eslint-config-standard-with-typescript": "^21.0.1",
16
17
  "eslint-plugin-svelte3": "^3.2.1",
@@ -8,7 +8,7 @@ export function watchForMutations(cb) {
8
8
  cb();
9
9
  }
10
10
  if (observers.size === 0) {
11
- mutationobserver ?? (mutationobserver = new MutationObserver(watch));
11
+ mutationobserver ??= new MutationObserver(watch);
12
12
  window.addEventListener('resize', watch, { passive: true });
13
13
  mutationobserver.observe(document.body, {
14
14
  subtree: true,