Skip to content

Commit

Permalink
chore(copy): re-expose public typedef
Browse files Browse the repository at this point in the history
  • Loading branch information
vnphanquang committed Jul 9, 2024
1 parent 7c50ad2 commit b0ab530
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/little-penguins-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@svelte-put/copy': patch
---

re-expose public typedef (following https://github.com/Rich-Harris/dts-buddy/pull/82)
17 changes: 9 additions & 8 deletions packages/copy/src/copy.action.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { copyToClipboard } from './copy.helpers.js';
* Copy text to clipboard on `click` event
* @template {keyof HTMLElementEventMap} K
* @param {HTMLElement} node - HTMLElement to register action
* @param {import('./public.js').CopyParameter<K>} parameter - svelte action parameters
* @returns {import('./public.js').CopyReturn<K>}
* @param {import('./types.public').CopyParameter<K>} parameter - svelte action parameters
* @returns {import('./types.public').CopyReturn<K>}
*/
export function copy(node, parameter = {}) {
let { trigger, enabled, text, events, synthetic } = resolveConfig(node, parameter);
Expand All @@ -16,7 +16,7 @@ export function copy(node, parameter = {}) {
async function handler(e) {
const rText = await text({ node, trigger, event: e });
copyToClipboard(rText);
/** @type {import('./public').CopyDetail} */
/** @type {import('./types.public').CopyDetail} */
const detail = { text: rText };
node.dispatchEvent(new CustomEvent('copied', { detail }));
if (synthetic) {
Expand All @@ -38,7 +38,7 @@ export function copy(node, parameter = {}) {
let offs = [];
function addEvents() {
if (trigger) {
offs = events.map((event) => on(trigger, event, handler));
offs = events.map((event) => on(trigger, /** @type {K} */(event), handler));
}
}

Expand Down Expand Up @@ -67,11 +67,11 @@ export function copy(node, parameter = {}) {
* @package
* @template {keyof HTMLElementEventMap} K
* @param {HTMLElement} node
* @param {import('./public').CopyParameter<K>} param
* @param {import('./types.public').CopyParameter<K>} param
* @returns {{
* trigger: HTMLElement;
* enabled: boolean;
* text: import('./public.js').TextResolver<K>;
* text: import('./types.public').TextResolver<K>;
* events: K[] | "click"[];
* synthetic: boolean;
* }}
Expand All @@ -81,13 +81,14 @@ function resolveConfig(node, param = {}) {
const text =
typeof param.text === 'function'
? param.text
: /** @type {import('./public.js').TextResolver<K>} */ (() => param.text ?? node.innerText);
: /** @type {import('./types.public').TextResolver<K>} */ (() => param.text ?? node.innerText);
const events = typeof param.event === 'string' ? [param.event] : param.event ?? ['click'];
return { trigger, enabled, text, events, synthetic };
}

/**
* Deprecated, use `CopyParameter` and `CopyConfig` instead
* @typedef {import('./public').CopyConfig<K>} CopyParameters
* @typedef {import('./types.public').CopyConfig<K>} CopyParameters
* @template {keyof HTMLElementEventMap} K
*/

2 changes: 2 additions & 0 deletions packages/copy/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@

export * from './copy.action.js';
export * from './copy.helpers.js';
export * from './types.public.js';

File renamed without changes.
3 changes: 3 additions & 0 deletions packages/copy/src/types.public.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/** to provide typing only, see types.public.d.ts */
export {};

0 comments on commit b0ab530

Please sign in to comment.