@freedam/picker 0.0.0-stage → 1.2.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.
@@ -0,0 +1,80 @@
1
+ import { P as PickerSelectMode, R as RuleTree, S as SortField, a as SortDirection, b as PickerAssetType, c as PickerLocale, d as PickerTheme, e as PickerMode, f as PickerAsset, F as FreedamPickerError } from './element-D6ex-aQ4.js';
2
+ export { E as ERROR_MESSAGES, g as FreedamPickerElement, h as FreedamPickerEventMap, H as HostCloseMessage, i as HostToPickerMessage, I as INLINE_MIN_HEIGHT, M as MAX_SELECTION, j as PICKER_ASSET_TYPES, k as PICKER_LOCALES, l as PICKER_MODES, m as PICKER_THEMES, n as PROTOCOL_VERSION, o as PickerCancelMessage, p as PickerDocument, q as PickerDocumentChoice, r as PickerDocumentFile, s as PickerDocumentForm, t as PickerErrorCode, u as PickerErrorMessage, v as PickerFileFormat, w as PickerFocusPoint, x as PickerFormat, y as PickerFrameMode, z as PickerImage, A as PickerImageChoice, B as PickerMessageBase, C as PickerMetadata, D as PickerMetadataValue, G as PickerOpenQuery, J as PickerReadyMessage, K as PickerResizeMessage, L as PickerSdkErrorCode, N as PickerSelectMessage, O as PickerServerErrorCode, Q as PickerSignInMessage, T as PickerSubtitle, U as PickerToHostMessage, V as PickerVideo, W as PickerVideoChoice, X as RuleFilter, Y as RuleGroup, Z as SDK_ERROR_CODES, _ as SERVER_ERROR_CODES, $ as SORT_DIRECTIONS, a0 as SORT_FIELDS } from './element-D6ex-aQ4.js';
3
+
4
+ interface PickerOptions {
5
+ /** Host of the Freedam workspace, without scheme or path: `acme.example.com`. HTTPS is always used. */
6
+ workspace: string;
7
+ /** Public key of the integration, shown in the workspace's integration settings. */
8
+ integration: string;
9
+ /**
10
+ * Key of the integration's access without a Freedam account (`fdpk_…`),
11
+ * shown in the integration's settings when the access is on. With it,
12
+ * visitors without an account can browse and insert the integration's
13
+ * assets. Not a secret.
14
+ */
15
+ publicKey?: string;
16
+ /** Default `single`. */
17
+ select?: PickerSelectMode;
18
+ /** Most assets the person can choose, 1 to 50, with `select: 'multiple'`. */
19
+ max?: number;
20
+ /** Initial search text, 500 characters at most. */
21
+ q?: string;
22
+ /** Initial filters, applied on top of the integration's own rules. */
23
+ filters?: RuleTree;
24
+ sort?: {
25
+ by: SortField;
26
+ direction?: SortDirection;
27
+ };
28
+ /** GAIDs selected when the picker opens; GAIDs the person cannot see are ignored. */
29
+ preselected?: string[];
30
+ /**
31
+ * Asset types the picker offers, among the integration's own: `['image']`
32
+ * for an image field. A type the integration does not offer is ignored.
33
+ * Default: every type of the integration.
34
+ */
35
+ types?: PickerAssetType[];
36
+ /** Interface language; default: the person's own setting. */
37
+ locale?: PickerLocale;
38
+ theme?: PickerTheme;
39
+ /**
40
+ * Default `popup`: a window on the workspace host. `tab` opens it in a
41
+ * new tab of the browser instead. `modal` shows the picker in an iframe
42
+ * over the page (full screen below 640 pixels wide); `inline` shows it
43
+ * in an iframe inside `container`. When the browser does not let the
44
+ * iframe sign in, the SDK offers to continue in a window.
45
+ */
46
+ mode?: PickerMode;
47
+ /** Element that receives the picker's iframe, required with `mode: 'inline'` and only then. */
48
+ container?: HTMLElement;
49
+ onReady?: () => void;
50
+ onSelect?: (assets: PickerAsset[]) => void;
51
+ onCancel?: () => void;
52
+ onError?: (error: FreedamPickerError) => void;
53
+ onClose?: () => void;
54
+ }
55
+
56
+ type PickerResult = PickerAsset[] | null;
57
+ /**
58
+ * Opens the picker and resolves with the inserted assets, or with `null`
59
+ * when the person cancels or closes it.
60
+ *
61
+ * Call it from a click handler, with no `await` before it: browsers block
62
+ * windows opened outside a user gesture. Invalid options reject with
63
+ * `invalid_options` before anything opens. While a picker of this page is
64
+ * open, another call brings it to the front and returns the same promise.
65
+ *
66
+ * In the `popup` and `tab` modes the picker runs in a window of its own,
67
+ * a popup or a new tab of the browser.
68
+ *
69
+ * In the `modal` and `inline` modes the picker runs in an iframe. When the
70
+ * iframe cannot sign in (`auth_required`) or the picker page sends nothing
71
+ * within READY_TIMEOUT_MS, the iframe gives way to an "Open Freedam"
72
+ * button that opens the picker in a window with the same options; the
73
+ * promise then settles with the outcome of that window.
74
+ */
75
+ declare function open(options: PickerOptions): Promise<PickerResult>;
76
+
77
+ /** Version of this SDK, equal to `version` in package.json (checked by tests/version.test.ts). */
78
+ declare const VERSION = "1.2.0";
79
+
80
+ export { FreedamPickerError, PickerAsset, PickerAssetType, PickerLocale, PickerMode, type PickerOptions, PickerSelectMode, PickerTheme, RuleTree, SortDirection, SortField, VERSION, open };
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ import{a as e,b as r,c as o,d as i,e as c,f as t,g as P,h as k,i as s,j as E,k as a,l as S,m as R,n as m}from"./chunk-SF2R2FAB.js";var p="1.2.0";export{o as ERROR_MESSAGES,i as FreedamPickerError,k as INLINE_MIN_HEIGHT,t as MAX_SELECTION,s as PICKER_ASSET_TYPES,E as PICKER_LOCALES,P as PICKER_MODES,a as PICKER_THEMES,c as PROTOCOL_VERSION,r as SDK_ERROR_CODES,e as SERVER_ERROR_CODES,R as SORT_DIRECTIONS,S as SORT_FIELDS,p as VERSION,m as open};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/version.ts"],"sourcesContent":["/** Version of this SDK, equal to `version` in package.json (checked by tests/version.test.ts). */\nexport const VERSION = '1.2.0';\n"],"mappings":"mIACO,IAAMA,EAAU","names":["VERSION"]}
@@ -0,0 +1 @@
1
+ "use strict";(()=>{var pe=["origin_denied","feature_unavailable","integration_suspended","integration_unavailable","insert_failed","auth_required","guest_access_unavailable"];var W={origin_denied:"This page is not allowed to open the picker: the integration does not exist or does not list this origin.",feature_unavailable:"The asset picker is not available on this workspace.",integration_suspended:"This integration is suspended.",integration_unavailable:"This integration cannot be used: its profile or publication channel is missing or disabled.",insert_failed:"The selected assets could not be inserted.",auth_required:"The picker cannot run in an iframe of this page: the person continues in a separate window.",guest_access_unavailable:"This integration does not allow access without an account.",popup_blocked:"The browser blocked the picker window. Call open() from a click handler.",invalid_options:"Invalid picker options."},B=["insert_failed","guest_access_unavailable"];function q(e){return pe.includes(e)}var m=class extends Error{constructor(t,r){super(r===void 0?W[t]:`${W[t]} ${r}`),this.name="FreedamPickerError",this.code=t}};var M="freedam-picker",j="/picker/";var G=["popup","modal","inline","tab"];var F=["image","video","document"],X=["single","multiple"],R=["en","fr","de","es","pt-BR","zh-CN"],Y=["light","dark","auto"],I=["created_at","updated_at","title","original_filename","size","relevance"],J=["asc","desc"];var me=["onReady","onSelect","onCancel","onError","onClose"],ge=/^fdpk_[A-Za-z0-9]{32}$/,Ee=/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)*(?::\d{1,5})?$/i;function a(e){return new m("invalid_options",e)}function x(e,t){return e.includes(t)}function N(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function ke(e){return typeof HTMLElement<"u"&&e instanceof HTMLElement}function te(e){if(!N(e))throw a("open() expects an options object.");if(typeof e.workspace!="string"||!Ee.test(e.workspace)||!ye(e.workspace))throw a('`workspace` must be the host of the workspace, without scheme or path, e.g. "acme.example.com".');if(typeof e.integration!="string"||!/^\S+$/.test(e.integration))throw a("`integration` must be the key of the integration, without spaces.");if(e.publicKey!==void 0&&(typeof e.publicKey!="string"||!ge.test(e.publicKey)))throw a('`publicKey` must be the key of the access without an account: "fdpk_" followed by 32 letters and digits.');if(e.select!==void 0&&!x(X,e.select))throw a('`select` must be "single" or "multiple".');if(e.max!==void 0){if(e.select!=="multiple")throw a('`max` requires `select: "multiple"`.');if(typeof e.max!="number"||!Number.isInteger(e.max)||e.max<1||e.max>50)throw a(`\`max\` must be an integer from 1 to ${50}.`)}if(e.q!==void 0&&(typeof e.q!="string"||e.q.length>500))throw a(`\`q\` must be a string of ${500} characters at most.`);if(e.filters!==void 0){if(!N(e.filters))throw a("`filters` must be a filter or group object.");try{JSON.stringify(e.filters)}catch{throw a("`filters` must be serializable to JSON.")}}if(e.sort!==void 0){if(!N(e.sort)||!x(I,e.sort.by))throw a(`\`sort.by\` must be one of ${I.join(", ")}.`);if(e.sort.direction!==void 0&&!x(J,e.sort.direction))throw a('`sort.direction` must be "asc" or "desc".')}if(e.preselected!==void 0){let t=e.preselected;if(!Array.isArray(t)||!t.every(r=>typeof r=="string"&&r!==""&&!r.includes(",")))throw a("`preselected` must be an array of GAIDs.")}if(e.types!==void 0){let t=e.types;if(!Array.isArray(t)||t.length===0||!t.every(r=>x(F,r)))throw a(`\`types\` must be a non-empty array of ${F.join(", ")}.`)}if(e.locale!==void 0&&!x(R,e.locale))throw a(`\`locale\` must be one of ${R.join(", ")}.`);if(e.theme!==void 0&&!x(Y,e.theme))throw a('`theme` must be "light", "dark" or "auto".');if(e.mode!==void 0&&!x(G,e.mode))throw a('`mode` must be "popup", "tab", "modal" or "inline".');if(e.mode==="inline"){if(!ke(e.container)||!e.container.isConnected)throw a('`mode: "inline"` requires `container`, an element of the page.')}else if(e.container!==void 0)throw a('`container` requires `mode: "inline"`.');for(let t of me)if(e[t]!==void 0&&typeof e[t]!="function")throw a(`\`${t}\` must be a function.`)}function ye(e){try{return v(e),!0}catch{return!1}}function v(e){return new URL(`https://${e}`).origin}function re(e){if(!/^https?:\/\//.test(e))throw a("The host page must be served over HTTP or HTTPS.");return e}function ne(){let e=new Uint8Array(16);crypto.getRandomValues(e);let t="";for(let r of e)t+=String.fromCharCode(r);return btoa(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function D(e,t,r,l=e.mode??"popup"){let s=new URL(`${j}${encodeURIComponent(e.integration)}`,v(e.workspace)),n=s.searchParams;n.set("protocol",String(1)),n.set("origin",t),n.set("channel",r),n.set("mode",l),n.set("select",e.select??"single"),e.max!==void 0&&n.set("max",String(e.max)),e.publicKey!==void 0&&n.set("public_key",e.publicKey),e.q!==void 0&&e.q!==""&&n.set("q",e.q),e.filters!==void 0&&n.set("filters",JSON.stringify(e.filters)),e.sort!==void 0&&(n.set("sort_by",e.sort.by),e.sort.direction!==void 0&&n.set("sort_direction",e.sort.direction)),e.preselected!==void 0&&e.preselected.length>0&&n.set("preselected",e.preselected.join(",")),e.types!==void 0&&n.set("types",[...new Set(e.types)].join(",")),e.locale!==void 0&&n.set("locale",e.locale),e.theme!==void 0&&n.set("theme",e.theme);let i=s.toString();if(i.length>6e3)throw a(`The picker URL would exceed ${6e3} characters: shorten \`filters\`, \`q\` or \`preselected\`.`);return i}var Pe=1100,be=760,xe=1e4,we="2147483000",Se={en:{message:"Freedam cannot be shown in this page. Continue in a separate window.",open:"Open Freedam",cancel:"Cancel",close:"Close"},fr:{message:"Freedam ne peut pas s\u2019afficher dans cette page. Continuez dans une fen\xEAtre s\xE9par\xE9e.",open:"Ouvrir Freedam",cancel:"Annuler",close:"Fermer"},de:{message:"Freedam kann auf dieser Seite nicht angezeigt werden. Fahren Sie in einem separaten Fenster fort.",open:"Freedam \xF6ffnen",cancel:"Abbrechen",close:"Schlie\xDFen"},es:{message:"Freedam no se puede mostrar en esta p\xE1gina. Contin\xFAe en una ventana aparte.",open:"Abrir Freedam",cancel:"Cancelar",close:"Cerrar"},"pt-BR":{message:"O Freedam n\xE3o pode ser exibido nesta p\xE1gina. Continue em uma janela separada.",open:"Abrir o Freedam",cancel:"Cancelar",close:"Fechar"},"zh-CN":{message:"\u65E0\u6CD5\u5728\u6B64\u9875\u9762\u4E2D\u663E\u793A Freedam\u3002\u8BF7\u5728\u5355\u72EC\u7684\u7A97\u53E3\u4E2D\u7EE7\u7EED\u3002",open:"\u6253\u5F00 Freedam",cancel:"\u53D6\u6D88",close:"\u5173\u95ED"}};function Te(e){let t=[e,document.documentElement.lang,typeof navigator>"u"?void 0:navigator.language];for(let r of t){if(typeof r!="string"||r==="")continue;let l=R.find(i=>i.toLowerCase()===r.toLowerCase());if(l!==void 0)return l;let s=r.split("-")[0].toLowerCase(),n=R.find(i=>i.split("-")[0]===s);if(n!==void 0)return n}return"en"}function h(e,t={}){let r=document.createElement(e);return Object.assign(r.style,t),r}function ie(e,t){let r=h("button",{font:"inherit",fontWeight:"600",padding:"10px 18px",borderRadius:"8px",cursor:"pointer",border:t?"1px solid #111827":"1px solid #d1d5db",background:t?"#111827":"#ffffff",color:t?"#ffffff":"#111827"});return r.type="button",r.textContent=e,r}function oe(e){let t=Se[Te(e.locale)],r=document.activeElement instanceof HTMLElement?document.activeElement:null,l=[],s=!1,n=h("iframe",{display:"block",width:"100%",height:"100%",border:"0",background:"#ffffff"});n.src=e.url,n.name=`freedam-picker-${e.channel}`,n.title="Freedam",n.setAttribute("data-freedam-picker",e.mode);let i,c;if(e.mode==="modal"){i=h("div",{position:"fixed",top:"0",right:"0",bottom:"0",left:"0",zIndex:we,display:"flex",alignItems:"center",justifyContent:"center",boxSizing:"border-box",background:"rgba(17, 24, 39, 0.6)"}),i.setAttribute("role","dialog"),i.setAttribute("aria-modal","true"),i.setAttribute("aria-label","Freedam"),i.setAttribute("data-freedam-picker-overlay",""),c=h("div",{position:"relative",width:"100%",height:"100%",overflow:"hidden",background:"#ffffff",boxShadow:"0 24px 48px rgba(0, 0, 0, 0.3)"});let d=h("button",{position:"absolute",top:"6px",right:"8px",width:"32px",height:"32px",padding:"0",border:"0",borderRadius:"16px",background:"transparent",color:"#ffffff",fontSize:"24px",lineHeight:"32px",cursor:"pointer"});d.type="button",d.textContent="\xD7",d.setAttribute("aria-label",t.close),d.setAttribute("data-freedam-picker-close",""),d.addEventListener("click",()=>e.onDismiss()),i.append(c,d);let o=typeof window.matchMedia=="function"?window.matchMedia(`(max-width: ${640-.02}px)`):null,p=()=>{let f=o?.matches===!0;Object.assign(i.style,{padding:f?"44px 0 0":"48px 24px 24px"}),Object.assign(c.style,{maxWidth:f?"none":`${Pe}px`,maxHeight:f?"none":`${be}px`,borderRadius:f?"0":"12px"})};p(),o!==null&&(o.addEventListener("change",p),l.push(()=>o.removeEventListener("change",p)));let u=f=>{if(f.key==="Escape"){e.onDismiss();return}if(f.key!=="Tab")return;let S=Array.from(i.querySelectorAll("button, iframe")),k=S[0],T=S[S.length-1],_=document.activeElement;k===void 0||T===void 0||(!(_ instanceof Node)||!i.contains(_)?(f.preventDefault(),k.focus()):f.shiftKey&&_===k?(f.preventDefault(),T.focus()):!f.shiftKey&&_===T&&(f.preventDefault(),k.focus()))};document.addEventListener("keydown",u),l.push(()=>document.removeEventListener("keydown",u));let E=document.documentElement,O=E.style.overflow;E.style.overflow="hidden",l.push(()=>{E.style.overflow=O}),c.append(n),document.body.append(i)}else i=h("div",{display:"block",width:"100%",height:"100%",minHeight:`${480}px`}),i.setAttribute("data-freedam-picker-inline",""),c=i,n.style.minHeight=`${480}px`,c.append(n),e.container.append(i);e.mode==="modal"&&n.focus();let b=()=>c.querySelector("[data-freedam-picker-open]");return{mode:e.mode,target:()=>n.isConnected?n.contentWindow:null,isClosed:()=>s||!i.isConnected,focus:()=>(b()??n).focus(),close:(d=!0)=>{if(s)return;s=!0;let o=n.isConnected?n.contentWindow:null;if(o!==null){let p={source:M,protocol:1,channel:e.channel,type:"close"};o.postMessage(p,e.origin)}i.remove();for(let p of l)p();d&&e.mode==="modal"&&r!==null&&r.isConnected&&r.focus()},showFallback:()=>{if(s||b()!==null)return;let d=h("div",{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:"16px",boxSizing:"border-box",width:"100%",height:"100%",minHeight:e.mode==="inline"?`${480}px`:"0",padding:"24px",background:"#ffffff",color:"#111827",fontFamily:'system-ui, -apple-system, "Segoe UI", Roboto, sans-serif',fontSize:"15px",lineHeight:"1.5",textAlign:"center"});d.setAttribute("data-freedam-picker-fallback","");let o=h("p",{margin:"0",maxWidth:"420px"});o.textContent=t.message;let p=h("div",{display:"flex",flexWrap:"wrap",justifyContent:"center",gap:"8px"}),u=ie(t.open,!0);u.setAttribute("data-freedam-picker-open",""),u.addEventListener("click",()=>e.onOpenWindow());let E=ie(t.cancel,!1);E.setAttribute("data-freedam-picker-cancel",""),E.addEventListener("click",()=>e.onDismiss()),p.append(u,E),d.append(o,p),n.remove(),c.append(d),e.mode==="modal"&&u.focus()},resize:d=>{e.mode!=="inline"||!Number.isFinite(d)||(n.style.height=`${Math.round(Math.min(xe,Math.max(480,d)))}px`,i.style.height="auto")}}}function K(e,t){let r=Math.min(1100,window.screen.availWidth||1100),l=Math.min(760,window.screen.availHeight||760),s=Math.round(window.screenX+(window.outerWidth-r)/2),n=Math.round(window.screenY+(window.outerHeight-l)/2);return ae(window.open(e,`freedam-picker-${t}`,`popup=yes,width=${r},height=${l},left=${s},top=${n}`))}function se(e,t){return ae(window.open(e,`freedam-picker-${t}`))}function ae(e){return e?{target:()=>e,isClosed:()=>e.closed,focus:()=>e.focus(),close:()=>e.close()}:null}var _e=500,Re=1e3,Ce=15e3,w=null;function Oe(){return navigator.userActivation?.isActive===!0}function P(e,...t){if(typeof e=="function")try{e(...t)}catch(r){setTimeout(()=>{throw r})}}function Me(e,t){if(typeof e!="object"||e===null)return!1;let r=e;return r.source===M&&r.protocol===1&&r.channel===t&&typeof r.type=="string"}function A(e){if(w!==null&&!w.surface().isClosed())return w.surface().focus(),w.promise;let t,r,l,s;try{te(e),l=v(e.workspace),s=ne();let o=re(window.location.origin);t=D(e,o,s),r=D(e,o,s,"popup")}catch(o){if(!(o instanceof m))throw o;return P(e?.onError,o),Promise.reject(o)}let n=e.mode??"popup",i,c=null,b={dismiss:()=>{},openWindow:()=>{}};if(n==="popup"||n==="tab"){let o=n==="tab"?se(t,s):K(t,s);if(o===null){let p=new m("popup_blocked");return P(e.onError,p),Promise.reject(p)}i=o}else c=oe({url:t,channel:s,origin:l,mode:n,container:e.container,locale:e.locale,onDismiss:()=>b.dismiss(),onOpenWindow:()=>b.openWindow()}),i=c;let d=new Promise((o,p)=>{let u=!1,E=!1,O,f,S=()=>{if(c!==null){c.close(),k();return}O=setTimeout(()=>{i.isClosed()||i.close()},Re)},k=()=>{i.isClosed()&&(c?.close(),clearInterval(fe),clearTimeout(O),clearTimeout(f),window.removeEventListener("message",U),w?.promise===d&&(w=null),u||(u=!0,P(e.onCancel),o(null)),P(e.onClose))},T=()=>{if(c===null||u)return!1;let y=K(r,s);return y===null?!1:(clearTimeout(f),c.close(!1),c=null,i=y,!0)};b.dismiss=()=>{i.close(),k()},b.openWindow=()=>{if(!T()&&!u){u=!0;let y=new m("popup_blocked");P(e.onError,y),p(y),i.close(),k()}};let _=()=>{Oe()&&T()||c?.showFallback()},U=y=>{if(u||y.origin!==l||y.source!==i.target())return;let g=y.data;if(Me(g,s))switch(clearTimeout(f),g.type){case"ready":E||(E=!0,P(e.onReady));break;case"resize":typeof g.height=="number"&&c?.resize(g.height);break;case"select":if(!Array.isArray(g.assets))return;u=!0,P(e.onSelect,g.assets),o(g.assets),S();break;case"cancel":u=!0,P(e.onCancel),o(null),S();break;case"error":{if(!q(g.code))return;if(g.code==="auth_required"){_();return}let z=new m(g.code);P(e.onError,z),B.includes(g.code)||(u=!0,p(z));break}}},fe=setInterval(k,_e);c!==null&&(f=setTimeout(()=>{u||c?.showFallback()},Ce)),window.addEventListener("message",U)});return w={surface:()=>i,promise:d},d}var ce="freedam-picker",ve="[data-freedam-picker-inline], [data-freedam-picker-overlay]",Le=typeof HTMLElement>"u"?class{}:HTMLElement,$=class extends Le{constructor(){super(),this.addEventListener("click",t=>{t.target instanceof Element&&t.target.closest(ve)!==null||this.open().catch(()=>{})})}get filters(){return this.filtersValue}set filters(t){this.filtersValue=t}get preselected(){return this.preselectedValue}set preselected(t){this.preselectedValue=t}get container(){return this.containerValue}set container(t){this.containerValue=t}open(){let t;try{t=this.options()}catch(r){return r instanceof m&&this.emit("freedam-error",{error:r}),Promise.reject(r)}return A(t)}options(){let t=i=>this.getAttribute(i)??void 0,r=t("max"),l=t("sort-by"),s=t("sort-direction"),n=t("container");return{workspace:t("workspace"),integration:t("integration"),publicKey:t("public-key"),select:t("select"),max:r===void 0?void 0:Number(r),q:t("q"),filters:this.filtersValue??Ae(t("filters")),sort:l===void 0&&s===void 0?void 0:{by:l,direction:s},preselected:this.preselectedValue??le(t("preselected")),types:He(le(t("types"))),locale:t("locale"),theme:t("theme"),mode:t("mode"),container:this.containerValue??(n===void 0?void 0:document.getElementById(n)??void 0),onReady:()=>this.emit("freedam-ready",{}),onSelect:i=>this.emit("freedam-select",{assets:i}),onCancel:()=>this.emit("freedam-cancel",{}),onError:i=>this.emit("freedam-error",{error:i}),onClose:()=>this.emit("freedam-close",{})}}emit(t,r){this.dispatchEvent(new CustomEvent(t,{detail:r,bubbles:!0,composed:!0}))}};function Ae(e){if(e!==void 0)try{return JSON.parse(e)}catch{throw new m("invalid_options","The `filters` attribute must be JSON.")}}function le(e){return e?.split(",").map(t=>t.trim()).filter(t=>t!=="")}function He(e){return e===void 0||e.length===0?void 0:e}function V(){typeof customElements<"u"&&customElements.get(ce)===void 0&&customElements.define(ce,$)}V();var de="1.2.0";var ue=window,H=ue.Freedam,Fe=typeof H=="object"&&H!==null||typeof H=="function"?H:ue.Freedam={};Fe.picker={open:A,FreedamPickerError:m,VERSION:de};V();})();
package/package.json CHANGED
@@ -1,6 +1,70 @@
1
1
  {
2
- "name": "@freedam/picker",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@freedam/picker",
3
+ "version": "1.2.0",
4
+ "description": "Embeddable asset picker for Freedam workspaces: let people choose assets from Freedam inside your own application",
5
+ "homepage": "https://freedam.io/docs/api-picker-reference",
6
+ "bugs": {
7
+ "url": "https://freedam.io/docs/api-picker-reference",
8
+ "email": "hello@freedam.io"
9
+ },
10
+ "type": "module",
11
+ "main": "./dist/index.cjs",
12
+ "module": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
14
+ "sideEffects": [
15
+ "./dist/element.js",
16
+ "./dist/picker.global.js"
17
+ ],
18
+ "exports": {
19
+ ".": {
20
+ "import": {
21
+ "types": "./dist/index.d.ts",
22
+ "default": "./dist/index.js"
23
+ },
24
+ "require": {
25
+ "types": "./dist/index.d.cts",
26
+ "default": "./dist/index.cjs"
27
+ }
28
+ },
29
+ "./element": {
30
+ "types": "./dist/element.d.ts",
31
+ "default": "./dist/element.js"
32
+ },
33
+ "./schema.json": "./schema/payload.schema.json"
34
+ },
35
+ "files": [
36
+ "dist",
37
+ "schema",
38
+ "README.md",
39
+ "CHANGELOG.md"
40
+ ],
41
+ "publishConfig": {
42
+ "access": "public"
43
+ },
44
+ "engines": {
45
+ "node": ">=18"
46
+ },
47
+ "scripts": {
48
+ "build": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\" && tsup",
49
+ "test": "vitest run",
50
+ "typecheck": "tsc --noEmit",
51
+ "size": "node scripts/check-size.mjs",
52
+ "verify": "node scripts/verify-global-build.mjs",
53
+ "publish:cdn": "node scripts/publish-cdn.mjs",
54
+ "prepublishOnly": "npm run typecheck && npm run test && npm run build && npm run size && npm run verify"
55
+ },
56
+ "keywords": [
57
+ "freedam",
58
+ "dam",
59
+ "digital-asset-management",
60
+ "asset-picker",
61
+ "media-picker"
62
+ ],
63
+ "license": "MIT",
64
+ "devDependencies": {
65
+ "jsdom": "^26.1.0",
66
+ "tsup": "^8.4.0",
67
+ "typescript": "^5.7.3",
68
+ "vitest": "^3.0.0"
69
+ }
70
+ }
@@ -0,0 +1,316 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "title": "Freedam Picker asset",
4
+ "description": "One asset inserted from the Freedam Picker, as the picker sends it to the host page in a `select` message. Keys are snake_case, like the Freedam API.",
5
+ "oneOf": [
6
+ { "$ref": "#/$defs/image" },
7
+ { "$ref": "#/$defs/video" },
8
+ { "$ref": "#/$defs/document" }
9
+ ],
10
+ "$defs": {
11
+ "url": {
12
+ "type": "string",
13
+ "minLength": 1
14
+ },
15
+ "nullable_text": {
16
+ "type": ["string", "null"]
17
+ },
18
+ "dimension": {
19
+ "description": "Size of the original file, in pixels; null when unknown, e.g. for a document without dimensions.",
20
+ "type": ["integer", "null"],
21
+ "minimum": 1
22
+ },
23
+ "url_template": {
24
+ "description": "Signed URL of the asset's image (the image itself, a video's poster, a document's first page) with the literal text {options} where the URL options go.",
25
+ "type": "string",
26
+ "pattern": "\\{options\\}"
27
+ },
28
+ "widths": {
29
+ "description": "Widths the url_template serves with w=, in pixels, smallest first: the channel's width tiers up to the original's width. The smallest tier when the original is narrower than it; every tier when the original's width is unknown. A width above the channel maximum answers 400.",
30
+ "type": "array",
31
+ "items": { "type": "integer", "minimum": 1 },
32
+ "uniqueItems": true
33
+ },
34
+ "format": {
35
+ "description": "A named format of the publication channel, offered by the integration's profile.",
36
+ "type": "object",
37
+ "required": ["name", "ratio", "url"],
38
+ "properties": {
39
+ "name": { "description": "Name used in URL options (fmt=hero).", "type": "string", "minLength": 1 },
40
+ "ratio": { "description": "Width to height, e.g. 16:9.", "type": "string" },
41
+ "url": { "$ref": "#/$defs/url" }
42
+ },
43
+ "additionalProperties": false
44
+ },
45
+ "formats": {
46
+ "type": "array",
47
+ "items": { "$ref": "#/$defs/format" }
48
+ },
49
+ "focus_point": {
50
+ "description": "Position from the top-left corner, in percent; null when the asset has none.",
51
+ "type": ["object", "null"],
52
+ "required": ["x", "y"],
53
+ "properties": {
54
+ "x": { "type": "number", "minimum": 0, "maximum": 100 },
55
+ "y": { "type": "number", "minimum": 0, "maximum": 100 }
56
+ },
57
+ "additionalProperties": false
58
+ },
59
+ "metadata_value": {
60
+ "description": "A value as the Freedam API returns it: a list for several values, a map of language code to text for a multilingual field, a YYYY-MM-DD string for a date.",
61
+ "type": ["string", "number", "boolean", "null", "array", "object"],
62
+ "items": { "type": ["string", "number", "boolean"] },
63
+ "additionalProperties": { "type": "string" }
64
+ },
65
+ "metadata": {
66
+ "description": "Fields the integration's profile exposes. An exposed field is always present, null when empty or hidden from the person who inserted the asset.",
67
+ "type": "object",
68
+ "properties": {
69
+ "title": { "$ref": "#/$defs/nullable_text" },
70
+ "description": { "$ref": "#/$defs/nullable_text" },
71
+ "alt": { "$ref": "#/$defs/nullable_text" },
72
+ "credit": { "$ref": "#/$defs/nullable_text" },
73
+ "copyright": { "$ref": "#/$defs/nullable_text" },
74
+ "keywords": {
75
+ "type": ["array", "null"],
76
+ "items": { "type": "string" }
77
+ },
78
+ "custom": {
79
+ "description": "Workspace metadata fields, by field key. Dates are YYYY-MM-DD.",
80
+ "type": "object",
81
+ "additionalProperties": { "$ref": "#/$defs/metadata_value" }
82
+ }
83
+ },
84
+ "additionalProperties": false
85
+ },
86
+ "image_choice": {
87
+ "type": "object",
88
+ "required": ["format", "file_format"],
89
+ "properties": {
90
+ "format": {
91
+ "description": "Format name, or null for the original ratio.",
92
+ "type": ["string", "null"]
93
+ },
94
+ "file_format": {
95
+ "description": "Image file format, or null to let the browser negotiate it.",
96
+ "enum": ["avif", "webp", "jpeg", null]
97
+ }
98
+ },
99
+ "additionalProperties": false
100
+ },
101
+ "subtitle": {
102
+ "type": "object",
103
+ "required": ["language", "label", "url", "is_default"],
104
+ "properties": {
105
+ "language": { "type": "string", "minLength": 1 },
106
+ "label": { "type": "string" },
107
+ "url": { "$ref": "#/$defs/url" },
108
+ "is_default": { "type": "boolean" }
109
+ },
110
+ "additionalProperties": false
111
+ },
112
+ "video_choice": {
113
+ "type": "object",
114
+ "required": ["autoplay", "muted", "loop", "controls", "start", "subtitle_language"],
115
+ "properties": {
116
+ "autoplay": { "type": "boolean" },
117
+ "muted": { "description": "Always true when autoplay is true.", "type": "boolean" },
118
+ "loop": { "type": "boolean" },
119
+ "controls": { "type": "boolean" },
120
+ "start": { "description": "Start position, in seconds.", "type": "number", "minimum": 0 },
121
+ "subtitle_language": {
122
+ "description": "Subtitles shown when playback starts: null for the video's default track, \"off\" for none, otherwise the language code of one of `subtitles`.",
123
+ "type": ["string", "null"],
124
+ "minLength": 1
125
+ }
126
+ },
127
+ "additionalProperties": false
128
+ },
129
+ "document_choice": {
130
+ "type": "object",
131
+ "required": ["form", "file"],
132
+ "properties": {
133
+ "form": {
134
+ "description": "What the host inserts: a link to url, the preview_url image linked to url, or embed_html.",
135
+ "enum": ["link", "thumbnail", "viewer"]
136
+ },
137
+ "file": {
138
+ "description": "Which file url delivers.",
139
+ "enum": ["original", "pdf"]
140
+ }
141
+ },
142
+ "additionalProperties": false
143
+ },
144
+ "image": {
145
+ "type": "object",
146
+ "required": [
147
+ "gaid",
148
+ "version",
149
+ "type",
150
+ "mime_type",
151
+ "file_size",
152
+ "width",
153
+ "height",
154
+ "url",
155
+ "url_template",
156
+ "widths",
157
+ "formats",
158
+ "focus_point",
159
+ "thumbnail_url",
160
+ "metadata",
161
+ "usage_id",
162
+ "usage_token",
163
+ "choice"
164
+ ],
165
+ "properties": {
166
+ "gaid": { "type": "string", "minLength": 1 },
167
+ "version": { "type": "integer", "minimum": 1 },
168
+ "type": { "const": "image" },
169
+ "mime_type": { "type": "string", "minLength": 1 },
170
+ "file_size": { "type": "integer", "minimum": 0 },
171
+ "width": { "$ref": "#/$defs/dimension" },
172
+ "height": { "$ref": "#/$defs/dimension" },
173
+ "url": { "$ref": "#/$defs/url" },
174
+ "url_template": { "$ref": "#/$defs/url_template" },
175
+ "widths": { "$ref": "#/$defs/widths" },
176
+ "formats": { "$ref": "#/$defs/formats" },
177
+ "focus_point": { "$ref": "#/$defs/focus_point" },
178
+ "thumbnail_url": { "$ref": "#/$defs/url" },
179
+ "metadata": { "$ref": "#/$defs/metadata" },
180
+ "usage_id": { "type": "string", "minLength": 1 },
181
+ "usage_token": { "type": "string", "minLength": 1 },
182
+ "choice": { "$ref": "#/$defs/image_choice" }
183
+ },
184
+ "additionalProperties": false
185
+ },
186
+ "video": {
187
+ "type": "object",
188
+ "required": [
189
+ "gaid",
190
+ "version",
191
+ "type",
192
+ "mime_type",
193
+ "file_size",
194
+ "width",
195
+ "height",
196
+ "url",
197
+ "url_template",
198
+ "widths",
199
+ "formats",
200
+ "focus_point",
201
+ "thumbnail_url",
202
+ "metadata",
203
+ "usage_id",
204
+ "usage_token",
205
+ "player_url",
206
+ "embed_html",
207
+ "stream_url",
208
+ "poster_url",
209
+ "duration",
210
+ "subtitles",
211
+ "choice"
212
+ ],
213
+ "properties": {
214
+ "gaid": { "type": "string", "minLength": 1 },
215
+ "version": { "type": "integer", "minimum": 1 },
216
+ "type": { "const": "video" },
217
+ "mime_type": { "type": "string", "minLength": 1 },
218
+ "file_size": { "type": "integer", "minimum": 0 },
219
+ "width": { "$ref": "#/$defs/dimension" },
220
+ "height": { "$ref": "#/$defs/dimension" },
221
+ "url": { "description": "Equal to player_url.", "$ref": "#/$defs/url" },
222
+ "url_template": { "$ref": "#/$defs/url_template" },
223
+ "widths": { "$ref": "#/$defs/widths" },
224
+ "formats": { "$ref": "#/$defs/formats" },
225
+ "focus_point": { "$ref": "#/$defs/focus_point" },
226
+ "thumbnail_url": { "$ref": "#/$defs/url" },
227
+ "metadata": { "$ref": "#/$defs/metadata" },
228
+ "usage_id": { "type": "string", "minLength": 1 },
229
+ "usage_token": { "type": "string", "minLength": 1 },
230
+ "player_url": { "$ref": "#/$defs/url" },
231
+ "embed_html": { "description": "Responsive <iframe> of player_url.", "type": "string", "minLength": 1 },
232
+ "stream_url": { "description": "HLS manifest.", "$ref": "#/$defs/url" },
233
+ "poster_url": { "$ref": "#/$defs/url" },
234
+ "duration": { "description": "In seconds; null when unknown.", "type": ["number", "null"], "minimum": 0 },
235
+ "subtitles": {
236
+ "type": "array",
237
+ "items": { "$ref": "#/$defs/subtitle" }
238
+ },
239
+ "choice": { "$ref": "#/$defs/video_choice" }
240
+ },
241
+ "additionalProperties": false
242
+ },
243
+ "document": {
244
+ "type": "object",
245
+ "required": [
246
+ "gaid",
247
+ "version",
248
+ "type",
249
+ "mime_type",
250
+ "file_size",
251
+ "width",
252
+ "height",
253
+ "url",
254
+ "url_template",
255
+ "widths",
256
+ "formats",
257
+ "focus_point",
258
+ "thumbnail_url",
259
+ "metadata",
260
+ "usage_id",
261
+ "usage_token",
262
+ "download_url",
263
+ "pdf_url",
264
+ "preview_url",
265
+ "viewer_url",
266
+ "embed_html",
267
+ "page_count",
268
+ "extension",
269
+ "choice"
270
+ ],
271
+ "properties": {
272
+ "gaid": { "type": "string", "minLength": 1 },
273
+ "version": { "type": "integer", "minimum": 1 },
274
+ "type": { "const": "document" },
275
+ "mime_type": { "type": "string", "minLength": 1 },
276
+ "file_size": { "type": "integer", "minimum": 0 },
277
+ "width": { "$ref": "#/$defs/dimension" },
278
+ "height": { "$ref": "#/$defs/dimension" },
279
+ "url": { "description": "download_url or pdf_url, as choice.file says.", "$ref": "#/$defs/url" },
280
+ "url_template": { "$ref": "#/$defs/url_template" },
281
+ "widths": { "$ref": "#/$defs/widths" },
282
+ "formats": { "$ref": "#/$defs/formats" },
283
+ "focus_point": { "$ref": "#/$defs/focus_point" },
284
+ "thumbnail_url": { "$ref": "#/$defs/url" },
285
+ "metadata": { "$ref": "#/$defs/metadata" },
286
+ "usage_id": { "type": "string", "minLength": 1 },
287
+ "usage_token": { "type": "string", "minLength": 1 },
288
+ "download_url": { "$ref": "#/$defs/url" },
289
+ "pdf_url": {
290
+ "description": "Equal to download_url for a PDF; null when no PDF version exists.",
291
+ "type": ["string", "null"],
292
+ "minLength": 1
293
+ },
294
+ "preview_url": {
295
+ "description": "First page, served as an image; null when the document has no preview.",
296
+ "type": ["string", "null"],
297
+ "minLength": 1
298
+ },
299
+ "viewer_url": {
300
+ "description": "Page-by-page viewer; null when no PDF version exists.",
301
+ "type": ["string", "null"],
302
+ "minLength": 1
303
+ },
304
+ "embed_html": {
305
+ "description": "Responsive <iframe> of viewer_url; null when no PDF version exists.",
306
+ "type": ["string", "null"],
307
+ "minLength": 1
308
+ },
309
+ "page_count": { "type": ["integer", "null"], "minimum": 1 },
310
+ "extension": { "type": "string", "minLength": 1 },
311
+ "choice": { "$ref": "#/$defs/document_choice" }
312
+ },
313
+ "additionalProperties": false
314
+ }
315
+ }
316
+ }