@symbo.ls/sync 3.14.0 → 3.14.2

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,120 +0,0 @@
1
- 'use strict'
2
-
3
- // const ANIMATION = {
4
- // fadeInUp: {
5
- // from: {
6
- // transform: 'translate3d(0, 12.5%, 1px)',
7
- // opacity: 0
8
- // },
9
- // to: {
10
- // transform: 'translate3d(0, 0, 1px)',
11
- // opacity: 1
12
- // }
13
- // },
14
- // fadeOutDown: {
15
- // from: {
16
- // transform: 'translate3d(0, 0, 1px)',
17
- // opacity: 1
18
- // },
19
- // to: {
20
- // transform: 'translate3d(0, 12.5%, 1px)',
21
- // opacity: 0
22
- // }
23
- // }
24
- // }
25
-
26
- // const COLOR = {
27
- // black: '#000000',
28
- // blue: '#3686F7'
29
- // }
30
-
31
- // set({
32
- // COLOR,
33
- // ANIMATION
34
- // })
35
-
36
- const NOTIF_COLORS = {
37
- success: 'green',
38
- error: 'red',
39
- warning: 'yellow'
40
- }
41
-
42
- export const connectedToSymbols = (clients, element, state) => {
43
- if (clients.symbols) {
44
- if (!state.connected) {
45
- state.notifications.connected = {
46
- title: 'Connected',
47
- message: 'to the Symbols live server'
48
- }
49
-
50
- state.update({ connected: true })
51
-
52
- const t = setTimeout(() => {
53
- delete state.notifications.connected
54
- element.notifications.content.connected.update({
55
- animation: 'fadeOutDown'
56
- })
57
- state.update({ connected: true })
58
- clearTimeout(t)
59
- }, 3000)
60
- }
61
- } else {
62
- if (state.connected) {
63
- state.notifications.connected = {
64
- title: 'Disconnected',
65
- type: 'error'
66
- }
67
-
68
- state.update({ connected: false })
69
-
70
- const t = setTimeout(() => {
71
- delete state.notifications.connected
72
- if (element.notifications.content.connected) {
73
- element.notifications.content.connected.update({
74
- animation: 'fadeOutDown'
75
- })
76
- }
77
- state.update({ connected: true })
78
- clearTimeout(t)
79
- }, 3000)
80
- }
81
- }
82
- }
83
-
84
- export const Notifications = {
85
- state: {
86
- notifications: []
87
- },
88
-
89
- Notifications: {
90
- position: 'fixed',
91
- left: 'A2',
92
- bottom: 'Z2',
93
- zIndex: '999',
94
- childExtends: 'Notification',
95
- childProps: ({ state }) => ({
96
- animationDuration: 'C',
97
- background: NOTIF_COLORS[state.type || 'success'],
98
- icon: null,
99
- Flex: {
100
- Title: {
101
- text: '{{ title }}'
102
- },
103
- P: {
104
- text: '{{ title }}'
105
- }
106
- },
107
- onRender: (e, el, s) => {
108
- el.update({ animation: 'fadeInUp' })
109
- },
110
- onClick: (e, el, s) => {
111
- delete s.notifications[el.key]
112
- el.update({ animation: 'fadeOutDown' })
113
- if (s.onClose) s.onClose(e, el, s)
114
- }
115
- }),
116
- IconText: null,
117
- childrenAs: 'state',
118
- children: ({ state }) => state.notifications
119
- }
120
- }
package/client.js DELETED
@@ -1,129 +0,0 @@
1
- import { window, isFunction, isArray } from '@symbo.ls/utils'
2
- import io from 'socket.io-client'
3
-
4
- const defautlOpts = {}
5
-
6
- let CONNECT_ATTEPT = 0
7
- const CONNECT_ATTEPT_MAX_ALLOWED = 1
8
-
9
- const getIsDev = options => {
10
- return (
11
- options.development ||
12
- (window && window.location && window.location.host.includes('local')) ||
13
- ENV === 'testing' ||
14
- ENV === 'development'
15
- )
16
- }
17
-
18
- const getSocketUrl = (options, isDev) => {
19
- const SOCKET_BACKEND_URL = isDev
20
- ? 'http://localhost:8080/'
21
- : 'https://api.symbols.app/'
22
-
23
- const socketUrls = isArray(options.socketUrl)
24
- ? options.socketUrl
25
- : [options.socketUrl || SOCKET_BACKEND_URL]
26
-
27
- const primaryUrl = socketUrls[0]
28
- const secondaryUrl = socketUrls[1] || 'api.symbols.app'
29
-
30
- return {
31
- primaryUrl: primaryUrl || SOCKET_BACKEND_URL,
32
- secondaryUrl
33
- }
34
- }
35
-
36
- export const connect = (key, options = {}) => {
37
- const isDev = getIsDev(options)
38
-
39
- const { primaryUrl, secondaryUrl } = getSocketUrl(options, isDev)
40
- const socket = io(primaryUrl || secondaryUrl, {
41
- // withCredentials: true
42
- })
43
-
44
- socket.on('connect', () => {
45
- if (isDev) {
46
- console.warn(
47
- `Connected to %c${primaryUrl} %c${key} %c${socket.id}`,
48
- 'font-weight: bold; color: green;',
49
- 'font-weight: bold;',
50
- ''
51
- )
52
- }
53
-
54
- socket.emit('initConnect', { key, ...options })
55
-
56
- try {
57
- if (isFunction(options.onConnect)) {
58
- options.onConnect(socket.id, socket)
59
- }
60
- } catch (e) {
61
- console.error(e)
62
- }
63
- })
64
-
65
- socket.on('connect_error', (err) => {
66
- console.log(`event: connect_error | reason: ${err.message}`)
67
- try {
68
- if (isFunction(options.onError)) {
69
- options.onError(err, socket)
70
- }
71
-
72
- if (CONNECT_ATTEPT < CONNECT_ATTEPT_MAX_ALLOWED) {
73
- CONNECT_ATTEPT++
74
-
75
- socket.disconnect()
76
-
77
- if (utils.isNotProduction()) {
78
- console.log(
79
- `Could not connect to %c${primaryUrl}%c, reconnecting to %c${
80
- secondaryUrl
81
- }`,
82
- 'font-weight: bold; color: red;',
83
- '',
84
- 'font-weight: bold; color: green;'
85
- )
86
- }
87
-
88
- connect(key, { ...options, socketUrl: secondaryUrl })
89
- }
90
- } catch (e) {
91
- console.error(e)
92
- }
93
- })
94
-
95
- socket.on('disconnect', (reason) => {
96
- console.log(`event: disconnect | reason: ${reason}`)
97
- try {
98
- if (isFunction(options.onDisconnect)) {
99
- options.onDisconnect(reason, socket)
100
- }
101
- } catch (e) {
102
- console.error(e)
103
- }
104
- })
105
-
106
- socket.onAny((event, ...args) => {
107
- if (event === 'connect') {
108
- return
109
- }
110
-
111
- try {
112
- if (isFunction(options.onChange)) {
113
- options.onChange(event, args[0], socket)
114
- }
115
- } catch (e) {
116
- console.error(e)
117
- }
118
- })
119
-
120
- return socket
121
- }
122
-
123
- export function send(event = 'change', changes, options) {
124
- this.emit(event, changes, { ...options, ...defautlOpts })
125
- }
126
-
127
- export function disconnect() {
128
- this.disconnect()
129
- }
@@ -1,191 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var Inspect_exports = {};
30
- __export(Inspect_exports, {
31
- Inspect: () => Inspect
32
- });
33
- module.exports = __toCommonJS(Inspect_exports);
34
- var smblsUI = __toESM(require("@symbo.ls/default-config/components"), 1);
35
- var import_utils = require("@symbo.ls/utils");
36
- var import_client = require("./client.js");
37
- function returnStringExtend(_extends) {
38
- return (0, import_utils.isString)(_extends) ? _extends : (0, import_utils.isArray)(_extends) ? _extends.find((extItem) => (0, import_utils.isString)(extItem)) : "";
39
- }
40
- function getComponentKey(el) {
41
- if (!el) return;
42
- const __componentKey = el.__ref.__componentKey;
43
- const extendsStr = el.extends && returnStringExtend(el.extends);
44
- const parentChildExtendStr = el.parent && el.parent.childExtends && returnStringExtend(el.parent.childExtends);
45
- return (__componentKey || extendsStr || parentChildExtendStr || "").split("_")[0].split(".")[0].split("+")[0];
46
- }
47
- function findComponent(el) {
48
- if (!el || !el.__ref) return;
49
- const { components, pages, editor } = el.context;
50
- const componentKey = getComponentKey(el);
51
- if (editor && editor.onInitInspect) {
52
- const initInspectReturns = editor.onInitInspect(componentKey, el, el.state);
53
- if (!initInspectReturns) return findComponent(el.parent);
54
- }
55
- if (componentKey && (components[componentKey] || pages[componentKey])) {
56
- return el;
57
- }
58
- return findComponent(el.parent);
59
- }
60
- const onInspect = (app, state, ctx) => {
61
- const windowOpts = ctx.window || window;
62
- windowOpts.onkeydown = (ev) => {
63
- if (ev.altKey && ev.shiftKey) {
64
- app.state.update({ debugging: true, preventSelect: true }, {
65
- preventUpdate: true,
66
- preventContentUpdate: true,
67
- preventRecursive: true
68
- });
69
- }
70
- };
71
- windowOpts.onkeyup = (ev) => {
72
- if (app.state.preventSelect && (!ev.altKey || !ev.shiftKey)) {
73
- app.state.replace({ debugging: false, preventSelect: false }, {
74
- preventUpdate: true,
75
- preventContentUpdate: true,
76
- preventRecursive: true
77
- });
78
- app.Inspector.state.update({ area: false });
79
- }
80
- };
81
- };
82
- const Inspect = {
83
- ".preventSelect": { userSelect: "none" },
84
- "!preventSelect": { userSelect: "auto" },
85
- onInspect,
86
- onMousemove: (ev, e, state) => {
87
- const el = ev.target.ref;
88
- const component = findComponent(el);
89
- const focusState = e.Inspector.state;
90
- if (!component || !state.debugging || !component.__ref) return focusState.update({ area: false });
91
- const componentKey = getComponentKey(component);
92
- const updateValue = (area) => {
93
- focusState.update({ area, focusKey: componentKey });
94
- };
95
- const update = () => {
96
- if (ev.altKey && ev.shiftKey) {
97
- const { x, y, width, height } = component.node.getBoundingClientRect();
98
- const area = { x, y, width, height };
99
- if (!focusState.area) return updateValue(area);
100
- if (focusState.area.x !== area.x) updateValue(area);
101
- } else if (focusState.area) {
102
- focusState.update({ area: false });
103
- }
104
- };
105
- window.requestAnimationFrame(() => {
106
- update();
107
- window.requestAnimationFrame(update);
108
- });
109
- },
110
- onMousedown: (ev, elem, state) => {
111
- if (!state.debugging) return;
112
- const el = ev.target.ref;
113
- const component = findComponent(el);
114
- if (!component) return;
115
- const componentKey = getComponentKey(component);
116
- if (!componentKey) return;
117
- const editor = el.context.editor;
118
- if (editor && editor.onInspect) {
119
- return editor.onInspect(componentKey, el, el.state, { allowRouterWhileInspect: true });
120
- }
121
- const data = JSON.stringify({
122
- componentKey: `${componentKey}`
123
- });
124
- import_client.send.call(el.context.socket, "route", data);
125
- ev.preventDefault();
126
- ev.stopPropagation();
127
- return false;
128
- },
129
- Inspector: {
130
- state: {},
131
- transition: "all, defaultBezier, X",
132
- position: "fixed",
133
- hide: (el, s) => !(s.area && s.parent.debugging),
134
- style: {
135
- boxShadow: "0 0 10px #3686F733, 0 0 0 3px #3686F766, 0 0 100vmax 100vmax #000A",
136
- zIndex: "9999999",
137
- borderRadius: "10px",
138
- pointerEvents: "none"
139
- },
140
- Span: {
141
- position: "absolute",
142
- margin: "A2 0",
143
- fontSize: "Z",
144
- color: "text",
145
- // color: 'blue',
146
- zIndex: "99999999",
147
- transition: "all, defaultBezier, X",
148
- textDecoration: "underline",
149
- fontWeight: "500",
150
- top: "100%",
151
- style: {
152
- boxShadow: "0 25px 10px 35px black",
153
- textShadow: "0 0 10px black"
154
- },
155
- text: "{{ focusKey }}"
156
- },
157
- onInit: ({ context }) => {
158
- const { components } = context;
159
- if ((0, import_utils.isObject)(components)) {
160
- const { Content, ...rest } = components;
161
- for (const key in rest) {
162
- if (smblsUI[key]) continue;
163
- if (!rest[key].__ref) rest[key].__ref = {};
164
- if (!rest[key].__ref.__componentKey) {
165
- rest[key].__ref.__componentKey = key;
166
- }
167
- }
168
- }
169
- },
170
- onBeforeUpdate: (ch, el, s) => {
171
- const { area } = s;
172
- const isDebugging = s.area && s.parent.debugging;
173
- let style;
174
- if (!isDebugging) {
175
- style = "display: none !important";
176
- } else if (area) {
177
- const { x, y, width, height } = area;
178
- style = `
179
- display: block !important;
180
- top: ${y - 6}px;
181
- left: ${x - 6}px;
182
- width: ${width + 12}px;
183
- height: ${height + 12}px;
184
- `;
185
- }
186
- el.node.style = style;
187
- el.Span.node.innerText = s.focusKey;
188
- return false;
189
- }
190
- }
191
- };
@@ -1,102 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var SyncNotifications_exports = {};
20
- __export(SyncNotifications_exports, {
21
- Notifications: () => Notifications,
22
- connectedToSymbols: () => connectedToSymbols
23
- });
24
- module.exports = __toCommonJS(SyncNotifications_exports);
25
- const NOTIF_COLORS = {
26
- success: "green",
27
- error: "red",
28
- warning: "yellow"
29
- };
30
- const connectedToSymbols = (clients, element, state) => {
31
- if (clients.symbols) {
32
- if (!state.connected) {
33
- state.notifications.connected = {
34
- title: "Connected",
35
- message: "to the Symbols live server"
36
- };
37
- state.update({ connected: true });
38
- const t = setTimeout(() => {
39
- delete state.notifications.connected;
40
- element.notifications.content.connected.update({
41
- animation: "fadeOutDown"
42
- });
43
- state.update({ connected: true });
44
- clearTimeout(t);
45
- }, 3e3);
46
- }
47
- } else {
48
- if (state.connected) {
49
- state.notifications.connected = {
50
- title: "Disconnected",
51
- type: "error"
52
- };
53
- state.update({ connected: false });
54
- const t = setTimeout(() => {
55
- delete state.notifications.connected;
56
- if (element.notifications.content.connected) {
57
- element.notifications.content.connected.update({
58
- animation: "fadeOutDown"
59
- });
60
- }
61
- state.update({ connected: true });
62
- clearTimeout(t);
63
- }, 3e3);
64
- }
65
- }
66
- };
67
- const Notifications = {
68
- state: {
69
- notifications: []
70
- },
71
- Notifications: {
72
- position: "fixed",
73
- left: "A2",
74
- bottom: "Z2",
75
- zIndex: "999",
76
- childExtends: "Notification",
77
- childProps: ({ state }) => ({
78
- animationDuration: "C",
79
- background: NOTIF_COLORS[state.type || "success"],
80
- icon: null,
81
- Flex: {
82
- Title: {
83
- text: "{{ title }}"
84
- },
85
- P: {
86
- text: "{{ title }}"
87
- }
88
- },
89
- onRender: (e, el, s) => {
90
- el.update({ animation: "fadeInUp" });
91
- },
92
- onClick: (e, el, s) => {
93
- delete s.notifications[el.key];
94
- el.update({ animation: "fadeOutDown" });
95
- if (s.onClose) s.onClose(e, el, s);
96
- }
97
- }),
98
- IconText: null,
99
- childrenAs: "state",
100
- children: ({ state }) => state.notifications
101
- }
102
- };
@@ -1,129 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var client_exports = {};
29
- __export(client_exports, {
30
- connect: () => connect,
31
- disconnect: () => disconnect,
32
- send: () => send
33
- });
34
- module.exports = __toCommonJS(client_exports);
35
- var import_utils = require("@symbo.ls/utils");
36
- var import_socket = __toESM(require("socket.io-client"), 1);
37
- const defautlOpts = {};
38
- let CONNECT_ATTEPT = 0;
39
- const CONNECT_ATTEPT_MAX_ALLOWED = 1;
40
- const getIsDev = (options) => {
41
- return options.development || import_utils.window && import_utils.window.location && import_utils.window.location.host.includes("local") || ENV === "testing" || ENV === "development";
42
- };
43
- const getSocketUrl = (options, isDev) => {
44
- const SOCKET_BACKEND_URL = isDev ? "http://localhost:8080/" : "https://api.symbols.app/";
45
- const socketUrls = (0, import_utils.isArray)(options.socketUrl) ? options.socketUrl : [options.socketUrl || SOCKET_BACKEND_URL];
46
- const primaryUrl = socketUrls[0];
47
- const secondaryUrl = socketUrls[1] || "api.symbols.app";
48
- return {
49
- primaryUrl: primaryUrl || SOCKET_BACKEND_URL,
50
- secondaryUrl
51
- };
52
- };
53
- const connect = (key, options = {}) => {
54
- const isDev = getIsDev(options);
55
- const { primaryUrl, secondaryUrl } = getSocketUrl(options, isDev);
56
- const socket = (0, import_socket.default)(primaryUrl || secondaryUrl, {
57
- // withCredentials: true
58
- });
59
- socket.on("connect", () => {
60
- if (isDev) {
61
- console.warn(
62
- `Connected to %c${primaryUrl} %c${key} %c${socket.id}`,
63
- "font-weight: bold; color: green;",
64
- "font-weight: bold;",
65
- ""
66
- );
67
- }
68
- socket.emit("initConnect", { key, ...options });
69
- try {
70
- if ((0, import_utils.isFunction)(options.onConnect)) {
71
- options.onConnect(socket.id, socket);
72
- }
73
- } catch (e) {
74
- console.error(e);
75
- }
76
- });
77
- socket.on("connect_error", (err) => {
78
- console.log(`event: connect_error | reason: ${err.message}`);
79
- try {
80
- if ((0, import_utils.isFunction)(options.onError)) {
81
- options.onError(err, socket);
82
- }
83
- if (CONNECT_ATTEPT < CONNECT_ATTEPT_MAX_ALLOWED) {
84
- CONNECT_ATTEPT++;
85
- socket.disconnect();
86
- if (utils.isNotProduction()) {
87
- console.log(
88
- `Could not connect to %c${primaryUrl}%c, reconnecting to %c${secondaryUrl}`,
89
- "font-weight: bold; color: red;",
90
- "",
91
- "font-weight: bold; color: green;"
92
- );
93
- }
94
- connect(key, { ...options, socketUrl: secondaryUrl });
95
- }
96
- } catch (e) {
97
- console.error(e);
98
- }
99
- });
100
- socket.on("disconnect", (reason) => {
101
- console.log(`event: disconnect | reason: ${reason}`);
102
- try {
103
- if ((0, import_utils.isFunction)(options.onDisconnect)) {
104
- options.onDisconnect(reason, socket);
105
- }
106
- } catch (e) {
107
- console.error(e);
108
- }
109
- });
110
- socket.onAny((event, ...args) => {
111
- if (event === "connect") {
112
- return;
113
- }
114
- try {
115
- if ((0, import_utils.isFunction)(options.onChange)) {
116
- options.onChange(event, args[0], socket);
117
- }
118
- } catch (e) {
119
- console.error(e);
120
- }
121
- });
122
- return socket;
123
- };
124
- function send(event = "change", changes, options) {
125
- this.emit(event, changes, { ...options, ...defautlOpts });
126
- }
127
- function disconnect() {
128
- this.disconnect();
129
- }