@schibsted/sps-sdk 5.2.0-CBT-20902.2 → 5.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.
@@ -1 +0,0 @@
1
- {"version":3,"file":"iframe.js","sourceRoot":"","sources":["../../../src/actions/iframe.ts"],"names":[],"mappings":"AAAA,MAAM,oBAAoB,GAAG,CAAC,GAAa,EAAQ,EAAE;IACnD,CAAC,GAAG,CAAC,eAAe,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE;QAC7C,EAAE,CAAC,KAAK,CAAC,MAAM,GAAG,GAAG,CAAC;QACtB,EAAE,CAAC,KAAK,CAAC,OAAO,GAAG,GAAG,CAAC;QACvB,EAAE,CAAC,KAAK,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC/B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,sBAAsB,GAAG,CAAC,GAAa,EAAQ,EAAE;IACrD,GAAG,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;QACtC,MAAM,MAAM,GAAI,KAAK,CAAC,MAAyB,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;QAC9D,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC;YAClB,OAAO;QACT,CAAC;QACD,KAAK,CAAC,cAAc,EAAE,CAAC;QACvB,wEAAwE;QACxE,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC;IAClE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,OAAoB,EACpB,QAAgB,EAChB,OAAe,EACA,EAAE,CACjB,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;IACtB,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IAChD,MAAM,CAAC,EAAE,GAAG,QAAQ,CAAC;IACrB,MAAM,CAAC,KAAK,CAAC,MAAM,GAAG,GAAG,CAAC;IAC1B,MAAM,CAAC,KAAK,CAAC,OAAO,GAAG,OAAO,CAAC;IAC/B,MAAM,CAAC,KAAK,CAAC,KAAK,GAAG,MAAM,CAAC;IAC5B,MAAM,CAAC,gBAAgB,CACrB,MAAM,EACN,GAAG,EAAE;QACH,MAAM,GAAG,GAAG,MAAM,CAAC,eAAgB,CAAC;QACpC,oBAAoB,CAAC,GAAG,CAAC,CAAC;QAC1B,sBAAsB,CAAC,GAAG,CAAC,CAAC;QAE5B,MAAM,YAAY,GAAG,GAAG,EAAE;YACxB,MAAM,CAAC,KAAK,CAAC,MAAM,GAAG,GAAG,GAAG,CAAC,IAAI,CAAC,YAAY,IAAI,CAAC;QACrD,CAAC,CAAC;QACF,YAAY,EAAE,CAAC;QACf,IAAI,cAAc,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACnD,OAAO,EAAE,CAAC;IACZ,CAAC,EACD,EAAE,IAAI,EAAE,IAAI,EAAE,CACf,CAAC;IACF,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC;IACxB,OAAO,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;AAClC,CAAC,CAAC,CAAC"}
@@ -1,52 +0,0 @@
1
- import type { RenderPlacementsOptions } from "./sps.js";
2
- import type { PlacementTypeWithStringContent } from "./sps/placement.js";
3
- export declare const PLACEMENT_ELEMENT_TAG = "sps-placement";
4
- export declare const PLACEMENT_LOADED_EVENT = "sps-loaded";
5
- export declare const PLACEMENT_ERROR_EVENT = "sps-error";
6
- /**
7
- * Page-wide configuration for `<sps-placement>` elements, set with {@link configureSps}.
8
- * Takes the options of {@link renderFrontpagePlacements} and {@link renderArticlePagePlacements},
9
- * plus the page context.
10
- */
11
- export type ConfigureSpsOptions = RenderPlacementsOptions & {
12
- /** Which kind of page the placements are on. */
13
- context: "frontpage" | "article";
14
- };
15
- /** Detail of the `sps-loaded` event dispatched on every element of a finished load. */
16
- export type PlacementLoadedDetail = {
17
- /** The placement types that were rendered by the load this element was part of. */
18
- rendered: PlacementTypeWithStringContent[];
19
- };
20
- /** Detail of the `sps-error` event dispatched when a load fails. */
21
- export type PlacementErrorDetail = {
22
- error: unknown;
23
- };
24
- /** Methods of the `<sps-placement>` element. */
25
- export interface SpsPlacementElement extends HTMLElement {
26
- /**
27
- * Loads this element together with the other elements of its `group`, like
28
- * {@link loadPlacements} for that group.
29
- */
30
- load(): Promise<PlacementTypeWithStringContent[]>;
31
- }
32
- /**
33
- * Loads the `<sps-placement>` elements of a group in one request, so SPS can choose between their
34
- * placement types. Elements without a `group` attribute are in the default group. Loading again
35
- * replaces what was rendered. Nothing is loaded until {@link configureSps} has been called.
36
- *
37
- * @param group - The group to load. Defaults to the group of elements without a `group` attribute.
38
- * @returns The placement types that were rendered, which is empty when SPS returned none.
39
- */
40
- export declare const loadPlacements: (group?: string) => Promise<PlacementTypeWithStringContent[]>;
41
- /**
42
- * Configures the SDK for the page and defines the `<sps-placement>` element.
43
- *
44
- * Nothing is loaded by this call: call {@link loadPlacements} or `load()` on an element when you
45
- * are ready. Calling this again replaces the configuration.
46
- *
47
- * In an environment without custom elements, such as Node, the configuration is stored and
48
- * nothing else happens.
49
- *
50
- * @param options - The publication and environment to request from, the page context, and request options including `params`.
51
- */
52
- export declare const configureSps: (options: ConfigureSpsOptions) => void;
@@ -1,86 +0,0 @@
1
- import { renderArticlePagePlacements, renderFrontpagePlacements } from "./sps.js";
2
- export const PLACEMENT_ELEMENT_TAG = "sps-placement";
3
- export const PLACEMENT_LOADED_EVENT = "sps-loaded";
4
- export const PLACEMENT_ERROR_EVENT = "sps-error";
5
- const DEFAULT_GROUP = "default";
6
- let config;
7
- const loadElements = async (elements) => {
8
- if (!config) {
9
- console.warn("[SPS sdk] Call configureSps before loading placements");
10
- return [];
11
- }
12
- if (elements.length === 0) {
13
- return [];
14
- }
15
- const { context, ...options } = config;
16
- const render = context === "frontpage" ? renderFrontpagePlacements : renderArticlePagePlacements;
17
- const placements = elements.map((element) => ({
18
- placementType: element.getAttribute("type"),
19
- element,
20
- }));
21
- try {
22
- const rendered = await render(placements, options);
23
- elements.forEach((element) => {
24
- element.hidden = !rendered.includes(element.getAttribute("type"));
25
- element.dispatchEvent(new CustomEvent(PLACEMENT_LOADED_EVENT, {
26
- detail: { rendered },
27
- bubbles: true,
28
- }));
29
- });
30
- return rendered;
31
- }
32
- catch (error) {
33
- console.error("[SPS sdk] Failed to load placements", error);
34
- elements.forEach((element) => element.dispatchEvent(new CustomEvent(PLACEMENT_ERROR_EVENT, {
35
- detail: { error },
36
- bubbles: true,
37
- })));
38
- return [];
39
- }
40
- };
41
- const getGroup = (element) => element.getAttribute("group") ?? DEFAULT_GROUP;
42
- /**
43
- * Loads the `<sps-placement>` elements of a group in one request, so SPS can choose between their
44
- * placement types. Elements without a `group` attribute are in the default group. Loading again
45
- * replaces what was rendered. Nothing is loaded until {@link configureSps} has been called.
46
- *
47
- * @param group - The group to load. Defaults to the group of elements without a `group` attribute.
48
- * @returns The placement types that were rendered, which is empty when SPS returned none.
49
- */
50
- export const loadPlacements = (group = DEFAULT_GROUP) => {
51
- const members = [...document.querySelectorAll(PLACEMENT_ELEMENT_TAG)].filter((member) => getGroup(member) === group && member.getAttribute("type"));
52
- return loadElements(members);
53
- };
54
- // Defined lazily: extending HTMLElement at module scope would throw when the SDK is imported in Node
55
- const definePlacementElement = () => {
56
- if (customElements.get(PLACEMENT_ELEMENT_TAG)) {
57
- return;
58
- }
59
- // Zero specificity, so any rule from the host page wins
60
- const style = document.createElement("style");
61
- style.textContent = `:where(${PLACEMENT_ELEMENT_TAG}) { display: block; }`;
62
- document.head.appendChild(style);
63
- customElements.define(PLACEMENT_ELEMENT_TAG, class extends HTMLElement {
64
- load() {
65
- return loadPlacements(getGroup(this));
66
- }
67
- });
68
- };
69
- /**
70
- * Configures the SDK for the page and defines the `<sps-placement>` element.
71
- *
72
- * Nothing is loaded by this call: call {@link loadPlacements} or `load()` on an element when you
73
- * are ready. Calling this again replaces the configuration.
74
- *
75
- * In an environment without custom elements, such as Node, the configuration is stored and
76
- * nothing else happens.
77
- *
78
- * @param options - The publication and environment to request from, the page context, and request options including `params`.
79
- */
80
- export const configureSps = (options) => {
81
- config = options;
82
- if (typeof customElements !== "undefined") {
83
- definePlacementElement();
84
- }
85
- };
86
- //# sourceMappingURL=configure.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"configure.js","sourceRoot":"","sources":["../../src/configure.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,yBAAyB,EAAE,MAAM,OAAO,CAAC;AAI/E,MAAM,CAAC,MAAM,qBAAqB,GAAG,eAAe,CAAC;AACrD,MAAM,CAAC,MAAM,sBAAsB,GAAG,YAAY,CAAC;AACnD,MAAM,CAAC,MAAM,qBAAqB,GAAG,WAAW,CAAC;AAEjD,MAAM,aAAa,GAAG,SAAS,CAAC;AA8BhC,IAAI,MAAuC,CAAC;AAE5C,MAAM,YAAY,GAAG,KAAK,EACxB,QAA+B,EACY,EAAE;IAC7C,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,CAAC,IAAI,CAAC,uDAAuD,CAAC,CAAC;QACtE,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,GAAG,MAAM,CAAC;IACvC,MAAM,MAAM,GAAG,OAAO,KAAK,WAAW,CAAC,CAAC,CAAC,yBAAyB,CAAC,CAAC,CAAC,2BAA2B,CAAC;IAEjG,MAAM,UAAU,GAAuB,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,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