@txstate-mws/svelte-components 1.2.11 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,3 +6,4 @@ export * from './portal.js';
6
6
  export * from './resize.js';
7
7
  export * from './sticky.js';
8
8
  export * from './stickyfixed.js';
9
+ export * from './passactions.js';
package/actions/index.js CHANGED
@@ -6,3 +6,4 @@ export * from './portal.js';
6
6
  export * from './resize.js';
7
7
  export * from './sticky.js';
8
8
  export * from './stickyfixed.js';
9
+ export * from './passactions.js';
@@ -0,0 +1,10 @@
1
+ export interface SvelteActionReturnType<P> {
2
+ update?: (newParams: P) => void;
3
+ destroy?: () => void;
4
+ }
5
+ export declare type SvelteHTMLActionType<P = any> = (node: HTMLElement, params?: P) => SvelteActionReturnType<P> | undefined;
6
+ export declare type HTMLActionEntry<P extends any = any> = SvelteHTMLActionType<P> | [SvelteHTMLActionType<P>, P];
7
+ export declare type SvelteSVGActionType<P = any> = (node: SVGElement, params?: P) => SvelteActionReturnType<P> | undefined;
8
+ export declare type SVGActionEntry<P extends any = any> = SvelteSVGActionType<P> | [SvelteSVGActionType<P>, P];
9
+ export declare function passActions(node: HTMLElement, actions: HTMLActionEntry[]): SvelteActionReturnType<HTMLActionEntry[]>;
10
+ export declare function passActions(node: SVGElement, actions: SVGActionEntry[]): SvelteActionReturnType<SVGActionEntry[]>;
@@ -0,0 +1,36 @@
1
+ import { toArray } from 'txstate-utils';
2
+ export function passActions(node, actions) {
3
+ let actionReturns = new Map();
4
+ for (const actionEntry of actions ?? []) {
5
+ const [action, params] = toArray(actionEntry);
6
+ actionReturns.set(action, action(node, params));
7
+ }
8
+ return {
9
+ update(actions) {
10
+ const newActionReturns = new Map();
11
+ // accept new actions and update actions we already had
12
+ for (const actionEntry of actions ?? []) {
13
+ const [action, params] = toArray(actionEntry);
14
+ if (actionReturns.has(action)) {
15
+ const existing = actionReturns.get(action);
16
+ newActionReturns.set(action, existing);
17
+ existing?.update?.(params);
18
+ }
19
+ else {
20
+ newActionReturns.set(action, action(node, params));
21
+ }
22
+ }
23
+ // destroy any actions that were removed
24
+ for (const [action, actionReturn] of actionReturns.entries()) {
25
+ if (!newActionReturns.has(action))
26
+ actionReturn?.destroy?.();
27
+ }
28
+ actionReturns = newActionReturns;
29
+ },
30
+ destroy() {
31
+ for (const actionReturn of actionReturns.values()) {
32
+ actionReturn?.destroy?.();
33
+ }
34
+ }
35
+ };
36
+ }
@@ -1,13 +1,14 @@
1
1
  <script>export let className = '';
2
2
  import { getContext } from 'svelte';
3
- import { resize } from '../actions';
3
+ import { resize, passActions } from '../actions';
4
4
  import { CARDLAYOUT } from '../types';
5
+ export let use = [];
5
6
  const block = { element: undefined };
6
7
  const { registerBlock, gutter, recalculate } = getContext(CARDLAYOUT);
7
8
  const { width, order, linebreak } = registerBlock(block);
8
9
  </script>
9
10
 
10
- <li class="cardlayout-card {className}" bind:this={block.element} use:resize on:resize={recalculate} style="margin-bottom: {$gutter}px; width: {$width}; order: {$order};">
11
+ <li class="cardlayout-card {className}" bind:this={block.element} use:passActions={use} use:resize on:resize={recalculate} style="margin-bottom: {$gutter}px; width: {$width}; order: {$order};">
11
12
  <slot></slot>
12
13
  </li>
