@symbo.ls/sync 2.11.454 → 2.11.460

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.
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,212 @@
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/uikit"), 1);
35
+ var import_utils = require("@domql/utils");
36
+ var import_client = require("@symbo.ls/socket/client");
37
+ function returnStringExtend(extend) {
38
+ return (0, import_utils.isString)(extend) ? extend : (0, import_utils.isArray)(extend) ? extend.find((extItem) => (0, import_utils.isString)(extItem)) : "";
39
+ }
40
+ function getComponentKey(el) {
41
+ if (!el)
42
+ return;
43
+ const __componentKey = el.__ref.__componentKey;
44
+ const extendStr = el.extend && returnStringExtend(el.extend);
45
+ const parentChildExtendStr = el.parent && el.parent.childExtend && returnStringExtend(el.parent.childExtend);
46
+ return (__componentKey || extendStr || parentChildExtendStr || "").split("_")[0].split(".")[0].split("+")[0];
47
+ }
48
+ function findComponent(el) {
49
+ if (!el || !el.__ref)
50
+ return;
51
+ const { components, pages, editor } = el.context;
52
+ const componentKey = getComponentKey(el);
53
+ if (editor && editor.onInitInspect) {
54
+ const initInspectReturns = editor.onInitInspect(componentKey, el, el.state);
55
+ if (!initInspectReturns)
56
+ return findComponent(el.parent);
57
+ }
58
+ if (componentKey && (components[componentKey] || pages[componentKey])) {
59
+ return el;
60
+ }
61
+ return findComponent(el.parent);
62
+ }
63
+ const inspectOnKey = (app, state, ctx) => {
64
+ const windowOpts = ctx.window || window;
65
+ windowOpts.onkeydown = (ev) => {
66
+ if (ev.altKey && ev.shiftKey) {
67
+ app.state.update({ debugging: true, preventSelect: true }, {
68
+ preventUpdate: true,
69
+ preventContentUpdate: true,
70
+ preventRecursive: true
71
+ });
72
+ }
73
+ };
74
+ windowOpts.onkeyup = (ev) => {
75
+ if (app.state.preventSelect && (!ev.altKey || !ev.shiftKey)) {
76
+ app.state.replace({ debugging: false, preventSelect: false }, {
77
+ preventUpdate: true,
78
+ preventContentUpdate: true,
79
+ preventRecursive: true
80
+ });
81
+ app.Inspector.state.update({ area: false });
82
+ }
83
+ };
84
+ };
85
+ const Inspect = {
86
+ props: {
87
+ ".preventSelect": { userSelect: "none" },
88
+ "!preventSelect": { userSelect: "auto" }
89
+ },
90
+ Inspector: {
91
+ state: {},
92
+ props: (el, s) => ({
93
+ transition: "all, defaultBezier, X",
94
+ position: "fixed",
95
+ hide: !(s.area && s.parent.debugging),
96
+ style: {
97
+ boxShadow: "0 0 10px #3686F733, 0 0 0 3px #3686F766, 0 0 100vmax 100vmax #000A",
98
+ zIndex: "9999999",
99
+ borderRadius: "10px",
100
+ pointerEvents: "none"
101
+ }
102
+ }),
103
+ span: {
104
+ props: {
105
+ position: "absolute",
106
+ margin: "A2 0",
107
+ fontSize: "Z",
108
+ color: "text",
109
+ // color: 'blue',
110
+ zIndex: "99999999",
111
+ transition: "all, defaultBezier, X",
112
+ textDecoration: "underline",
113
+ fontWeight: "500",
114
+ top: "100%",
115
+ style: {
116
+ boxShadow: "0 25px 10px 35px black",
117
+ textShadow: "0 0 10px black"
118
+ },
119
+ text: "{{ focusKey }}"
120
+ }
121
+ },
122
+ on: {
123
+ init: ({ context }) => {
124
+ const { components } = context;
125
+ if ((0, import_utils.isObject)(components)) {
126
+ const { Content, ...rest } = components;
127
+ for (const key in rest) {
128
+ if (smblsUI[key])
129
+ continue;
130
+ if (!rest[key].__ref)
131
+ rest[key].__ref = {};
132
+ if (!rest[key].__ref.__componentKey) {
133
+ rest[key].__ref.__componentKey = key;
134
+ }
135
+ }
136
+ }
137
+ },
138
+ beforeUpdate: (ch, el, s) => {
139
+ const { area } = s;
140
+ const isDebugging = s.area && s.parent.debugging;
141
+ let style;
142
+ if (!isDebugging) {
143
+ style = "display: none !important";
144
+ } else if (area) {
145
+ const { x, y, width, height } = area;
146
+ style = `
147
+ display: block !important;
148
+ top: ${y - 6}px;
149
+ left: ${x - 6}px;
150
+ width: ${width + 12}px;
151
+ height: ${height + 12}px;
152
+ `;
153
+ }
154
+ el.node.style = style;
155
+ el.span.node.innerText = s.focusKey;
156
+ return false;
157
+ }
158
+ }
159
+ },
160
+ on: {
161
+ inspectOnKey,
162
+ mousemove: (ev, e, state) => {
163
+ const el = ev.target.ref;
164
+ const component = findComponent(el);
165
+ const focusState = e.Inspector.state;
166
+ if (!component || !state.debugging || !component.__ref)
167
+ return focusState.update({ area: false });
168
+ const componentKey = getComponentKey(component);
169
+ const updateValue = (area) => {
170
+ focusState.update({ area, focusKey: componentKey });
171
+ };
172
+ const update = () => {
173
+ if (ev.altKey && ev.shiftKey) {
174
+ const { x, y, width, height } = component.node.getBoundingClientRect();
175
+ const area = { x, y, width, height };
176
+ if (!focusState.area)
177
+ return updateValue(area);
178
+ if (focusState.area.x !== area.x)
179
+ updateValue(area);
180
+ } else if (focusState.area) {
181
+ focusState.update({ area: false });
182
+ }
183
+ };
184
+ window.requestAnimationFrame(() => {
185
+ update();
186
+ window.requestAnimationFrame(update);
187
+ });
188
+ },
189
+ mousedown: (ev, elem, state) => {
190
+ if (!state.debugging)
191
+ return;
192
+ const el = ev.target.ref;
193
+ const component = findComponent(el);
194
+ if (!component)
195
+ return;
196
+ const componentKey = getComponentKey(component);
197
+ if (!componentKey)
198
+ return;
199
+ const editor = el.context.editor;
200
+ if (editor && editor.onInspect) {
201
+ return editor.onInspect(componentKey, el, el.state, { allowRouterWhileInspect: true });
202
+ }
203
+ const data = JSON.stringify({
204
+ componentKey: `${componentKey}`
205
+ });
206
+ import_client.send.call(el.context.socket, "route", data);
207
+ ev.preventDefault();
208
+ ev.stopPropagation();
209
+ return false;
210
+ }
211
+ }
212
+ };
@@ -0,0 +1,103 @@
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 Notifications_exports = {};
20
+ __export(Notifications_exports, {
21
+ Notifications: () => Notifications,
22
+ connectedToSymbols: () => connectedToSymbols
23
+ });
24
+ module.exports = __toCommonJS(Notifications_exports);
25
+ const NOTIF_COLORS = {
26
+ success: "green",
27
+ error: "red",
28
+ warning: "yellow"
29
+ };
30
+ const connectedToSymbols = (clients, element, state) => {
31
+ console.log(clients);
32
+ if (clients.symbols) {
33
+ if (!state.connected) {
34
+ state.notifications.connected = {
35
+ title: "Connected",
36
+ message: "to the Symbols live server"
37
+ };
38
+ state.update({ connected: true });
39
+ const t = setTimeout(() => {
40
+ delete state.notifications.connected;
41
+ element.notifications.content.connected.setProps({ animation: "fadeOutDown" });
42
+ state.update({ connected: true });
43
+ clearTimeout(t);
44
+ }, 3e3);
45
+ }
46
+ } else {
47
+ if (state.connected) {
48
+ state.notifications.connected = {
49
+ title: "Disconnected",
50
+ type: "error"
51
+ };
52
+ state.update({ connected: false });
53
+ const t = setTimeout(() => {
54
+ delete state.notifications.connected;
55
+ if (element.notifications.content.connected) {
56
+ element.notifications.content.connected.setProps({ animation: "fadeOutDown" });
57
+ }
58
+ state.update({ connected: true });
59
+ clearTimeout(t);
60
+ }, 3e3);
61
+ }
62
+ }
63
+ };
64
+ const Notifications = {
65
+ state: {
66
+ notifications: []
67
+ },
68
+ Notifications: {
69
+ props: {
70
+ position: "fixed",
71
+ left: "A2",
72
+ bottom: "Z2",
73
+ zIndex: "999"
74
+ },
75
+ childExtend: {
76
+ extend: "Notification",
77
+ props: ({ 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.setProps({ animation: "fadeInUp" });
91
+ },
92
+ onClick: (e, el, s) => {
93
+ delete s.notifications[el.key];
94
+ el.setProps({ animation: "fadeOutDown" });
95
+ if (s.onClose)
96
+ s.onClose(e, el, s);
97
+ }
98
+ }),
99
+ IconText: null
100
+ },
101
+ $stateCollection: ({ state }) => state.notifications
102
+ }
103
+ };
@@ -0,0 +1,99 @@
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var sync_exports = {};
21
+ __export(sync_exports, {
22
+ DefaultSyncApp: () => DefaultSyncApp,
23
+ SyncComponent: () => SyncComponent,
24
+ connectToSocket: () => connectToSocket
25
+ });
26
+ module.exports = __toCommonJS(sync_exports);
27
+ var import_router = require("@domql/router");
28
+ var import_init = require("@symbo.ls/init");
29
+ var import_client = require("@symbo.ls/socket/client");
30
+ var import_globals = require("@domql/globals");
31
+ var import_utils = require("@domql/utils");
32
+ var import_Notifications = require("./Notifications");
33
+ var import_Inspect = require("./Inspect");
34
+ __reExport(sync_exports, require("./DefaultSyncApp"), module.exports);
35
+ __reExport(sync_exports, require("./Notifications"), module.exports);
36
+ __reExport(sync_exports, require("./Inspect"), module.exports);
37
+ const isLocalhost = import_globals.window && import_globals.window.location && import_globals.window.location.host.includes("local");
38
+ const onConnect = (element, state) => {
39
+ return (socketId, socket) => {
40
+ };
41
+ };
42
+ const onDisconnect = (element, state) => {
43
+ return () => {
44
+ };
45
+ };
46
+ const onChange = (el, s, ctx) => {
47
+ return (event, data) => {
48
+ if (event === "change") {
49
+ const obj = JSON.parse(data);
50
+ if (!(obj == null ? void 0 : obj.DATA))
51
+ return;
52
+ const { state, designSystem, pages, components, snippets } = obj.DATA;
53
+ const { utils } = ctx;
54
+ if (pages) {
55
+ (0, import_utils.overwriteShallow)(ctx.pages, pages);
56
+ }
57
+ if (components) {
58
+ (0, import_utils.overwriteShallow)(ctx.components, components);
59
+ }
60
+ if (snippets) {
61
+ (0, import_utils.overwriteShallow)(ctx.snippets, snippets);
62
+ }
63
+ if (state) {
64
+ const route = state.route;
65
+ if (route)
66
+ (utils.router || import_router.router)(route.replace("/state", "") || "/", el, {});
67
+ else if (!(snippets && components && pages))
68
+ s.update(state);
69
+ }
70
+ if (snippets || components || pages) {
71
+ const { pathname, search, hash } = ctx.window.location;
72
+ (utils.router || import_router.router)(pathname + search + hash, el, {});
73
+ }
74
+ if (designSystem)
75
+ (0, import_init.init)(designSystem);
76
+ }
77
+ if (ctx.editor.verbose && event === "clients") {
78
+ (0, import_Notifications.connectedToSymbols)(data, el, s);
79
+ }
80
+ };
81
+ };
82
+ const connectToSocket = (el, s, ctx) => {
83
+ return (0, import_client.connect)(ctx.key, {
84
+ source: isLocalhost ? "localhost" : "client",
85
+ socketUrl: isLocalhost ? "localhost:13336" : "socket.symbols.app",
86
+ location: import_globals.window.location.host,
87
+ onConnect: onConnect(el, s, ctx),
88
+ onDisconnect: onDisconnect(el, s, ctx),
89
+ onChange: onChange(el, s, ctx)
90
+ });
91
+ };
92
+ const SyncComponent = {
93
+ on: {
94
+ initSync: connectToSocket
95
+ }
96
+ };
97
+ const DefaultSyncApp = {
98
+ extend: [SyncComponent, import_Inspect.Inspect, import_Notifications.Notifications]
99
+ };
@@ -0,0 +1,4 @@
1
+ {
2
+ "type": "commonjs",
3
+ "main": "index.js"
4
+ }
File without changes
@@ -0,0 +1,197 @@
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
+ import * as smblsUI from "@symbo.ls/uikit";
17
+ import { isObject, isString, isArray } from "@domql/utils";
18
+ import { send } from "@symbo.ls/socket/client";
19
+ function returnStringExtend(extend) {
20
+ return isString(extend) ? extend : isArray(extend) ? extend.find((extItem) => isString(extItem)) : "";
21
+ }
22
+ function getComponentKey(el) {
23
+ if (!el)
24
+ return;
25
+ const __componentKey = el.__ref.__componentKey;
26
+ const extendStr = el.extend && returnStringExtend(el.extend);
27
+ const parentChildExtendStr = el.parent && el.parent.childExtend && returnStringExtend(el.parent.childExtend);
28
+ return (__componentKey || extendStr || parentChildExtendStr || "").split("_")[0].split(".")[0].split("+")[0];
29
+ }
30
+ function findComponent(el) {
31
+ if (!el || !el.__ref)
32
+ return;
33
+ const { components, pages, editor } = el.context;
34
+ const componentKey = getComponentKey(el);
35
+ if (editor && editor.onInitInspect) {
36
+ const initInspectReturns = editor.onInitInspect(componentKey, el, el.state);
37
+ if (!initInspectReturns)
38
+ return findComponent(el.parent);
39
+ }
40
+ if (componentKey && (components[componentKey] || pages[componentKey])) {
41
+ return el;
42
+ }
43
+ return findComponent(el.parent);
44
+ }
45
+ const inspectOnKey = (app, state, ctx) => {
46
+ const windowOpts = ctx.window || window;
47
+ windowOpts.onkeydown = (ev) => {
48
+ if (ev.altKey && ev.shiftKey) {
49
+ app.state.update({ debugging: true, preventSelect: true }, {
50
+ preventUpdate: true,
51
+ preventContentUpdate: true,
52
+ preventRecursive: true
53
+ });
54
+ }
55
+ };
56
+ windowOpts.onkeyup = (ev) => {
57
+ if (app.state.preventSelect && (!ev.altKey || !ev.shiftKey)) {
58
+ app.state.replace({ debugging: false, preventSelect: false }, {
59
+ preventUpdate: true,
60
+ preventContentUpdate: true,
61
+ preventRecursive: true
62
+ });
63
+ app.Inspector.state.update({ area: false });
64
+ }
65
+ };
66
+ };
67
+ const Inspect = {
68
+ props: {
69
+ ".preventSelect": { userSelect: "none" },
70
+ "!preventSelect": { userSelect: "auto" }
71
+ },
72
+ Inspector: {
73
+ state: {},
74
+ props: (el, s) => ({
75
+ transition: "all, defaultBezier, X",
76
+ position: "fixed",
77
+ hide: !(s.area && s.parent.debugging),
78
+ style: {
79
+ boxShadow: "0 0 10px #3686F733, 0 0 0 3px #3686F766, 0 0 100vmax 100vmax #000A",
80
+ zIndex: "9999999",
81
+ borderRadius: "10px",
82
+ pointerEvents: "none"
83
+ }
84
+ }),
85
+ span: {
86
+ props: {
87
+ position: "absolute",
88
+ margin: "A2 0",
89
+ fontSize: "Z",
90
+ color: "text",
91
+ // color: 'blue',
92
+ zIndex: "99999999",
93
+ transition: "all, defaultBezier, X",
94
+ textDecoration: "underline",
95
+ fontWeight: "500",
96
+ top: "100%",
97
+ style: {
98
+ boxShadow: "0 25px 10px 35px black",
99
+ textShadow: "0 0 10px black"
100
+ },
101
+ text: "{{ focusKey }}"
102
+ }
103
+ },
104
+ on: {
105
+ init: ({ context }) => {
106
+ const { components } = context;
107
+ if (isObject(components)) {
108
+ const _a = components, { Content } = _a, rest = __objRest(_a, ["Content"]);
109
+ for (const key in rest) {
110
+ if (smblsUI[key])
111
+ continue;
112
+ if (!rest[key].__ref)
113
+ rest[key].__ref = {};
114
+ if (!rest[key].__ref.__componentKey) {
115
+ rest[key].__ref.__componentKey = key;
116
+ }
117
+ }
118
+ }
119
+ },
120
+ beforeUpdate: (ch, el, s) => {
121
+ const { area } = s;
122
+ const isDebugging = s.area && s.parent.debugging;
123
+ let style;
124
+ if (!isDebugging) {
125
+ style = "display: none !important";
126
+ } else if (area) {
127
+ const { x, y, width, height } = area;
128
+ style = `
129
+ display: block !important;
130
+ top: ${y - 6}px;
131
+ left: ${x - 6}px;
132
+ width: ${width + 12}px;
133
+ height: ${height + 12}px;
134
+ `;
135
+ }
136
+ el.node.style = style;
137
+ el.span.node.innerText = s.focusKey;
138
+ return false;
139
+ }
140
+ }
141
+ },
142
+ on: {
143
+ inspectOnKey,
144
+ mousemove: (ev, e, state) => {
145
+ const el = ev.target.ref;
146
+ const component = findComponent(el);
147
+ const focusState = e.Inspector.state;
148
+ if (!component || !state.debugging || !component.__ref)
149
+ return focusState.update({ area: false });
150
+ const componentKey = getComponentKey(component);
151
+ const updateValue = (area) => {
152
+ focusState.update({ area, focusKey: componentKey });
153
+ };
154
+ const update = () => {
155
+ if (ev.altKey && ev.shiftKey) {
156
+ const { x, y, width, height } = component.node.getBoundingClientRect();
157
+ const area = { x, y, width, height };
158
+ if (!focusState.area)
159
+ return updateValue(area);
160
+ if (focusState.area.x !== area.x)
161
+ updateValue(area);
162
+ } else if (focusState.area) {
163
+ focusState.update({ area: false });
164
+ }
165
+ };
166
+ window.requestAnimationFrame(() => {
167
+ update();
168
+ window.requestAnimationFrame(update);
169
+ });
170
+ },
171
+ mousedown: (ev, elem, state) => {
172
+ if (!state.debugging)
173
+ return;
174
+ const el = ev.target.ref;
175
+ const component = findComponent(el);
176
+ if (!component)
177
+ return;
178
+ const componentKey = getComponentKey(component);
179
+ if (!componentKey)
180
+ return;
181
+ const editor = el.context.editor;
182
+ if (editor && editor.onInspect) {
183
+ return editor.onInspect(componentKey, el, el.state, { allowRouterWhileInspect: true });
184
+ }
185
+ const data = JSON.stringify({
186
+ componentKey: `${componentKey}`
187
+ });
188
+ send.call(el.context.socket, "route", data);
189
+ ev.preventDefault();
190
+ ev.stopPropagation();
191
+ return false;
192
+ }
193
+ }
194
+ };
195
+ export {
196
+ Inspect
197
+ };
@@ -0,0 +1,83 @@
1
+ const NOTIF_COLORS = {
2
+ success: "green",
3
+ error: "red",
4
+ warning: "yellow"
5
+ };
6
+ const connectedToSymbols = (clients, element, state) => {
7
+ console.log(clients);
8
+ if (clients.symbols) {
9
+ if (!state.connected) {
10
+ state.notifications.connected = {
11
+ title: "Connected",
12
+ message: "to the Symbols live server"
13
+ };
14
+ state.update({ connected: true });
15
+ const t = setTimeout(() => {
16
+ delete state.notifications.connected;
17
+ element.notifications.content.connected.setProps({ animation: "fadeOutDown" });
18
+ state.update({ connected: true });
19
+ clearTimeout(t);
20
+ }, 3e3);
21
+ }
22
+ } else {
23
+ if (state.connected) {
24
+ state.notifications.connected = {
25
+ title: "Disconnected",
26
+ type: "error"
27
+ };
28
+ state.update({ connected: false });
29
+ const t = setTimeout(() => {
30
+ delete state.notifications.connected;
31
+ if (element.notifications.content.connected) {
32
+ element.notifications.content.connected.setProps({ animation: "fadeOutDown" });
33
+ }
34
+ state.update({ connected: true });
35
+ clearTimeout(t);
36
+ }, 3e3);
37
+ }
38
+ }
39
+ };
40
+ const Notifications = {
41
+ state: {
42
+ notifications: []
43
+ },
44
+ Notifications: {
45
+ props: {
46
+ position: "fixed",
47
+ left: "A2",
48
+ bottom: "Z2",
49
+ zIndex: "999"
50
+ },
51
+ childExtend: {
52
+ extend: "Notification",
53
+ props: ({ state }) => ({
54
+ animationDuration: "C",
55
+ background: NOTIF_COLORS[state.type || "success"],
56
+ icon: null,
57
+ Flex: {
58
+ Title: {
59
+ text: "{{ title }}"
60
+ },
61
+ P: {
62
+ text: "{{ title }}"
63
+ }
64
+ },
65
+ onRender: (e, el, s) => {
66
+ el.setProps({ animation: "fadeInUp" });
67
+ },
68
+ onClick: (e, el, s) => {
69
+ delete s.notifications[el.key];
70
+ el.setProps({ animation: "fadeOutDown" });
71
+ if (s.onClose)
72
+ s.onClose(e, el, s);
73
+ }
74
+ }),
75
+ IconText: null
76
+ },
77
+ $stateCollection: ({ state }) => state.notifications
78
+ }
79
+ };
80
+ export {
81
+ Notifications,
82
+ connectedToSymbols
83
+ };
@@ -0,0 +1,78 @@
1
+ import { router } from "@domql/router";
2
+ import { init } from "@symbo.ls/init";
3
+ import { connect } from "@symbo.ls/socket/client";
4
+ import { window } from "@domql/globals";
5
+ import { overwriteShallow } from "@domql/utils";
6
+ import { connectedToSymbols, Notifications } from "./Notifications";
7
+ import { Inspect } from "./Inspect";
8
+ export * from "./DefaultSyncApp";
9
+ export * from "./Notifications";
10
+ export * from "./Inspect";
11
+ const isLocalhost = window && window.location && window.location.host.includes("local");
12
+ const onConnect = (element, state) => {
13
+ return (socketId, socket) => {
14
+ };
15
+ };
16
+ const onDisconnect = (element, state) => {
17
+ return () => {
18
+ };
19
+ };
20
+ const onChange = (el, s, ctx) => {
21
+ return (event, data) => {
22
+ if (event === "change") {
23
+ const obj = JSON.parse(data);
24
+ if (!(obj == null ? void 0 : obj.DATA))
25
+ return;
26
+ const { state, designSystem, pages, components, snippets } = obj.DATA;
27
+ const { utils } = ctx;
28
+ if (pages) {
29
+ overwriteShallow(ctx.pages, pages);
30
+ }
31
+ if (components) {
32
+ overwriteShallow(ctx.components, components);
33
+ }
34
+ if (snippets) {
35
+ overwriteShallow(ctx.snippets, snippets);
36
+ }
37
+ if (state) {
38
+ const route = state.route;
39
+ if (route)
40
+ (utils.router || router)(route.replace("/state", "") || "/", el, {});
41
+ else if (!(snippets && components && pages))
42
+ s.update(state);
43
+ }
44
+ if (snippets || components || pages) {
45
+ const { pathname, search, hash } = ctx.window.location;
46
+ (utils.router || router)(pathname + search + hash, el, {});
47
+ }
48
+ if (designSystem)
49
+ init(designSystem);
50
+ }
51
+ if (ctx.editor.verbose && event === "clients") {
52
+ connectedToSymbols(data, el, s);
53
+ }
54
+ };
55
+ };
56
+ const connectToSocket = (el, s, ctx) => {
57
+ return connect(ctx.key, {
58
+ source: isLocalhost ? "localhost" : "client",
59
+ socketUrl: isLocalhost ? "localhost:13336" : "socket.symbols.app",
60
+ location: window.location.host,
61
+ onConnect: onConnect(el, s, ctx),
62
+ onDisconnect: onDisconnect(el, s, ctx),
63
+ onChange: onChange(el, s, ctx)
64
+ });
65
+ };
66
+ const SyncComponent = {
67
+ on: {
68
+ initSync: connectToSocket
69
+ }
70
+ };
71
+ const DefaultSyncApp = {
72
+ extend: [SyncComponent, Inspect, Notifications]
73
+ };
74
+ export {
75
+ DefaultSyncApp,
76
+ SyncComponent,
77
+ connectToSocket
78
+ };
package/index.js CHANGED
@@ -5,7 +5,12 @@ import { init } from '@symbo.ls/init'
5
5
  import { connect } from '@symbo.ls/socket/client'
