@symbo.ls/sync 3.1.2 → 3.2.7
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 +1 -1
- package/client.js +131 -0
- package/dist/cjs/Inspect.js +1 -1
- package/dist/cjs/client.js +130 -0
- package/dist/cjs/index.js +185 -51
- package/dist/cjs/server.js +115 -0
- package/dist/esm/Inspect.js +2 -17
- package/dist/esm/client.js +101 -0
- package/dist/esm/index.js +186 -51
- package/dist/esm/server.js +85 -0
- package/dist/iife/index.js +495 -0
- package/index.js +222 -53
- package/package.json +48 -22
- package/server.js +102 -0
- package/dist/cjs/package.json +0 -4
package/Inspect.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import * as smblsUI from '@symbo.ls/uikit'
|
|
4
4
|
import { isObject, isString, isArray } from '@domql/utils'
|
|
5
|
-
import { send } from '
|
|
5
|
+
import { send } from './client.js'
|
|
6
6
|
|
|
7
7
|
function returnStringExtend (_extends) {
|
|
8
8
|
return isString(_extends) ? _extends : isArray(_extends) ? _extends.find(extItem => isString(extItem)) : ''
|
package/client.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import * as utils from '@domql/utils'
|
|
2
|
+
import io from 'socket.io-client'
|
|
3
|
+
|
|
4
|
+
const { window, isFunction, isArray } = utils.default || utils
|
|
5
|
+
|
|
6
|
+
const defautlOpts = {}
|
|
7
|
+
|
|
8
|
+
let CONNECT_ATTEPT = 0
|
|
9
|
+
const CONNECT_ATTEPT_MAX_ALLOWED = 1
|
|
10
|
+
|
|
11
|
+
const getIsDev = options => {
|
|
12
|
+
return (
|
|
13
|
+
options.development ||
|
|
14
|
+
(window && window.location && window.location.host.includes('local')) ||
|
|
15
|
+
ENV === 'testing' ||
|
|
16
|
+
ENV === 'development'
|
|
17
|
+
)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const getSocketUrl = (options, isDev) => {
|
|
21
|
+
const SOCKET_BACKEND_URL = isDev
|
|
22
|
+
? 'http://localhost:8080/'
|
|
23
|
+
: 'https://api.symbols.app/'
|
|
24
|
+
|
|
25
|
+
const socketUrls = isArray(options.socketUrl)
|
|
26
|
+
? options.socketUrl
|
|
27
|
+
: [options.socketUrl || SOCKET_BACKEND_URL]
|
|
28
|
+
|
|
29
|
+
const primaryUrl = socketUrls[0]
|
|
30
|
+
const secondaryUrl = socketUrls[1] || 'api.symbols.app'
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
primaryUrl: primaryUrl || SOCKET_BACKEND_URL,
|
|
34
|
+
secondaryUrl
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const connect = (key, options = {}) => {
|
|
39
|
+
const isDev = getIsDev(options)
|
|
40
|
+
|
|
41
|
+
const { primaryUrl, secondaryUrl } = getSocketUrl(options, isDev)
|
|
42
|
+
const socket = io(primaryUrl || secondaryUrl, {
|
|
43
|
+
// withCredentials: true
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
socket.on('connect', () => {
|
|
47
|
+
if (isDev) {
|
|
48
|
+
console.warn(
|
|
49
|
+
`Connected to %c${primaryUrl} %c${key} %c${socket.id}`,
|
|
50
|
+
'font-weight: bold; color: green;',
|
|
51
|
+
'font-weight: bold;',
|
|
52
|
+
''
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
socket.emit('initConnect', { key, ...options })
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
if (isFunction(options.onConnect)) {
|
|
60
|
+
options.onConnect(socket.id, socket)
|
|
61
|
+
}
|
|
62
|
+
} catch (e) {
|
|
63
|
+
console.error(e)
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
socket.on('connect_error', (err) => {
|
|
68
|
+
console.log(`event: connect_error | reason: ${err.message}`)
|
|
69
|
+
try {
|
|
70
|
+
if (isFunction(options.onError)) {
|
|
71
|
+
options.onError(err, socket)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (CONNECT_ATTEPT < CONNECT_ATTEPT_MAX_ALLOWED) {
|
|
75
|
+
CONNECT_ATTEPT++
|
|
76
|
+
|
|
77
|
+
socket.disconnect()
|
|
78
|
+
|
|
79
|
+
if (utils.isNotProduction()) {
|
|
80
|
+
console.log(
|
|
81
|
+
`Could not connect to %c${primaryUrl}%c, reconnecting to %c${
|
|
82
|
+
secondaryUrl
|
|
83
|
+
}`,
|
|
84
|
+
'font-weight: bold; color: red;',
|
|
85
|
+
'',
|
|
86
|
+
'font-weight: bold; color: green;'
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
connect(key, { ...options, socketUrl: secondaryUrl })
|
|
91
|
+
}
|
|
92
|
+
} catch (e) {
|
|
93
|
+
console.error(e)
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
socket.on('disconnect', (reason) => {
|
|
98
|
+
console.log(`event: disconnect | reason: ${reason}`)
|
|
99
|
+
try {
|
|
100
|
+
if (isFunction(options.onDisconnect)) {
|
|
101
|
+
options.onDisconnect(reason, socket)
|
|
102
|
+
}
|
|
103
|
+
} catch (e) {
|
|
104
|
+
console.error(e)
|
|
105
|
+
}
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
socket.onAny((event, ...args) => {
|
|
109
|
+
if (event === 'connect') {
|
|
110
|
+
return
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
try {
|
|
114
|
+
if (isFunction(options.onChange)) {
|
|
115
|
+
options.onChange(event, args[0], socket)
|
|
116
|
+
}
|
|
117
|
+
} catch (e) {
|
|
118
|
+
console.error(e)
|
|
119
|
+
}
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
return socket
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function send(event = 'change', changes, options) {
|
|
126
|
+
this.emit(event, changes, { ...options, ...defautlOpts })
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function disconnect() {
|
|
130
|
+
this.disconnect()
|
|
131
|
+
}
|
package/dist/cjs/Inspect.js
CHANGED
|
@@ -33,7 +33,7 @@ __export(Inspect_exports, {
|
|
|
33
33
|
module.exports = __toCommonJS(Inspect_exports);
|
|
34
34
|
var smblsUI = __toESM(require("@symbo.ls/uikit"), 1);
|
|
35
35
|
var import_utils = require("@domql/utils");
|
|
36
|
-
var import_client = require("
|
|
36
|
+
var import_client = require("./client.js");
|
|
37
37
|
function returnStringExtend(_extends) {
|
|
38
38
|
return (0, import_utils.isString)(_extends) ? _extends : (0, import_utils.isArray)(_extends) ? _extends.find((extItem) => (0, import_utils.isString)(extItem)) : "";
|
|
39
39
|
}
|
|
@@ -0,0 +1,130 @@
|
|
|
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 utils = __toESM(require("@domql/utils"), 1);
|
|
36
|
+
var import_socket = __toESM(require("socket.io-client"), 1);
|
|
37
|
+
const { window, isFunction, isArray } = utils.default || utils;
|
|
38
|
+
const defautlOpts = {};
|
|
39
|
+
let CONNECT_ATTEPT = 0;
|
|
40
|
+
const CONNECT_ATTEPT_MAX_ALLOWED = 1;
|
|
41
|
+
const getIsDev = (options) => {
|
|
42
|
+
return options.development || window && window.location && window.location.host.includes("local") || ENV === "testing" || ENV === "development";
|
|
43
|
+
};
|
|
44
|
+
const getSocketUrl = (options, isDev) => {
|
|
45
|
+
const SOCKET_BACKEND_URL = isDev ? "http://localhost:8080/" : "https://api.symbols.app/";
|
|
46
|
+
const socketUrls = isArray(options.socketUrl) ? options.socketUrl : [options.socketUrl || SOCKET_BACKEND_URL];
|
|
47
|
+
const primaryUrl = socketUrls[0];
|
|
48
|
+
const secondaryUrl = socketUrls[1] || "api.symbols.app";
|
|
49
|
+
return {
|
|
50
|
+
primaryUrl: primaryUrl || SOCKET_BACKEND_URL,
|
|
51
|
+
secondaryUrl
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
const connect = (key, options = {}) => {
|
|
55
|
+
const isDev = getIsDev(options);
|
|
56
|
+
const { primaryUrl, secondaryUrl } = getSocketUrl(options, isDev);
|
|
57
|
+
const socket = (0, import_socket.default)(primaryUrl || secondaryUrl, {
|
|
58
|
+
// withCredentials: true
|
|
59
|
+
});
|
|
60
|
+
socket.on("connect", () => {
|
|
61
|
+
if (isDev) {
|
|
62
|
+
console.warn(
|
|
63
|
+
`Connected to %c${primaryUrl} %c${key} %c${socket.id}`,
|
|
64
|
+
"font-weight: bold; color: green;",
|
|
65
|
+
"font-weight: bold;",
|
|
66
|
+
""
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
socket.emit("initConnect", { key, ...options });
|
|
70
|
+
try {
|
|
71
|
+
if (isFunction(options.onConnect)) {
|
|
72
|
+
options.onConnect(socket.id, socket);
|
|
73
|
+
}
|
|
74
|
+
} catch (e) {
|
|
75
|
+
console.error(e);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
socket.on("connect_error", (err) => {
|
|
79
|
+
console.log(`event: connect_error | reason: ${err.message}`);
|
|
80
|
+
try {
|
|
81
|
+
if (isFunction(options.onError)) {
|
|
82
|
+
options.onError(err, socket);
|
|
83
|
+
}
|
|
84
|
+
if (CONNECT_ATTEPT < CONNECT_ATTEPT_MAX_ALLOWED) {
|
|
85
|
+
CONNECT_ATTEPT++;
|
|
86
|
+
socket.disconnect();
|
|
87
|
+
if (utils.isNotProduction()) {
|
|
88
|
+
console.log(
|
|
89
|
+
`Could not connect to %c${primaryUrl}%c, reconnecting to %c${secondaryUrl}`,
|
|
90
|
+
"font-weight: bold; color: red;",
|
|
91
|
+
"",
|
|
92
|
+
"font-weight: bold; color: green;"
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
connect(key, { ...options, socketUrl: secondaryUrl });
|
|
96
|
+
}
|
|
97
|
+
} catch (e) {
|
|
98
|
+
console.error(e);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
socket.on("disconnect", (reason) => {
|
|
102
|
+
console.log(`event: disconnect | reason: ${reason}`);
|
|
103
|
+
try {
|
|
104
|
+
if (isFunction(options.onDisconnect)) {
|
|
105
|
+
options.onDisconnect(reason, socket);
|
|
106
|
+
}
|
|
107
|
+
} catch (e) {
|
|
108
|
+
console.error(e);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
socket.onAny((event, ...args) => {
|
|
112
|
+
if (event === "connect") {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
try {
|
|
116
|
+
if (isFunction(options.onChange)) {
|
|
117
|
+
options.onChange(event, args[0], socket);
|
|
118
|
+
}
|
|
119
|
+
} catch (e) {
|
|
120
|
+
console.error(e);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
return socket;
|
|
124
|
+
};
|
|
125
|
+
function send(event = "change", changes, options) {
|
|
126
|
+
this.emit(event, changes, { ...options, ...defautlOpts });
|
|
127
|
+
}
|
|
128
|
+
function disconnect() {
|
|
129
|
+
this.disconnect();
|
|
130
|
+
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -26,69 +25,204 @@ __export(index_exports, {
|
|
|
26
25
|
});
|
|
27
26
|
module.exports = __toCommonJS(index_exports);
|
|
28
27
|
var import_router = require("@domql/router");
|
|
29
|
-
var
|
|
30
|
-
var
|
|
28
|
+
var import_smbls = require("smbls");
|
|
29
|
+
var import_socket = require("socket.io-client");
|
|
31
30
|
var import_utils = require("@domql/utils");
|
|
32
31
|
var import_SyncNotifications = require("./SyncNotifications");
|
|
33
32
|
var import_Inspect = require("./Inspect");
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const onChange = (el, s, ctx) => {
|
|
44
|
-
return (event, data) => {
|
|
45
|
-
if (event === "change") {
|
|
46
|
-
const obj = JSON.parse(data);
|
|
47
|
-
if (!(obj == null ? void 0 : obj.DATA)) return;
|
|
48
|
-
const { state, designSystem, pages, components, snippets, functions } = obj.DATA;
|
|
49
|
-
const { utils } = ctx;
|
|
50
|
-
if (pages) {
|
|
51
|
-
(0, import_utils.overwriteShallow)(ctx.pages, pages);
|
|
52
|
-
}
|
|
53
|
-
if (components) {
|
|
54
|
-
(0, import_utils.overwriteShallow)(ctx.components, components);
|
|
55
|
-
}
|
|
56
|
-
if (functions) {
|
|
57
|
-
(0, import_utils.overwriteShallow)(ctx.functions, functions);
|
|
33
|
+
const isLocal = process.env.NODE_ENV === "local";
|
|
34
|
+
const deletePath = (obj, path) => {
|
|
35
|
+
if (!obj || !Array.isArray(path)) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
path.reduce((acc, v, i, arr) => {
|
|
39
|
+
if (acc && v in acc) {
|
|
40
|
+
if (i !== arr.length - 1) {
|
|
41
|
+
return acc[v];
|
|
58
42
|
}
|
|
59
|
-
|
|
60
|
-
|
|
43
|
+
delete acc[v];
|
|
44
|
+
}
|
|
45
|
+
return void 0;
|
|
46
|
+
}, obj);
|
|
47
|
+
};
|
|
48
|
+
const setPath = (obj, path, value, createNestedObjects = false) => {
|
|
49
|
+
if (!obj || !Array.isArray(path)) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
path.reduce((acc, v, i, arr) => {
|
|
53
|
+
if (!acc) {
|
|
54
|
+
return void 0;
|
|
55
|
+
}
|
|
56
|
+
if (i !== arr.length - 1) {
|
|
57
|
+
if (!acc[v] && createNestedObjects) {
|
|
58
|
+
acc[v] = {};
|
|
61
59
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
60
|
+
return acc[v];
|
|
61
|
+
}
|
|
62
|
+
acc[v] = value;
|
|
63
|
+
return void 0;
|
|
64
|
+
}, obj);
|
|
65
|
+
};
|
|
66
|
+
const applyOpsToCtx = (ctx, changes) => {
|
|
67
|
+
const topLevelChanged = /* @__PURE__ */ new Set();
|
|
68
|
+
if (!Array.isArray(changes)) {
|
|
69
|
+
return topLevelChanged;
|
|
70
|
+
}
|
|
71
|
+
for (const [action, path, change] of changes) {
|
|
72
|
+
if (!Array.isArray(path) || !path.length) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
topLevelChanged.add(path[0]);
|
|
76
|
+
switch (action) {
|
|
77
|
+
case "delete":
|
|
78
|
+
deletePath(ctx, path);
|
|
79
|
+
break;
|
|
80
|
+
case "update":
|
|
81
|
+
case "set":
|
|
82
|
+
setPath(ctx, path, change, true);
|
|
83
|
+
break;
|
|
84
|
+
default:
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return topLevelChanged;
|
|
89
|
+
};
|
|
90
|
+
const fetchServiceToken = async () => {
|
|
91
|
+
try {
|
|
92
|
+
const urlBase = isLocal ? "http://localhost:8080" : "https://api.symbols.app";
|
|
93
|
+
const res = await import_utils.window.fetch(`${urlBase}/service-token`, {
|
|
94
|
+
method: "GET"
|
|
95
|
+
});
|
|
96
|
+
let txt;
|
|
97
|
+
try {
|
|
98
|
+
const json = await res.clone().json();
|
|
99
|
+
if (json && typeof json.token === "string") {
|
|
100
|
+
return json.token.trim();
|
|
66
101
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
102
|
+
txt = await res.text();
|
|
103
|
+
} catch {
|
|
104
|
+
txt = await res.text();
|
|
105
|
+
}
|
|
106
|
+
return (txt || "").replace(/\s+/gu, "") || void 0;
|
|
107
|
+
} catch (e) {
|
|
108
|
+
console.error("[sync] Failed to fetch service-token", e);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
const onSnapshot = (el, s, ctx) => (payload = {}) => {
|
|
112
|
+
let { data } = payload;
|
|
113
|
+
const { schema } = payload;
|
|
114
|
+
if (!data) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
data = el.call(
|
|
118
|
+
"deepDestringifyFunctions",
|
|
119
|
+
data,
|
|
120
|
+
Array.isArray(data) ? [] : {}
|
|
121
|
+
);
|
|
122
|
+
Object.entries(data).forEach(([key, val]) => {
|
|
123
|
+
if (ctx[key] && typeof ctx[key] === "object") {
|
|
124
|
+
if (key === "designSystem") {
|
|
125
|
+
(0, import_smbls.init)(val);
|
|
126
|
+
} else {
|
|
127
|
+
(0, import_utils.overwriteShallow)(ctx[key], val);
|
|
70
128
|
}
|
|
71
|
-
|
|
129
|
+
} else {
|
|
130
|
+
ctx[key] = val;
|
|
72
131
|
}
|
|
73
|
-
|
|
74
|
-
|
|
132
|
+
});
|
|
133
|
+
if (schema) {
|
|
134
|
+
ctx.schema = schema;
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
const onOps = (el, s, ctx) => (payload = {}) => {
|
|
138
|
+
let { changes } = payload;
|
|
139
|
+
if (!changes || !Array.isArray(changes) || !changes.length) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
changes = el.call(
|
|
143
|
+
"deepDestringifyFunctions",
|
|
144
|
+
changes,
|
|
145
|
+
Array.isArray(changes) ? [] : {}
|
|
146
|
+
);
|
|
147
|
+
const changed = applyOpsToCtx(ctx, changes);
|
|
148
|
+
if (changed.has("state")) {
|
|
149
|
+
const route = ctx.state?.route;
|
|
150
|
+
if (route) {
|
|
151
|
+
el.call(
|
|
152
|
+
"router",
|
|
153
|
+
route.replace("/state", "") || "/",
|
|
154
|
+
el.__ref.root,
|
|
155
|
+
{},
|
|
156
|
+
{ scrollToTop: false }
|
|
157
|
+
);
|
|
158
|
+
} else {
|
|
159
|
+
s.update(ctx.state);
|
|
75
160
|
}
|
|
76
|
-
}
|
|
161
|
+
}
|
|
162
|
+
if (["pages", "components", "snippets", "functions"].some(
|
|
163
|
+
(k) => changed.has(k)
|
|
164
|
+
)) {
|
|
165
|
+
const { pathname, search, hash } = ctx.window.location;
|
|
166
|
+
el.call(
|
|
167
|
+
"router",
|
|
168
|
+
pathname + search + hash,
|
|
169
|
+
el.__ref.root,
|
|
170
|
+
{},
|
|
171
|
+
{ scrollToTop: false }
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
if (changed.has("designSystem")) {
|
|
175
|
+
(0, import_smbls.init)(ctx.designSystem);
|
|
176
|
+
}
|
|
77
177
|
};
|
|
78
|
-
const connectToSocket = (el, s, ctx) => {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
178
|
+
const connectToSocket = async (el, s, ctx) => {
|
|
179
|
+
const token = await fetchServiceToken();
|
|
180
|
+
if (!token) {
|
|
181
|
+
console.warn("[sync] No service token \u2013 live collaboration disabled");
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
const projectKey = ctx.key;
|
|
185
|
+
if (!projectKey) {
|
|
186
|
+
console.warn(
|
|
187
|
+
"[sync] ctx.key missing \u2013 cannot establish collaborative connection"
|
|
188
|
+
);
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
const socketBaseUrl = isLocal ? "http://localhost:8080" : "https://api.symbols.app";
|
|
192
|
+
const socket = (0, import_socket.io)(socketBaseUrl, {
|
|
193
|
+
path: "/collab-socket",
|
|
194
|
+
transports: ["websocket"],
|
|
195
|
+
auth: {
|
|
196
|
+
token,
|
|
197
|
+
projectKey,
|
|
198
|
+
branch: "main",
|
|
199
|
+
live: true,
|
|
200
|
+
clientType: "platform"
|
|
201
|
+
},
|
|
202
|
+
reconnectionAttempts: Infinity,
|
|
203
|
+
reconnectionDelayMax: 4e3
|
|
204
|
+
});
|
|
205
|
+
socket.on("connect", () => {
|
|
206
|
+
if (ctx.editor?.verbose) {
|
|
207
|
+
console.info("[sync] Connected to collab socket");
|
|
208
|
+
}
|
|
86
209
|
});
|
|
210
|
+
socket.on("snapshot", onSnapshot(el, s, ctx));
|
|
211
|
+
socket.on("ops", onOps(el, s, ctx));
|
|
212
|
+
socket.on("clients", (data) => {
|
|
213
|
+
if (ctx.editor?.verbose) {
|
|
214
|
+
(0, import_SyncNotifications.connectedToSymbols)(data, el, s);
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
socket.on("disconnect", (reason) => {
|
|
218
|
+
if (ctx.editor?.verbose) {
|
|
219
|
+
console.info("[sync] Disconnected from collab socket", reason);
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
return socket;
|
|
87
223
|
};
|
|
88
224
|
const SyncComponent = {
|
|
89
|
-
|
|
90
|
-
initSync: connectToSocket
|
|
91
|
-
}
|
|
225
|
+
onInitSync: connectToSocket
|
|
92
226
|
};
|
|
93
227
|
const DefaultSyncApp = {
|
|
94
228
|
extends: [SyncComponent, import_Inspect.Inspect, import_SyncNotifications.Notifications]
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
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 server_exports = {};
|
|
30
|
+
__export(server_exports, {
|
|
31
|
+
sync: () => sync,
|
|
32
|
+
updateDynamycFile: () => updateDynamycFile
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(server_exports);
|
|
35
|
+
var import_fs = __toESM(require("fs"), 1);
|
|
36
|
+
var import_chalk = __toESM(require("chalk"), 1);
|
|
37
|
+
var import_express = __toESM(require("express"), 1);
|
|
38
|
+
var import_http = __toESM(require("http"), 1);
|
|
39
|
+
var import_socket = require("socket.io");
|
|
40
|
+
var import_module = require("module");
|
|
41
|
+
var utils = __toESM(require("@domql/utils"), 1);
|
|
42
|
+
const import_meta = {};
|
|
43
|
+
const { overwriteDeep } = utils.default || utils;
|
|
44
|
+
const require2 = (0, import_module.createRequire)(import_meta.url);
|
|
45
|
+
const DES_SYS_DEFAULT_FILE = require2("./dynamic.json");
|
|
46
|
+
const app = (0, import_express.default)();
|
|
47
|
+
let io;
|
|
48
|
+
const debugMsg = import_chalk.default.dim(
|
|
49
|
+
"Use --verbose to debug the error or open the issue at https://github.com/symbo-ls/smbls"
|
|
50
|
+
);
|
|
51
|
+
const updateDynamycFile = (changes, options = {}) => {
|
|
52
|
+
const { verbose, prettify, verboseCode } = options;
|
|
53
|
+
const file = require2("./dynamic.json");
|
|
54
|
+
const newMerge = overwriteDeep(file, changes);
|
|
55
|
+
const mergeStr = JSON.stringify(newMerge, null, 2);
|
|
56
|
+
const initPath = `${process.cwd()}/node_modules/@symbo.ls/init/dynamic.json`;
|
|
57
|
+
console.log(import_chalk.default.dim("\n----------------\n"));
|
|
58
|
+
console.log(import_chalk.default.dim("Received update:"));
|
|
59
|
+
console.log(Object.keys(changes).join(", "));
|
|
60
|
+
if (verboseCode)
|
|
61
|
+
console.log(import_chalk.default.dim(JSON.stringify(changes, null, prettify ?? 2)));
|
|
62
|
+
try {
|
|
63
|
+
import_fs.default.writeFileSync(initPath, mergeStr);
|
|
64
|
+
if (verbose) {
|
|
65
|
+
console.log(import_chalk.default.bold.green("\nChanges wrote to the file"));
|
|
66
|
+
}
|
|
67
|
+
} catch (e) {
|
|
68
|
+
console.log("");
|
|
69
|
+
console.log(import_chalk.default.bold.red("Error writing file"));
|
|
70
|
+
if (verbose) {
|
|
71
|
+
console.error(e);
|
|
72
|
+
} else {
|
|
73
|
+
console.log(debugMsg);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const sync = (desSysFile = DES_SYS_DEFAULT_FILE, opts = {}) => {
|
|
78
|
+
const server = import_http.default.createServer(app);
|
|
79
|
+
const { key } = opts;
|
|
80
|
+
io = new import_socket.Server(server, {
|
|
81
|
+
transports: ["websocket", "polling", "flashsocket"],
|
|
82
|
+
cors: {
|
|
83
|
+
origin: "*"
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
app.get("/", (req, res) => {
|
|
87
|
+
res.end("open");
|
|
88
|
+
});
|
|
89
|
+
io.on("connection", (socket) => {
|
|
90
|
+
socket.join(key);
|
|
91
|
+
let source;
|
|
92
|
+
socket.on("initConnect", (options) => {
|
|
93
|
+
const { clientsCount } = io.engine;
|
|
94
|
+
socket.to(key).emit("clientsCount", clientsCount);
|
|
95
|
+
source = options.source;
|
|
96
|
+
console.log("Connected", key, source);
|
|
97
|
+
console.log("from", options.location);
|
|
98
|
+
});
|
|
99
|
+
socket.on("components", (data, options) => {
|
|
100
|
+
io.to(key).emit("change", data, options);
|
|
101
|
+
});
|
|
102
|
+
socket.on("route", (data, options) => {
|
|
103
|
+
io.to(key).emit("route", data, options);
|
|
104
|
+
});
|
|
105
|
+
socket.on("change", updateDynamycFile);
|
|
106
|
+
socket.on("disconnect", (changes, options) => {
|
|
107
|
+
const { clientsCount } = io.engine;
|
|
108
|
+
socket.to(key).emit("clientsCount", clientsCount);
|
|
109
|
+
console.log("Disconnected", key, source);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
server.listen(13336, () => {
|
|
113
|
+
console.log("listening on *:13336");
|
|
114
|
+
});
|
|
115
|
+
};
|
package/dist/esm/Inspect.js
CHANGED
|
@@ -1,21 +1,6 @@
|
|
|
1
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
2
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
3
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
4
|
-
var __objRest = (source, exclude) => {
|
|
5
|
-
var target = {};
|
|
6
|
-
for (var prop in source)
|
|
7
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
8
|
-
target[prop] = source[prop];
|
|
9
|
-
if (source != null && __getOwnPropSymbols)
|
|
10
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
11
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
12
|
-
target[prop] = source[prop];
|
|
13
|
-
}
|
|
14
|
-
return target;
|
|
15
|
-
};
|
|
16
1
|
import * as smblsUI from "@symbo.ls/uikit";
|
|
17
2
|
import { isObject, isString, isArray } from "@domql/utils";
|
|
18
|
-
import { send } from "
|
|
3
|
+
import { send } from "./client.js";
|
|
19
4
|
function returnStringExtend(_extends) {
|
|
20
5
|
return isString(_extends) ? _extends : isArray(_extends) ? _extends.find((extItem) => isString(extItem)) : "";
|
|
21
6
|
}
|
|
@@ -139,7 +124,7 @@ const Inspect = {
|
|
|
139
124
|
onInit: ({ context }) => {
|
|
140
125
|
const { components } = context;
|
|
141
126
|
if (isObject(components)) {
|
|
142
|
-
const
|
|
127
|
+
const { Content, ...rest } = components;
|
|
143
128
|
for (const key in rest) {
|
|
144
129
|
if (smblsUI[key]) continue;
|
|
145
130
|
if (!rest[key].__ref) rest[key].__ref = {};
|