13
14
  {#if $linebreak}
@@ -1,7 +1,9 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
+ import { type HTMLActionEntry } from '../actions';
2
3
  declare const __propDef: {
3
4
  props: {
4
5
  className?: string;
6
+ use?: HTMLActionEntry[];
5
7
  };
6
8
  events: {
7
9
  [evt: string]: CustomEvent<any>;
@@ -1,11 +1,12 @@
1
1
  <script>import { onDestroy, tick, setContext, onMount } from 'svelte';
2
2
  import { writable } from 'svelte/store';
3
- import { resize } from '../actions';
3
+ import { resize, passActions } from '../actions';
4
4
  import { CARDLAYOUT } from '../types';
5
5
  export let maxwidth = 500;
6
6
  export let preserveorder = false;
7
7
  export let gutter = 10;
8
8
  export let className = '';
9
+ export let use = [];
9
10
  const ssr = typeof navigator === 'undefined' || navigator.userAgent.includes('jsdom');
10
11
  const blocks = [];
11
12
  const gutterstore = writable(gutter);
@@ -177,7 +178,7 @@ function onResize(e) {
177
178
  onMount(() => triggerrecalc(layoutelement.clientWidth));
178
179
  </script>
179
180
 
180
- <ul class="cardlayout {className}" class:ssr style:height={ssr ? undefined : `${fullheight + gutter}px`} bind:this={layoutelement} use:resize on:resize={onResize}>
181
+ <ul class="cardlayout {className}" class:ssr style:height={ssr ? undefined : `${fullheight + gutter}px`} bind:this={layoutelement} use:resize on:resize={onResize} use:passActions={use}>
181
182
  <slot></slot>
182
183
  </ul>
183
184
 
@@ -1,10 +1,12 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
+ import { type HTMLActionEntry } from '../actions';
2
3
  declare const __propDef: {
3
4
  props: {
4
5
  maxwidth?: number;
5
6
  preserveorder?: boolean;
6
7
  gutter?: number;
7
8
  className?: string;
9
+ use?: HTMLActionEntry[];
8
10
  };
9
11
  events: {
10
12
  [evt: string]: CustomEvent<any>;
@@ -213,10 +213,10 @@ $: hasSelected = showSelected && items.some(itm => itm.value === value);
213
213
  {/if}
214
214
  {/each}
215
215
  {#if items.length === 0}
216
- <li role="option" class={`${menuItemClass} disabled`} aria-live="assertive">
216
+ <li role="option" class={`${menuItemClass} disabled`} aria-live="assertive" aria-selected={false}>
217
217
  <slot name="noresults">
218
218
  {#if !emptyText}
219
- <span aria-hidden="true">{'¯\\_(ツ)_/¯'}</span><ScreenReaderOnly>{emptyText || 'empty popup menu'}</ScreenReaderOnly>
219
+ <span aria-hidden="true">{'¯\\_(ツ)_/¯'}</span><ScreenReaderOnly>{emptyText || 'no results found'}</ScreenReaderOnly>
220
220
  {:else}
221
221
  {emptyText}
222
222
  {/if}
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@txstate-mws/svelte-components",
3
- "version": "1.2.11",
3
+ "version": "1.3.0",
4
4
  "description": "Svelte components that are generically useful.",
5
5
  "dependencies": {
6
6
  "@txstate-mws/svelte-store": "^1.0.3",
7
7
  "tabbable": "^6.0.0",
8
- "txstate-utils": "^1.6.0"
8
+ "txstate-utils": "^1.7.6"
9
9
  },
10
10
  "devDependencies": {
11
11
  "@playwright/test": "^1.18.1",
@@ -13,7 +13,7 @@
13
13
  "@sveltejs/kit": "next",
14
14
  "@sveltejs/package": "1.0.0-next.3",
15
15
  "@types/tabbable": "^3.1.2",
16
- "eslint-config-standard-with-typescript": "^22.0.0",
16
+ "eslint-config-standard-with-typescript": "^23.0.0",
17
17
  "eslint-plugin-svelte3": "^4.0.0",
18
18
  "svelte": "^3.44.0",
19
19
  "svelte-check": "^2.2.6",
@@ -36,6 +36,7 @@
36
36
  "./actions/glue": "./actions/glue.js",
37
37
  "./actions": "./actions/index.js",
38
38
  "./actions/offset": "./actions/offset.js",
39
+ "./actions/passactions": "./actions/passactions.js",
39
40
  "./actions/portal": "./actions/portal.js",
40
41
  "./actions/resize": "./actions/resize.js",
41
42
  "./actions/sticky": "./actions/sticky.js",