6
6
  import { window } from '@domql/globals'
7
7
  import { overwriteShallow } from '@domql/utils'
8
- import { connectedToSymbols } from './Notifications'
8
+ import { connectedToSymbols, Notifications } from './Notifications'
9
+ import { Inspect } from './Inspect'
10
+
11
+ export * from './DefaultSyncApp'
12
+ export * from './Notifications'
13
+ export * from './Inspect'
9
14
 
10
15
  const isLocalhost = window && window.location && window.location.host.includes('local')
11
16
 
@@ -76,3 +81,7 @@ export const SyncComponent = {
76
81
  initSync: connectToSocket
77
82
  }
78
83
  }
84
+
85
+ export const DefaultSyncApp = {
86
+ extend: [SyncComponent, Inspect, Notifications]
87
+ }
package/package.json CHANGED
@@ -1,9 +1,33 @@
1
1
  {
2
2
  "name": "@symbo.ls/sync",
3
- "version": "2.11.454",
3
+ "version": "2.11.460",
4
4
  "main": "index.js",
5
5
  "module": "index.js",
6
- "gitHead": "c00f58d1f3abb27367daa3a488580d7a82221e6d",
6
+ "gitHead": "30d3c30e9f5333b79479ce137b579e048547cafe",
7
+ "files": [
8
+ "src",
9
+ "dist"
10
+ ],
11
+ "repository": "https://github.com/symbo-ls/scratch",
12
+ "type": "module",
13
+ "unpkg": "dist/iife/index.js",
14
+ "jsdelivr": "dist/iife/index.js",
15
+ "exports": {
16
+ ".": {
17
+ "kalduna": "./index.js",
18
+ "default": "./dist/cjs/index.js"
19
+ }
20
+ },
21
+ "source": "index.js",
22
+ "publishConfig": {},
23
+ "scripts": {
24
+ "copy:package:cjs": "cp ../../build/package-cjs.json dist/cjs/package.json",
25
+ "build:esm": "npx esbuild *.js --target=es2017 --format=esm --outdir=dist/esm --loader:.svg=text",
26
+ "build:cjs": "npx esbuild *.js --target=node16 --format=cjs --outdir=dist/cjs --loader:.svg=text",
27
+ "build:iife": "npx esbuild ./index.js --target=es2017 --format=iife --outdir=dist/iife --loader:.svg=text --bundle --minify",
28
+ "build": "yarn build:esm; yarn build:cjs",
29
+ "prepublish": "rimraf -I dist && yarn build && yarn copy:package:cjs"
30
+ },
7
31
  "dependencies": {
8
32
  "@domql/globals": "latest",
9
33
  "@domql/router": "^2.5.0",
@@ -11,6 +35,9 @@
11
35
  "@symbo.ls/init": "^2.11.453",
12
36
  "@symbo.ls/scratch": "^2.11.453",
13
37
  "@symbo.ls/socket": "^2.11.453",
14
- "@symbo.ls/uikit": "^2.11.454"
38
+ "@symbo.ls/uikit": "^2.11.455"
39
+ },
40
+ "devDependencies": {
41
+ "@babel/core": "^7.12.0"
15
42
  }
16
43
  }
