@goatlab/fluent-formio 0.2.4 → 0.6.3

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/src/Utilities.js DELETED
@@ -1,280 +0,0 @@
1
- /* eslint-disable no-unused-vars */
2
- let Utilities = (() => {
3
- /**
4
- * Deep clones a JS object using JSON.parse
5
- * This function will not clone object
6
- * functions
7
- * @param {Object} object
8
- */
9
- const cloneDeep = object => {
10
- return JSON.parse(JSON.stringify(object));
11
- };
12
- /**
13
- * Given an Object and its path, if exisits it will
14
- * return the value of it, if not the default
15
- * @param {Object} obj
16
- * @param {String} path
17
- * @param {*} def
18
- */
19
- const get = (fn, def) => {
20
- try {
21
- return fn();
22
- } catch (e) {
23
- return def;
24
- }
25
- };
26
- /**
27
- *
28
- * @param {*} obj
29
- * @param {*} path
30
- * @param {*} def
31
- */
32
- const getFromPath = (obj, path, def) => {
33
- let _path = path;
34
-
35
- if (path.includes(' as ')) {
36
- path = path.split(' as ');
37
- _path = path[0];
38
- }
39
-
40
- let assignedName = get(() => {
41
- return Array.isArray(path) && path[1].trim();
42
- }, undefined);
43
-
44
- let fullPath = _path
45
- .replace(/\[/g, '.')
46
- .replace(/]/g, '')
47
- .split('.')
48
- .filter(Boolean)
49
- .map(e => e.trim());
50
-
51
- function everyFunc(step) {
52
- return !(step && (obj = obj[step]) === undefined);
53
- }
54
-
55
- let result = fullPath.every(everyFunc) ? obj : def;
56
-
57
- return { label: assignedName || _path, value: result };
58
- };
59
- /**
60
- *
61
- * @param {*} arr
62
- * @param {*} predicate
63
- */
64
- const uniqBy = (arr, predicate) => {
65
- const cb = typeof predicate === 'function' ? predicate : o => o[predicate];
66
-
67
- return [
68
- ...arr
69
- .reduce((map, item) => {
70
- const key = cb(item);
71
-
72
- map.has(key) || map.set(key, item);
73
-
74
- return map;
75
- }, new Map())
76
- .values()
77
- ];
78
- };
79
- /**
80
- *
81
- */
82
- const orderBy = () => { };
83
- /**
84
- *
85
- * @param {*} value
86
- */
87
- const isEmpty = value => {
88
- if (!value) {
89
- return true;
90
- }
91
- if (Array.isArray(value) || typeof value === 'string') {
92
- return !value.length;
93
- }
94
- for (let key in value) {
95
- if (hasOwnProperty.call(value, key)) {
96
- return false;
97
- }
98
- }
99
- return true;
100
- };
101
- /**
102
- *
103
- * @param {*} fn
104
- * @param {*} time
105
- */
106
- const debounce = (fn, time) => {
107
- let timeout;
108
-
109
- return function () {
110
- const functionCall = () => fn.apply(this, arguments);
111
-
112
- clearTimeout(timeout);
113
- timeout = setTimeout(functionCall, time);
114
- };
115
- };
116
- /**
117
- * Recursively removes all NULL values
118
- * from an Object or an Array
119
- *
120
- * @static
121
- * @param {Array|Object} object Array, Object to clean
122
- * @returns {Array|Object} returns the cleaned value
123
- */
124
- const deleteNulls = object => {
125
- let obj = object;
126
- var isArray = obj instanceof Array;
127
-
128
- for (let k in obj) {
129
- if (obj[k] === null) isArray ? obj.splice(k, 1) : delete obj[k];
130
- else if (typeof obj[k] === 'object') deleteNulls(obj[k]);
131
- }
132
- return obj;
133
- };
134
-
135
- const eachComponent = (components, fn, includeAll, path, parent) => {
136
- if (!components) return;
137
- path = path || '';
138
- components.forEach(component => {
139
- if (!component) {
140
- return;
141
- }
142
- const hasColumns = component.columns && Array.isArray(component.columns);
143
- const hasRows = component.rows && Array.isArray(component.rows);
144
- const hasComps =
145
- component.components && Array.isArray(component.components);
146
- let noRecurse = false;
147
- const newPath = component.key ?
148
- path ?
149
- `${path}.${component.key}` :
150
- component.key :
151
- '';
152
-
153
- // Keep track of parent references.
154
- if (parent) {
155
- // Ensure we don't create infinite JSON structures.
156
- component.parent = { ...parent };
157
- delete component.parent.components;
158
- delete component.parent.componentMap;
159
- delete component.parent.columns;
160
- delete component.parent.rows;
161
- }
162
-
163
- if (
164
- includeAll ||
165
- component.tree ||
166
- (!hasColumns && !hasRows && !hasComps)
167
- ) {
168
- noRecurse = fn(component, newPath);
169
- }
170
-
171
- const subPath = () => {
172
- if (
173
- component.key &&
174
- ![
175
- 'panel',
176
- 'table',
177
- 'well',
178
- 'columns',
179
- 'fieldset',
180
- 'tabs',
181
- 'form'
182
- ].includes(component.type) &&
183
- (['datagrid', 'container', 'editgrid'].includes(component.type) ||
184
- component.tree)
185
- ) {
186
- return newPath;
187
- } else if (component.key && component.type === 'form') {
188
- return `${newPath}.data`;
189
- }
190
- return path;
191
- };
192
-
193
- if (!noRecurse) {
194
- if (hasColumns) {
195
- component.columns.forEach(column =>
196
- eachComponent(
197
- column.components,
198
- fn,
199
- includeAll,
200
- subPath(),
201
- parent ? component : null
202
- )
203
- );
204
- } else if (hasRows) {
205
- component.rows.forEach(row => {
206
- if (Array.isArray(row)) {
207
- row.forEach(column =>
208
- eachComponent(
209
- column.components,
210
- fn,
211
- includeAll,
212
- subPath(),
213
- parent ? component : null
214
- )
215
- );
216
- }
217
- });
218
- } else if (hasComps) {
219
- eachComponent(
220
- component.components,
221
- fn,
222
- includeAll,
223
- subPath(),
224
- parent ? component : null
225
- );
226
- }
227
- }
228
- });
229
- };
230
-
231
- const matchComponent = (component, query) => {
232
- if (typeof query === 'string') {
233
- return component.key === query;
234
- }
235
- let matches = false;
236
-
237
- Object.keys(query).forEach(path => {
238
- matches = getFromPath(component, path).value === query[path];
239
- if (!matches) {
240
- return false;
241
- }
242
- });
243
- return matches;
244
- };
245
-
246
- const findComponents = (components, query) => {
247
- const results = [];
248
-
249
- eachComponent(
250
- components,
251
- (component, path) => {
252
- if (matchComponent(component, query)) {
253
- component.path = path;
254
- results.push(component);
255
- }
256
- },
257
- true
258
- );
259
- return results;
260
- };
261
-
262
- const unixDate = () => {
263
- return Math.round(+new Date() / 1000);
264
- };
265
-
266
- return Object.freeze({
267
- cloneDeep,
268
- get,
269
- orderBy,
270
- isEmpty,
271
- debounce,
272
- getFromPath,
273
- deleteNulls,
274
- eachComponent,
275
- findComponents,
276
- unixDate
277
- });
278
- })();
279
-
280
- export default Utilities;
@@ -1,69 +0,0 @@
1
- import Event from './Event';
2
- import Promise from 'bluebird';
3
- import axios from 'axios';
4
- /* eslint-disable no-unused-vars */
5
- let Connection = (() => {
6
- let online = (typeof window !== 'undefined') && window && window.navigator ? window.navigator.onLine : true;
7
-
8
- function setOnline() {
9
- if (!online) {
10
- online = true;
11
- Event.emit({
12
- name: 'FAST:CONNECTION:ONLINE',
13
- data: online,
14
- text: 'Application is now online'
15
- });
16
- }
17
- }
18
-
19
- function setOffline() {
20
- if (online) {
21
- online = false;
22
- Event.emit({
23
- name: 'FAST:CONNECTION:OFFLINE',
24
- data: online,
25
- text: 'Application is now offline'
26
- });
27
- }
28
- }
29
-
30
- /**
31
- * [status description]
32
- * @return {Promise} [description]
33
- */
34
- function initEventListeners() {
35
- Event.listen({
36
- name: 'online',
37
- callback: function () {
38
- console.log('App is now online');
39
- setOnline();
40
- }
41
- });
42
- Event.listen({
43
- name: 'offline',
44
- callback: function () {
45
- console.log('App is now offline');
46
- setOffline();
47
- }
48
- });
49
- }
50
-
51
- function isOnline() {
52
- return new Promise((resolve, reject) => {
53
- axios.get('https://yesno.wtf/api')
54
- .then( res => {
55
- resolve(true);
56
- })
57
- .catch( err => {
58
- resolve(false);
59
- })
60
- });
61
- }
62
-
63
- return Object.freeze({
64
- isOnline,
65
- initEventListeners
66
- });
67
- })();
68
-
69
- export default Connection;
@@ -1,42 +0,0 @@
1
- let Event = (() => {
2
- let CustomEvent = function (event, params) {
3
- var evt = document.createEvent('CustomEvent');
4
-
5
- params = params || { bubbles: false, cancelable: false, detail: undefined };
6
-
7
- evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
8
- return evt;
9
- };
10
-
11
- function emit({ name, data, text }) {
12
- if (!name) throw new Error('Event must have a name.');
13
- if (!data) throw new Error('Event must have data.');
14
- if (!text) throw new Error('Event must have a text.');
15
- let customEvent = CustomEvent(name, {
16
- detail: {
17
- data: data,
18
- text: text
19
- }
20
- });
21
-
22
- window.dispatchEvent(customEvent);
23
- }
24
- function listen({ name, callback }) {
25
- if (!name) throw new Error('Listener must have a name.');
26
- if (!callback) throw new Error('Listener must have a callback.');
27
- window.addEventListener(name, callback);
28
- }
29
-
30
- function remove({ name, callback }) {
31
- if (!name) throw new Error('Listener must have a name to detach');
32
- if (!callback) throw new Error('Listener must have a callback to detach');
33
- window.removeEventListener(name, callback);
34
- }
35
- return Object.freeze({
36
- emit,
37
- listen,
38
- remove
39
- });
40
- })();
41
-
42
- export default Event;
package/src/index.js DELETED
@@ -1,3 +0,0 @@
1
- import FluentConnector from "./FluentConnector";
2
-
3
- export default FluentConnector;
@@ -1,72 +0,0 @@
1
- global.XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
2
-
3
- const { JSDOM } = require('jsdom');
4
-
5
- const jsdom = new JSDOM('<!doctype html><html><body></body></html>');
6
- const { window } = jsdom;
7
-
8
- function copyProps (src, target) {
9
- const props = Object.getOwnPropertyNames(src)
10
- .filter((prop) => typeof target[prop] === 'undefined')
11
- .map((prop) => Object.getOwnPropertyDescriptor(src, prop));
12
-
13
- Object.defineProperties(target, props);
14
- }
15
-
16
- global.window = window;
17
- global.document = window.document;
18
- global.navigator = {
19
- onLine: true,
20
- userAgent: 'node.js'
21
- };
22
- copyProps(window, global);
23
- const fetch = require('node-fetch');
24
-
25
- require('isomorphic-fetch');
26
- global.Headers = fetch.Headers;
27
-
28
- global.Buffer = global.Buffer || require('buffer').Buffer;
29
-
30
- if (typeof btoa === 'undefined') {
31
- global.btoa = function (str) {
32
- return new Buffer(str, 'binary').toString('base64');
33
- };
34
- }
35
-
36
- if (typeof atob === 'undefined') {
37
- global.atob = function (b64Encoded) {
38
- return new Buffer(b64Encoded, 'base64').toString('binary');
39
- };
40
- }
41
-
42
- // Request animationFrame polly
43
-
44
- (function () {
45
- var lastTime = 0;
46
- var vendors = ['ms', 'moz', 'webkit', 'o'];
47
-
48
- for (let x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
49
- window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
50
- window.cancelAnimationFrame =
51
- window[vendors[x] + 'CancelAnimationFrame'] || window[vendors[x] + 'CancelRequestAnimationFrame'];
52
- }
53
-
54
- if (!window.requestAnimationFrame) {
55
- window.requestAnimationFrame = function (callback, element) {
56
- var currTime = new Date().getTime();
57
- var timeToCall = Math.max(0, 16 - (currTime - lastTime));
58
- var id = window.setTimeout(function () {
59
- callback(currTime + timeToCall);
60
- }, timeToCall);
61
-
62
- lastTime = currTime + timeToCall;
63
- return id;
64
- };
65
- }
66
-
67
- if (!window.cancelAnimationFrame) {
68
- window.cancelAnimationFrame = function (id) {
69
- clearTimeout(id);
70
- };
71
- }
72
- })();
@@ -1,19 +0,0 @@
1
- var nodeExternals = require('webpack-node-externals');
2
- const path = require('path');
3
- const Dotenv = require('dotenv-webpack');
4
-
5
- module.exports = {
6
- mode: 'development',
7
- output: {
8
- // use absolute paths in sourcemaps (important for debugging via IDE)
9
- devtoolModuleFilenameTemplate: '[absolute-resource-path]',
10
- devtoolFallbackModuleFilenameTemplate: '[absolute-resource-path]?[hash]'
11
- },
12
- resolve: {
13
- modules: [path.resolve('./src')]
14
- },
15
- target: 'node', // webpack should compile node compatible code
16
- externals: [nodeExternals()], // in order to ignore all modules in node_modules folder
17
- devtool: 'inline-cheap-module-source-map',
18
- plugins: [new Dotenv()]
19
- };
package/webpack.config.js DELETED
@@ -1,88 +0,0 @@
1
- /* global __dirname, require, module*/
2
- const webpack = require("webpack");
3
- const path = require("path");
4
- const env = require("yargs").argv.env; // use --env with webpack 2
5
- const pkg = require("./package.json");
6
- const BundleAnalyzerPlugin = require("webpack-bundle-analyzer")
7
- .BundleAnalyzerPlugin;
8
- const showBundle = false;
9
- let plugins = [new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)];
10
-
11
- if (showBundle) {
12
- plugins.push(new BundleAnalyzerPlugin());
13
- }
14
- let libraryName = pkg.name;
15
-
16
- let outputFile, minimize;
17
-
18
- if (env === "build") {
19
- minimize = true;
20
- outputFile = libraryName + ".min.js";
21
- } else {
22
- minimize = false;
23
- outputFile = libraryName + ".min.js";
24
- }
25
-
26
- const config = {
27
- mode: "production",
28
- entry: __dirname + "/src/index.js",
29
- devtool: "source-map",
30
- output: {
31
- path: __dirname + "/lib",
32
- filename: outputFile,
33
- library: libraryName,
34
- libraryTarget: "umd",
35
- umdNamedDefine: true,
36
- globalObject: "this"
37
- },
38
- optimization: {
39
- minimize: minimize
40
- },
41
- module: {
42
- rules: [
43
- {
44
- test: /(\.jsx|\.js)$/,
45
- loader: "babel-loader",
46
- exclude: /(node_modules|bower_components)/,
47
- options: {
48
- plugins: ["lodash"],
49
- presets: [["env", { modules: false, targets: { node: 4 } }]]
50
- }
51
- }
52
- /*
53
- {
54
- test: /(\.jsx|\.js)$/,
55
- loader: 'eslint-loader',
56
- exclude: /node_modules/
57
- }
58
- */
59
- ]
60
- },
61
- plugins: plugins,
62
- resolve: {
63
- modules: [path.resolve("./node_modules"), path.resolve("./src")],
64
- extensions: [".json", ".js"],
65
- alias: {
66
- "formio-export": path.resolve(__dirname, "src/")
67
- }
68
- },
69
- externals: {
70
- lodash: {
71
- commonjs: "lodash",
72
- commonjs2: "lodash",
73
- amd: "_",
74
- root: "_"
75
- },
76
- axios: "axios"
77
- },
78
- node: {
79
- // prevent webpack from injecting mocks to Node native modules
80
- // that does not make sense for the client
81
- dgram: "empty",
82
- fs: "empty",
83
- net: "empty",
84
- tls: "empty"
85
- }
86
- };
87
-
88
- module.exports = config;