@flourish/sdk 4.2.1 → 5.0.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.
- package/README.md +14 -1
- package/RELEASE_NOTES.md +4 -0
- package/common/embed/credit.d.ts +5 -0
- package/common/embed/credit.js +47 -0
- package/common/embed/customer_analytics.d.ts +5 -0
- package/common/embed/customer_analytics.js +114 -0
- package/common/embed/embedding.d.ts +25 -0
- package/common/embed/embedding.js +459 -0
- package/common/embed/localizations.d.ts +243 -0
- package/common/embed/localizations.js +90 -0
- package/common/embed/parse_query_params.d.ts +2 -0
- package/common/embed/parse_query_params.js +18 -0
- package/common/package.json +9 -0
- package/common/tsconfig.sdk.tsbuildinfo +1 -0
- package/common/utils/columns.d.ts +11 -0
- package/common/utils/columns.js +175 -0
- package/common/utils/data.d.ts +30 -0
- package/common/utils/data.js +279 -0
- package/common/utils/json.d.ts +3 -0
- package/common/utils/json.js +60 -0
- package/common/utils/polyfills.d.ts +0 -0
- package/common/utils/polyfills.js +30 -0
- package/common/utils/state.d.ts +7 -0
- package/common/utils/state.js +144 -0
- package/lib/cmd/login.js +12 -17
- package/lib/cmd/publish.js +3 -8
- package/lib/cmd/register.js +10 -13
- package/lib/common.js +1 -1
- package/lib/sdk.js +4 -6
- package/lib/validate_config.js +1 -1
- package/package.json +23 -24
- package/rollup.config.mjs +29 -0
- package/server/comms_js.js +1 -0
- package/server/index.js +5 -4
- package/server/views/index.html +5 -2
- package/site/embedded.js +2 -1
- package/site/images/icon-add-folder.svg +5 -0
- package/site/images/icon-all-projects.svg +3 -0
- package/site/images/icon-folder.svg +3 -0
- package/site/images/icon-search.svg +5 -0
- package/site/images/icon-shared-projects.svg +10 -0
- package/site/images/onboarding-tour-story-duplicate-slide.png +0 -0
- package/site/images/onboarding-tour-white-story.gif +0 -0
- package/site/images/story-onboarding-tour-legend.gif +0 -0
- package/site/script.js +3 -2
- package/site/sdk.css +2 -2
- package/tsconfig.json +10 -0
- package/server/columns.js +0 -201
- package/server/data.js +0 -327
- package/server/json.js +0 -66
- package/utils/state.js +0 -152
package/README.md
CHANGED
|
@@ -447,13 +447,26 @@ Builds the template and runs the SDK viewer in your web browser. If `dir_name` i
|
|
|
447
447
|
|
|
448
448
|
While it’s running it watches the template directory for changes:
|
|
449
449
|
* if you edit any static template files (`index.html`, `template.yml`, `data/*`, `static/*`) the SDK will refresh the page in the browser;
|
|
450
|
-
* if you edit a file that is the source for a [build rule](#build-configuration), the SDK will run that build rule and then refresh the page
|
|
450
|
+
* if you edit a file that is the source for a [build rule](#build-configuration), the SDK will run that build rule and then refresh the page;
|
|
451
|
+
* when the page has been refreshed, your previously applied settings in the same tab will be automatically restored (see below for more details).
|
|
451
452
|
|
|
452
453
|
Options:
|
|
453
454
|
* `--open` or `-o` Try to open the SDK in your web browser once the server is running. At present this only works on macOS.
|
|
454
455
|
* `--port` Specify a particular port; defaults to [1685](https://en.wikipedia.org/wiki/Johann_Sebastian_Bach)
|
|
455
456
|
* `--no-build` Skip the build process
|
|
456
457
|
|
|
458
|
+
### Settings restore and reset
|
|
459
|
+
|
|
460
|
+
Your previously applied settings in your SDK browser tab will be automatically restored by the SDK on each page refresh (from version `5.0.0`).
|
|
461
|
+
|
|
462
|
+
Template settings when using the SDK are therefore:
|
|
463
|
+
|
|
464
|
+
- stored locally in your browser's session storage per window
|
|
465
|
+
- are restored on page load before the template `draw` call
|
|
466
|
+
- do not include restore of template state other than settings
|
|
467
|
+
|
|
468
|
+
You can click the "Reset" button on the top right hand side of the SDK interface to refresh the tab and start from template default settings, or alternatively you can close and open a new SDK browser tab.
|
|
469
|
+
|
|
457
470
|
### Publish a template
|
|
458
471
|
```sh
|
|
459
472
|
flourish publish [dir_name]
|
package/RELEASE_NOTES.md
CHANGED
|
@@ -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, captions: 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";
|