package/DefaultSyncApp.js DELETED
@@ -1,9 +0,0 @@
1
- 'use strict'
2
-
3
- import { SyncComponent } from './index'
4
- import { Inspect } from './Inspect'
5
- import { Notifications } from './Notifications'
6
-
7
- export const DefaultSyncApp = {
8
- extend: [SyncComponent, Inspect, Notifications]
9
- }
package/Inspect.js DELETED
@@ -1,197 +0,0 @@
1
- 'use strict'
2
-
3
- import * as smblsUI from '@symbo.ls/uikit'
4
- import { isObject, isString, isArray } from '@domql/utils'
5
- import { send } from '@symbo.ls/socket/client'
6
-
7
- function returnStringExtend (extend) {
8
- return isString(extend) ? extend : isArray(extend) ? extend.find(extItem => isString(extItem)) : ''
9
- }
10
-
11
- function getComponentKey (el) {
12
- if (!el) return
13
- const __componentKey = el.__ref.__componentKey
14
- const extendStr = el.extend && returnStringExtend(el.extend)
15
- const parentChildExtendStr = el.parent && el.parent.childExtend && returnStringExtend(el.parent.childExtend)
16
- return (__componentKey || extendStr || 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 inspectOnKey = (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
- props: {
58
- '.preventSelect': { userSelect: 'none' },
59
- '!preventSelect': { userSelect: 'auto' }
60
- },
61
-
62
- Inspector: {
63
- state: {},
64
- props: (el, s) => ({
65
- transition: 'all, defaultBezier, X',
66
- position: 'fixed',
67
- hide: !(s.area && s.parent.debugging),
68
- style: {
69
- boxShadow: '0 0 10px #3686F733, 0 0 0 3px #3686F766, 0 0 100vmax 100vmax #000A',
70
- zIndex: '9999999',
71
- borderRadius: '10px',
72
- pointerEvents: 'none'
73
- }
74
- }),
75
-
76
- span: {
77
- props: {
78
- position: 'absolute',
79
- margin: 'A2 0',
80
- fontSize: 'Z',
81
- color: 'text',
82
- // color: 'blue',
83
- zIndex: '99999999',
84
- transition: 'all, defaultBezier, X',
85
- textDecoration: 'underline',
86
- fontWeight: '500',
87
- top: '100%',
88
- style: {
89
- boxShadow: '0 25px 10px 35px black',
90
- textShadow: '0 0 10px black'
91
- },
92
- text: '{{ focusKey }}'
93
- }
94
- },
95
-
96
- on: {
97
- init: ({ context }) => {
98
- const { components } = context
99
-
100
- if (isObject(components)) {
101
- const { Content, ...rest } = components
102
- for (const key in rest) {
103
- if (smblsUI[key]) continue
104
- if (!rest[key].__ref) rest[key].__ref = {}
105
- if (!rest[key].__ref.__componentKey) {
106
- rest[key].__ref.__componentKey = key
107
- }
108
- }
109
- }
110
- },
111
- beforeUpdate: (ch, el, s) => {
112
- const { area } = s
113
- const isDebugging = s.area && s.parent.debugging
114
-
115
- let style
116
- if (!isDebugging) {
117
- style = 'display: none !important'
118
- } else if (area) {
119
- const { x, y, width, height } = area
120
- // el.node.style = Object.stringify({
121
- // top: y - 6 + 'px',
122
- // left: x - 6 + 'px',
123
- // width: width + 12 + 'px',
124
- // height: height + 12 + 'px'
125
- // })
126
- style = `
127
- display: block !important;
128
- top: ${y - 6}px;
129
- left: ${x - 6}px;
130
- width: ${width + 12}px;
131
- height: ${height + 12}px;
132
- `
133
- }
134
-
135
- el.node.style = style
136
- el.span.node.innerText = s.focusKey
137
-
138
- return false
139
- }
140
- }
141
- },
142
-
143
- on: {
144
- inspectOnKey,
145
- mousemove: (ev, e, state) => {
146
- const el = ev.target.ref
147
- const component = findComponent(el)
148
- const focusState = e.Inspector.state
149
-
150
- if (!component || !state.debugging || !component.__ref) return focusState.update({ area: false })
151
-
152
- const componentKey = getComponentKey(component)
153
- const updateValue = (area) => {
154
- focusState.update({ area, focusKey: componentKey })
155
- }
156
-
157
- const update = () => {
158
- if (ev.altKey && ev.shiftKey) {
159
- const { x, y, width, height } = component.node.getBoundingClientRect()
160
- const area = { x, y, width, height }
161
-
162
- if (!focusState.area) return updateValue(area)
163
- if (focusState.area.x !== area.x) updateValue(area)
164
- } else if (focusState.area) {
165
- focusState.update({ area: false })
166
- }
167
- }
168
-
169
- window.requestAnimationFrame(() => {
170
- update()
171
- window.requestAnimationFrame(update)
172
- })
173
- },
174
- mousedown: (ev, elem, state) => {
175
- if (!state.debugging) return
176
- const el = ev.target.ref
177
- const component = findComponent(el)
178
- if (!component) return
179
- const componentKey = getComponentKey(component)
180
- if (!componentKey) return
181
-
182
- const editor = el.context.editor
183
- if (editor && editor.onInspect) {
184
- return editor.onInspect(componentKey, el, el.state, { allowRouterWhileInspect: true })
185
- }
186
-
187
- const data = JSON.stringify({
188
- componentKey: `${componentKey}`
189
- })
190
- send.call(el.context.socket, 'route', data)
191
-
192
- ev.preventDefault()
193
- ev.stopPropagation()
194
- return false
195
- }
196
- }
197
- }
package/Notifications.js DELETED
@@ -1,122 +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
- console.log(clients)
44
- if (clients.symbols) {
45
- if (!state.connected) {
46
- state.notifications.connected = {
47
- title: 'Connected',
48
- message: 'to the Symbols live server'
49
- }
50
-
51
- state.update({ connected: true })
52
-
53
- const t = setTimeout(() => {
54
- delete state.notifications.connected
55
- element.notifications.content.connected
56
- .setProps({ animation: 'fadeOutDown' })
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
74
- .setProps({ animation: 'fadeOutDown' })
75
- }
76
- state.update({ connected: true })
77
- clearTimeout(t)
78
- }, 3000)
79
- }
80
- }
81
- }
82
-
83
- export const Notifications = {
84
- state: {
85
- notifications: []
86
- },
87
-
88
- Notifications: {
89
- props: {
90
- position: 'fixed',
91
- left: 'A2',
92
- bottom: 'Z2',
93
- zIndex: '999'
94
- },
95
- childExtend: {
96
- extend: 'Notification',
97
- props: ({ state }) => ({
98
- animationDuration: 'C',
99
- background: NOTIF_COLORS[state.type || 'success'],
100
- icon: null,
101
- Flex: {
102
- Title: {
103
- text: '{{ title }}'
104
- },
105
- P: {
106
- text: '{{ title }}'
107
- }
108
- },
109
- onRender: (e, el, s) => {
110
- el.setProps({ animation: 'fadeInUp' })
111
- },
112
- onClick: (e, el, s) => {
113
- delete s.notifications[el.key]
114
- el.setProps({ animation: 'fadeOutDown' })
115
- if (s.onClose) s.onClose(e, el, s)
116
- }
117
- }),
118
- IconText: null
119
- },
120
- $stateCollection: ({ state }) => state.notifications
121
- }
122
- }