@flourish/sdk 4.1.0 → 4.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.
Files changed (48) hide show
  1. package/README.md +15 -4
  2. package/RELEASE_NOTES.md +6 -0
  3. package/common/embed/credit.d.ts +5 -0
  4. package/common/embed/credit.js +47 -0
  5. package/common/embed/customer_analytics.d.ts +5 -0
  6. package/common/embed/customer_analytics.js +114 -0
  7. package/common/embed/embedding.d.ts +25 -0
  8. package/common/embed/embedding.js +461 -0
  9. package/common/embed/localizations.d.ts +243 -0
  10. package/common/embed/localizations.js +90 -0
  11. package/common/embed/parse_query_params.d.ts +2 -0
  12. package/common/embed/parse_query_params.js +18 -0
  13. package/common/package.json +8 -0
  14. package/common/tsconfig.sdk.tsbuildinfo +1 -0
  15. package/common/utils/columns.d.ts +11 -0
  16. package/common/utils/columns.js +175 -0
  17. package/common/utils/data.d.ts +30 -0
  18. package/common/utils/data.js +279 -0
  19. package/common/utils/json.d.ts +3 -0
  20. package/common/utils/json.js +60 -0
  21. package/common/utils/polyfills.d.ts +0 -0
  22. package/common/utils/polyfills.js +30 -0
  23. package/common/utils/state.d.ts +7 -0
  24. package/common/utils/state.js +144 -0
  25. package/lib/sdk.js +22 -3
  26. package/lib/validate_config.js +21 -10
  27. package/package.json +3 -6
  28. package/server/columns.js +1 -1
  29. package/server/comms_js.js +1 -0
  30. package/server/data.js +31 -6
  31. package/server/json.js +1 -1
  32. package/server/views/index.html +1 -1
  33. package/site/embedded.js +1 -1
  34. package/site/images/company.svg +5 -0
  35. package/site/images/icon-editable.svg +10 -0
  36. package/site/images/icon-presentation.svg +3 -0
  37. package/site/images/icon-private.svg +3 -0
  38. package/site/images/icon-sliders.svg +3 -0
  39. package/site/images/icon-upload.svg +3 -0
  40. package/site/images/icon-viewable.svg +3 -0
  41. package/site/images/refresh.svg +3 -0
  42. package/site/images/user.svg +3 -0
  43. package/site/images/visualisation_purpose.svg +3 -0
  44. package/site/images/visualisation_type.svg +3 -0
  45. package/site/script.js +2 -2
  46. package/site/sdk.css +1 -1
  47. package/test/lib/validate_config.js +45 -2
  48. package/utils/state.js +1 -1
package/README.md CHANGED
@@ -214,7 +214,7 @@ show_if:
214
214
  color_mode: [diverging, continuous]
215
215
  ```
216
216
 
217
- You can specify multiple conditions. All of these tests must pass for the setting to be displayed. For example:
217
+ You can specify multiple conditions. Where _all_ conditions should pass for the setting to be displayed, use an object syntax. For example, the setting below will be shown if `show_x_axis` is enabled **AND** `color_mode` is set to "diverging".
218
218
 
219
219
  ```yaml
220
220
  show_if:
@@ -222,6 +222,17 @@ show_if:
222
222
  color_mode: diverging
223
223
  ```
224
224
 
225
+ Where _any_ one combination of conditions should pass for the setting to be displayed, use an array syntax where conditions **within** an array (elements separated with `-`) operate as **OR** and conditions within an object still operate as **AND**.
226
+
227
+ For example, the setting below will be shown if `chart_mode` is "line", **OR** if `chart_mode` is "bar" **AND** the "labels" data binding contains numeric data.
228
+
229
+ ```yaml
230
+ show_if:
231
+ - chart_mode: line
232
+ - chart_mode: bar
233
+ data.data.labels.type: numeric
234
+ ```
235
+
225
236
  The `hide_if` option works in exactly the same way, except that the setting is hidden if the conditional test passes.
226
237
 
227
238
  ```yaml
