@symbo.ls/sync 3.14.0 → 3.14.1

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/Inspect.js DELETED
@@ -1,190 +0,0 @@
1
- 'use strict'
2
-
3
- import * as smblsUI from '@symbo.ls/default-config/components'
4
- import { isObject, isString, isArray } from '@symbo.ls/utils'
5
- import { send } from './client.js'
6
-
7
- function returnStringExtend (_extends) {
8
- return isString(_extends) ? _extends : isArray(_extends) ? _extends.find(extItem => isString(extItem)) : ''
9
- }
10
-
11
- function getComponentKey (el) {
12
- if (!el) return
13
- const __componentKey = el.__ref.__componentKey
14
- const extendsStr = el.extends && returnStringExtend(el.extends)
15
- const parentChildExtendStr = el.parent && el.parent.childExtends && returnStringExtend(el.parent.childExtends)
16
- return (__componentKey || extendsStr || parentChildExtendStr || '').split('_')[0].split('.')[0].split('+')[0]
17
- }
18
-
19
- function findComponent (el) {
20
- if (!el || !el.__ref) return
21
- const { components, pages, editor } = el.context
22
- const componentKey = getComponentKey(el)
23
- if (editor && editor.onInitInspect) {
24
- const initInspectReturns = editor.onInitInspect(componentKey, el, el.state)
25
- if (!initInspectReturns) return findComponent(el.parent)
26
- }
27
- if (componentKey && (components[componentKey] || pages[componentKey])) {
28
- return el
29
- }
30
- return findComponent(el.parent)
31
- }
32
-
33
- const onInspect = (app, state, ctx) => {
34
- const windowOpts = ctx.window || window
35
- windowOpts.onkeydown = (ev) => {
36
- if (ev.altKey && ev.shiftKey) {
37
- app.state.update({ debugging: true, preventSelect: true }, {
38
- preventUpdate: true,
39
- preventContentUpdate: true,
40
- preventRecursive: true
41
- })
42
- }
43
- }
44
- windowOpts.onkeyup = (ev) => {
45
- if (app.state.preventSelect && (!ev.altKey || !ev.shiftKey)) {
46
- app.state.replace({ debugging: false, preventSelect: false }, {
47
- preventUpdate: true,
48
- preventContentUpdate: true,
49
- preventRecursive: true
50
- })
51
- app.Inspector.state.update({ area: false })
52
- }
53
- }
54
- }
55
-
56
- export const Inspect = {
57
- '.preventSelect': { userSelect: 'none' },
58
- '!preventSelect': { userSelect: 'auto' },
59
-
60
- onInspect,
61
-
62
- onMousemove: (ev, e, state) => {
63
- const el = ev.target.ref
64
- const component = findComponent(el)
65
- const focusState = e.Inspector.state
66
-
67
- if (!component || !state.debugging || !component.__ref) return focusState.update({ area: false })
68
-
69
- const componentKey = getComponentKey(component)
70
- const updateValue = (area) => {
71
- focusState.update({ area, focusKey: componentKey })
72
- }
73
-
74
- const update = () => {
75
- if (ev.altKey && ev.shiftKey) {
76
- const { x, y, width, height } = component.node.getBoundingClientRect()
77
- const area = { x, y, width, height }
78
-
79
- if (!focusState.area) return updateValue(area)
80
- if (focusState.area.x !== area.x) updateValue(area)
81
- } else if (focusState.area) {
82
- focusState.update({ area: false })
83
- }
84
- }
85
-
86
- window.requestAnimationFrame(() => {
87
- update()
88
- window.requestAnimationFrame(update)
89
- })
90
- },
91
-
92
- onMousedown: (ev, elem, state) => {
93
- if (!state.debugging) return
94
- const el = ev.target.ref
95
- const component = findComponent(el)
96
- if (!component) return
97
- const componentKey = getComponentKey(component)
98
- if (!componentKey) return
99
-
100
- const editor = el.context.editor
101
- if (editor && editor.onInspect) {
102
- return editor.onInspect(componentKey, el, el.state, { allowRouterWhileInspect: true })
103
- }
104
-
105
- const data = JSON.stringify({
106
- componentKey: `${componentKey}`
107
- })
108
- send.call(el.context.socket, 'route', data)
109
-
110
- ev.preventDefault()
111
- ev.stopPropagation()
112
- return false
113
- },
114
-
115
- Inspector: {
116
- state: {},
117
-
118
- transition: 'all, defaultBezier, X',
119
- position: 'fixed',
120
- hide: (el, s) => !(s.area && s.parent.debugging),
121
- style: {
122
- boxShadow: '0 0 10px #3686F733, 0 0 0 3px #3686F766, 0 0 100vmax 100vmax #000A',
123
- zIndex: '9999999',
124
- borderRadius: '10px',
125
- pointerEvents: 'none'
126
- },
127
-
128
- Span: {
129
- position: 'absolute',
130
- margin: 'A2 0',
131
- fontSize: 'Z',
132
- color: 'text',
133
- // color: 'blue',
134
- zIndex: '99999999',
135
- transition: 'all, defaultBezier, X',
136
- textDecoration: 'underline',
137
- fontWeight: '500',
138
- top: '100%',
139
- style: {
140
- boxShadow: '0 25px 10px 35px black',
141
- textShadow: '0 0 10px black'
142
- },
143
- text: '{{ focusKey }}'
144
- },
145
-
146
- onInit: ({ context }) => {
147
- const { components } = context
148
-
149
- if (isObject(components)) {
150
- const { Content, ...rest } = components
151
- for (const key in rest) {
152
- if (smblsUI[key]) continue
153
- if (!rest[key].__ref) rest[key].__ref = {}
154
- if (!rest[key].__ref.__componentKey) {
155
- rest[key].__ref.__componentKey = key
156
- }
157
- }
158
- }
159
- },
160
- onBeforeUpdate: (ch, el, s) => {
161
- const { area } = s
162
- const isDebugging = s.area && s.parent.debugging
163
-
164
- let style
165
- if (!isDebugging) {
166
- style = 'display: none !important'
167
- } else if (area) {
168
- const { x, y, width, height } = area
169
- // el.node.style = Object.stringify({
170
- // top: y - 6 + 'px',
171
- // left: x - 6 + 'px',
172
- // width: width + 12 + 'px',
173
- // height: height + 12 + 'px'
174
- // })
175
- style = `
176
- display: block !important;
177
- top: ${y - 6}px;
178
- left: ${x - 6}px;
179
- width: ${width + 12}px;
180
- height: ${height + 12}px;
181
- `
182
- }
183
-
184
- el.node.style = style
185
- el.Span.node.innerText = s.focusKey
186
-
187
- return false
188
- }
189
- }
190
- }
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
- };