@@ -245,7 +256,7 @@ The `template.yml` file may also include a `data` section. This section consists
245
256
 
246
257
  Once your template is published, Flourish users can change the data in the Flourish editor, and also change which columns are linked to each binding. But in your code you don’t need to worry about this because you just refer to the `key` rather than referencing the column header or index.
247
258
 
248
- There are two types of data binding: `column` is used when the number of columns is and must always be one; `columns` supports any number of columns, including none.
259
+ There are two types of data binding: `column` is used when the number of columns is and must always be one; `columns` supports any number of columns, including none.
249
260
 
250
261
  A default value must be supplied for each data binding, unless you have specified `optional: true` (only supported for single `column` bindings). The example below shows how this is done.
251
262
 
@@ -266,7 +277,7 @@ data:
266
277
  key: values
267
278
  type: columns # This binding can take any number of columns
268
279
  columns: By Decade::B-D,F # The default values are arrays drawing from columns B-D and F of `By Decade.csv`
269
- - name: Flag image
280
+ - name: Flag image
270
281
  dataset: country_scores
271
282
  key: flag_pic
272
283
  type: column
@@ -507,4 +518,4 @@ The method has 2 arguments:
507
518
 
508
519
  ```js
509
520
  takeScreenshot().then(onSuccess, onFail)
510
- ```
521
+ ```
package/RELEASE_NOTES.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 4.2.0
2
+ * Add support for OR conditions in `show_if` and `hide_if`
3
+
4
+ # 4.1.1
5
+ * Fixes the reporting of server errors by the CLI
6
+
1
7
  # 4.1.0
2
8
  * Allow SDK CLI token based authentication.
3
9
 
@@ -0,0 +1,5 @@
1
+ export function createFlourishCredit(credit_url: any, query_string: any, public_url: any, credit_text: any): any;
2
+ export function getLocalizedCreditTextAndUrl(lang: any, credit_key: any): {
3
+ credit_text: any;
4
+ credit_url: any;
5
+ };
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getLocalizedCreditTextAndUrl = exports.createFlourishCredit = void 0;
7
+ const localizations_1 = __importDefault(require("./localizations"));
8
+ function createFlourishCredit(credit_url, query_string, public_url, credit_text) {
9
+ credit_url = credit_url || "https://flourish.studio",
10
+ query_string = query_string || "?utm_source=api&utm_campaign=" + window.location.href,
11
+ public_url = public_url || "https://public.flourish.studio/",
12
+ credit_text = credit_text || "A Flourish data visualization";
13
+ var credit = document.createElement("div");
14
+ credit.setAttribute("class", "flourish-credit");
15
+ credit.setAttribute("style", "width:100%!important;margin:0 0 4px!important;text-align:right!important;font-family:Helvetica,sans-serif!important;color:#888!important;font-size:11px!important;font-weight:bold!important;font-style:normal!important;-webkit-font-smoothing:antialiased!important;box-shadow:none!important;");
16
+ var a = document.createElement("a");
17
+ a.setAttribute("href", credit_url + query_string);
18
+ a.setAttribute("target", "_top");
19
+ a.setAttribute("style", "display:inline-block!important;text-decoration:none!important;font:inherit!important;color:inherit!important;border:none!important;margin:0 5px!important;box-shadow:none!important;");
20
+ credit.appendChild(a);
21
+ var img = document.createElement("img");
22
+ img.setAttribute("alt", "Flourish logo");
23
+ img.setAttribute("src", public_url + "resources/bosh.svg");
24
+ img.setAttribute("style", "font:inherit!important;width:auto!important;height:12px!important;border:none!important;margin:0 2px 0!important;vertical-align:middle!important;display:inline-block!important;box-shadow:none!important;");
25
+ a.appendChild(img);
26
+ var span = document.createElement("span");
27
+ span.setAttribute("style", "font:inherit!important;color:#888!important;vertical-align:middle!important;display:inline-block!important;box-shadow:none!important;");
28
+ span.appendChild(document.createTextNode(credit_text));
29
+ a.appendChild(span);
30
+ return credit;
31
+ }
32
+ exports.createFlourishCredit = createFlourishCredit;
33
+ function getLocalizedCreditTextAndUrl(lang, credit_key) {
34
+ var credit_text, credit_url;
35
+ lang = lang || "en", credit_key = credit_key || "";
36
+ credit_text = localizations_1.default[lang].credits[credit_key] || localizations_1.default.en.credits[credit_key] || localizations_1.default.en.credits.default;
37
+ if (typeof credit_text == "object") {
38
+ if (credit_text.url)
39
+ credit_url = credit_text.url;
40
+ credit_text = credit_text.text;
41
+ }
42
+ return {
43
+ credit_text: credit_text,
44
+ credit_url: credit_url
45
+ };
46
+ }
47
+ exports.getLocalizedCreditTextAndUrl = getLocalizedCreditTextAndUrl;
@@ -0,0 +1,5 @@
1
+ export function sendCustomerAnalyticsMessage(message: any): void;
2
+ export function addAnalyticsListener(callback: any): void;
3
+ export function removeAnalyticsListener(callback: any): void;
4
+ export function dispatchAnalyticsEvent(message: any): void;
5
+ export function initCustomerAnalytics(): void;
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.initCustomerAnalytics = exports.dispatchAnalyticsEvent = exports.removeAnalyticsListener = exports.addAnalyticsListener = exports.sendCustomerAnalyticsMessage = void 0;
4
+ // Embedded code - must work in IE
5
+ var enabled = false;
6
+ function getLocationData() {
7
+ var data = {};
8
+ if (window._Flourish_template_id) {
9
+ data.template_id = window._Flourish_template_id;
10
+ }
11
+ if (window.Flourish && window.Flourish.app && window.Flourish.app.loaded_template_id) {
12
+ data.template_id = window.Flourish.app.loaded_template_id;
13
+ }
14
+ if (window._Flourish_visualisation_id) {
15
+ data.visualisation_id = window._Flourish_visualisation_id;
16
+ }
17
+ if (window.Flourish && window.Flourish.app && window.Flourish.app.loaded_visualisation) {
18
+ data.visualisation_id = window.Flourish.app.loaded_visualisation.id;
19
+ }
20
+ if (window.Flourish && window.Flourish.app && window.Flourish.app.story) {
21
+ data.story_id = window.Flourish.app.story.id;
22
+ data.slide_count = window.Flourish.app.story.slides.length;
23
+ }
24
+ if (window.Flourish && window.Flourish.app && window.Flourish.app.current_slide) {
25
+ // One indexed
26
+ data.slide_index = window.Flourish.app.current_slide.index + 1;
27
+ }
28
+ return data;
29
+ }
30
+ function sendCustomerAnalyticsMessage(message) {
31
+ if (!enabled)
32
+ return;
33
+ if (window.top === window.self)
34
+ return;
35
+ var embedded_window = window;
36
+ if (embedded_window.location.pathname === "srcdoc")
37
+ embedded_window = embedded_window.parent;
38
+ var location_data = getLocationData();
39
+ var message_with_metadata = {
40
+ sender: "Flourish",
41
+ method: "customerAnalytics"
42
+ };
43
+ for (var key in location_data) {
44
+ if (location_data.hasOwnProperty(key)) {
45
+ message_with_metadata[key] = location_data[key];
46
+ }
47
+ }
48
+ for (var key in message) {
49
+ if (message.hasOwnProperty(key)) {
50
+ message_with_metadata[key] = message[key];
51
+ }
52
+ }
53
+ embedded_window.parent.postMessage(JSON.stringify(message_with_metadata), "*");
54
+ }
55
+ exports.sendCustomerAnalyticsMessage = sendCustomerAnalyticsMessage;
56
+ function addAnalyticsListener(callback) {
57
+ if (typeof callback !== "function") {
58
+ throw new Error("Analytics callback is not a function");
59
+ }
60
+ window.Flourish._analytics_listeners.push(callback);
61
+ }
62
+ exports.addAnalyticsListener = addAnalyticsListener;
63
+ function removeAnalyticsListener(callback) {
64
+ if (typeof callback !== "function") {
65
+ throw new Error("Analytics callback is not a function");
66
+ }
67
+ window.Flourish._analytics_listeners = window.Flourish._analytics_listeners.filter(function (listener) {
68
+ return callback !== listener;
69
+ });
70
+ }
71
+ exports.removeAnalyticsListener = removeAnalyticsListener;
72
+ function dispatchAnalyticsEvent(message) {
73
+ // If the window.Flourish object hasn't been created by the customer, they
74
+ // can't be listening for analytics events
75
+ if (!window.Flourish)
76
+ return;
77
+ window.Flourish._analytics_listeners.forEach(function (listener) {
78
+ listener(message);
79
+ });
80
+ }
81
+ exports.dispatchAnalyticsEvent = dispatchAnalyticsEvent;
82
+ function initCustomerAnalytics() {
83
+ enabled = true;
84
+ var events = [
85
+ {
86
+ event_name: "click",
87
+ action_name: "click",
88
+ use_capture: true
89
+ },
90
+ {
91
+ event_name: "keydown",
92
+ action_name: "key_down",
93
+ use_capture: true
94
+ },
95
+ {
96
+ event_name: "mouseenter",
97
+ action_name: "mouse_enter",
98
+ use_capture: false
99
+ },
100
+ {
101
+ event_name: "mouseleave",
102
+ action_name: "mouse_leave",
103
+ use_capture: false
104
+ }
105
+ ];
106
+ events.forEach(function (event) {
107
+ document.body.addEventListener(event.event_name, function () {
108
+ sendCustomerAnalyticsMessage({
109
+ action: event.action_name
110
+ });
111
+ }, event.use_capture);
112
+ });
113
+ }
114
+ exports.initCustomerAnalytics = initCustomerAnalytics;
@@ -0,0 +1,25 @@
1
+ export default initEmbedding;
2
+ declare function initEmbedding(): {
3
+ createEmbedIframe: typeof createEmbedIframe;
4
+ isFixedHeight: typeof isFixedHeight;
5
+ getHeightForBreakpoint: typeof getHeightForBreakpoint;
6
+ startEventListeners: typeof startEventListeners;
7
+ notifyParentWindow: typeof notifyParentWindow;
8
+ initScrolly: typeof initScrolly;
9
+ createScrolly: typeof createScrolly;
10
+ isSafari: typeof isSafari;
11
+ initCustomerAnalytics: typeof initCustomerAnalytics;
12
+ addAnalyticsListener: typeof addAnalyticsListener;
13
+ sendCustomerAnalyticsMessage: typeof sendCustomerAnalyticsMessage;
14
+ };
15
+ declare function createEmbedIframe(embed_url: any, container: any, width: any, height: any, play_on_load: any): any;
16
+ declare function isFixedHeight(): any;
17
+ declare function getHeightForBreakpoint(width: any): 650 | 575 | 400;
18
+ declare function startEventListeners(callback: any, allowed_methods: any, embed_domain: any): void;
19
+ declare function notifyParentWindow(height: any, opts: any): void;
20
+ declare function initScrolly(opts: any): void;
21
+ declare function createScrolly(iframe: any, slides: any): void;
22
+ declare function isSafari(): boolean;
23
+ import { initCustomerAnalytics } from "./customer_analytics";
24
+ import { addAnalyticsListener } from "./customer_analytics";
25
+ import { sendCustomerAnalyticsMessage } from "./customer_analytics";