@symbo.ls/sync 2.11.437
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/DefaultSyncApp.js +8 -0
- package/Inspect.js +196 -0
- package/LICENSE +21 -0
- package/Notifications.js +120 -0
- package/index.js +72 -0
- package/package.json +16 -0
package/Inspect.js
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
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
|
+
export const Inspect = {
|
|
8
|
+
props: {
|
|
9
|
+
'.preventSelect': { userSelect: 'none' },
|
|
10
|
+
'!preventSelect': { userSelect: 'auto' }
|
|
11
|
+
},
|
|
12
|
+
|
|
13
|
+
focus: {
|
|
14
|
+
state: {},
|
|
15
|
+
props: (el, s) => ({
|
|
16
|
+
transition: 'all, defaultBezier, X',
|
|
17
|
+
position: 'fixed',
|
|
18
|
+
hide: !(s.area && s.parent.debugging),
|
|
19
|
+
style: {
|
|
20
|
+
boxShadow: '0 0 10px #3686F733, 0 0 0 3px #3686F766, 0 0 100vmax 100vmax #000A',
|
|
21
|
+
zIndex: '9999999',
|
|
22
|
+
borderRadius: '10px',
|
|
23
|
+
pointerEvents: 'none'
|
|
24
|
+
}
|
|
25
|
+
}),
|
|
26
|
+
|
|
27
|
+
span: {
|
|
28
|
+
props: {
|
|
29
|
+
position: 'absolute',
|
|
30
|
+
margin: 'A2 0',
|
|
31
|
+
fontSize: 'Z',
|
|
32
|
+
color: 'text',
|
|
33
|
+
// color: 'blue',
|
|
34
|
+
zIndex: '99999999',
|
|
35
|
+
transition: 'all, defaultBezier, X',
|
|
36
|
+
textDecoration: 'underline',
|
|
37
|
+
fontWeight: '500',
|
|
38
|
+
top: '100%',
|
|
39
|
+
style: {
|
|
40
|
+
boxShadow: '0 25px 10px 35px black',
|
|
41
|
+
textShadow: '0 0 10px black'
|
|
42
|
+
},
|
|
43
|
+
text: '{{ focusKey }}'
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
on: {
|
|
48
|
+
init: ({ context }) => {
|
|
49
|
+
const { components } = context
|
|
50
|
+
|
|
51
|
+
if (isObject(components)) {
|
|
52
|
+
const { Content, ...rest } = components
|
|
53
|
+
for (const key in rest) {
|
|
54
|
+
if (smblsUI[key]) continue
|
|
55
|
+
if (!rest[key].__ref) rest[key].__ref = {}
|
|
56
|
+
if (!rest[key].__ref.__componentKey) {
|
|
57
|
+
rest[key].__ref.__componentKey = key
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
beforeUpdate: (ch, el, s) => {
|
|
63
|
+
const { area } = s
|
|
64
|
+
const isDebugging = s.area && s.parent.debugging
|
|
65
|
+
|
|
66
|
+
let style
|
|
67
|
+
if (!isDebugging) {
|
|
68
|
+
style = 'display: none !important'
|
|
69
|
+
} else if (area) {
|
|
70
|
+
const { x, y, width, height } = area
|
|
71
|
+
// el.node.style = Object.stringify({
|
|
72
|
+
// top: y - 6 + 'px',
|
|
73
|
+
// left: x - 6 + 'px',
|
|
74
|
+
// width: width + 12 + 'px',
|
|
75
|
+
// height: height + 12 + 'px'
|
|
76
|
+
// })
|
|
77
|
+
style = `
|
|
78
|
+
display: block !important;
|
|
79
|
+
top: ${y - 6}px;
|
|
80
|
+
left: ${x - 6}px;
|
|
81
|
+
width: ${width + 12}px;
|
|
82
|
+
height: ${height + 12}px;
|
|
83
|
+
`
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
el.node.style = style
|
|
87
|
+
el.span.node.innerText = s.focusKey
|
|
88
|
+
|
|
89
|
+
return false
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
on: {
|
|
95
|
+
mousemove: (ev, e, state) => {
|
|
96
|
+
const el = ev.target.ref
|
|
97
|
+
const component = findComponent(el)
|
|
98
|
+
const focusState = e.focus.state
|
|
99
|
+
|
|
100
|
+
if (!component || !state.debugging || !component.__ref) return focusState.update({ area: false })
|
|
101
|
+
|
|
102
|
+
const componentKey = getComponentKey(component)
|
|
103
|
+
const updateValue = (area) => {
|
|
104
|
+
focusState.update({ area, focusKey: componentKey })
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const update = () => {
|
|
108
|
+
if (ev.altKey && ev.shiftKey) {
|
|
109
|
+
const { x, y, width, height } = component.node.getBoundingClientRect()
|
|
110
|
+
const area = { x, y, width, height }
|
|
111
|
+
|
|
112
|
+
if (!focusState.area) return updateValue(area)
|
|
113
|
+
if (focusState.area.x !== area.x) updateValue(area)
|
|
114
|
+
} else if (focusState.area) {
|
|
115
|
+
focusState.update({ area: false })
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
window.requestAnimationFrame(() => {
|
|
120
|
+
update()
|
|
121
|
+
window.requestAnimationFrame(update)
|
|
122
|
+
})
|
|
123
|
+
},
|
|
124
|
+
mousedown: (ev, elem, state) => {
|
|
125
|
+
if (!state.debugging) return
|
|
126
|
+
const el = ev.target.ref
|
|
127
|
+
const component = findComponent(el)
|
|
128
|
+
if (!component) return
|
|
129
|
+
const componentKey = getComponentKey(component)
|
|
130
|
+
if (!componentKey) return
|
|
131
|
+
|
|
132
|
+
const editor = el.context.editor
|
|
133
|
+
if (editor && editor.onInspect) {
|
|
134
|
+
return editor.onInspect(componentKey, el, el.state, { allowRouterWhileInspect: true })
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const data = JSON.stringify({
|
|
138
|
+
componentKey: `${componentKey}`
|
|
139
|
+
})
|
|
140
|
+
send.call(el.context.socket, 'route', data)
|
|
141
|
+
|
|
142
|
+
ev.preventDefault()
|
|
143
|
+
ev.stopPropagation()
|
|
144
|
+
return false
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function returnStringExtend (extend) {
|
|
150
|
+
return isString(extend) ? extend : isArray(extend) ? extend.find(extItem => isString(extItem)) : ''
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function getComponentKey (el) {
|
|
154
|
+
if (!el) return
|
|
155
|
+
const __componentKey = el.__ref.__componentKey
|
|
156
|
+
const extendStr = el.extend && returnStringExtend(el.extend)
|
|
157
|
+
const parentChildExtendStr = el.parent && el.parent.childExtend && returnStringExtend(el.parent.childExtend)
|
|
158
|
+
return (__componentKey || extendStr || parentChildExtendStr || '').split('_')[0].split('.')[0].split('+')[0]
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function findComponent (el) {
|
|
162
|
+
if (!el || !el.__ref) return
|
|
163
|
+
const { components, pages, editor } = el.context
|
|
164
|
+
const componentKey = getComponentKey(el)
|
|
165
|
+
if (editor && editor.onInitInspect) {
|
|
166
|
+
const initInspectReturns = editor.onInitInspect(componentKey, el, el.state)
|
|
167
|
+
if (!initInspectReturns) return findComponent(el.parent)
|
|
168
|
+
}
|
|
169
|
+
if (componentKey && (components[componentKey] || pages[componentKey])) {
|
|
170
|
+
return el
|
|
171
|
+
}
|
|
172
|
+
return findComponent(el.parent)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export const inspectOnKey = (app, ctx) => {
|
|
176
|
+
const windowOpts = ctx.window || window
|
|
177
|
+
windowOpts.onkeydown = (ev) => {
|
|
178
|
+
if (ev.altKey && ev.shiftKey) {
|
|
179
|
+
app.state.update({ debugging: true, preventSelect: true }, {
|
|
180
|
+
preventUpdate: true,
|
|
181
|
+
preventContentUpdate: true,
|
|
182
|
+
preventRecursive: true
|
|
183
|
+
})
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
windowOpts.onkeyup = (ev) => {
|
|
187
|
+
if (app.state.preventSelect && (!ev.altKey || !ev.shiftKey)) {
|
|
188
|
+
app.state.replace({ debugging: false, preventSelect: false }, {
|
|
189
|
+
preventUpdate: true,
|
|
190
|
+
preventContentUpdate: true,
|
|
191
|
+
preventRecursive: true
|
|
192
|
+
})
|
|
193
|
+
app.focus.state.update({ area: false })
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 symbo.ls
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/Notifications.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
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
|
+
const Notifications = {
|
|
84
|
+
props: {
|
|
85
|
+
position: 'fixed',
|
|
86
|
+
left: 'A2',
|
|
87
|
+
bottom: 'Z2',
|
|
88
|
+
zIndex: '999'
|
|
89
|
+
},
|
|
90
|
+
childExtend: {
|
|
91
|
+
extend: 'Notification',
|
|
92
|
+
props: ({ state }) => ({
|
|
93
|
+
animation: 'fadeInUp',
|
|
94
|
+
animationDuration: 'C',
|
|
95
|
+
background: NOTIF_COLORS[state.type || 'success'],
|
|
96
|
+
icon: null,
|
|
97
|
+
Flex: {
|
|
98
|
+
Title: {
|
|
99
|
+
text: state.title
|
|
100
|
+
},
|
|
101
|
+
P: {
|
|
102
|
+
text: state.message
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
onClick: (e, el, s) => {
|
|
106
|
+
delete s.notifications[el.key]
|
|
107
|
+
el.setProps({ animation: 'fadeOutDown' })
|
|
108
|
+
}
|
|
109
|
+
})
|
|
110
|
+
},
|
|
111
|
+
$stateCollection: ({ state }) => state.notifications
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export const Sync = {
|
|
115
|
+
notifications: Notifications,
|
|
116
|
+
|
|
117
|
+
state: {
|
|
118
|
+
notifications: []
|
|
119
|
+
}
|
|
120
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import { router } from '@domql/router'
|
|
4
|
+
import { init } from '@symbo.ls/init'
|
|
5
|
+
import { connect } from '@symbo.ls/socket/client'
|
|
6
|
+
import { window } from '@domql/globals'
|
|
7
|
+
import { overwriteShallow } from '@domql/utils'
|
|
8
|
+
import { connectedToSymbols } from './Notifications'
|
|
9
|
+
|
|
10
|
+
const isLocalhost = window && window.location && window.location.host.includes('local')
|
|
11
|
+
|
|
12
|
+
const onConnect = (element, state) => {
|
|
13
|
+
return (socketId, socket) => {
|
|
14
|
+
// send('components', { COMPONENTS: a(COMPONENTS) })
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const onDisconnect = (element, state) => {
|
|
19
|
+
return () => {}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const onChange = (el, s, ctx) => {
|
|
23
|
+
return (event, data) => {
|
|
24
|
+
if (event === 'change') {
|
|
25
|
+
const obj = JSON.parse(data)
|
|
26
|
+
if (!obj?.DATA) return
|
|
27
|
+
const { state, designSystem, pages, components, snippets } = obj.DATA
|
|
28
|
+
const { utils } = ctx
|
|
29
|
+
|
|
30
|
+
if (pages) {
|
|
31
|
+
// overwriteShallow(ctx.pages, pages)
|
|
32
|
+
overwriteShallow(ctx.pages, pages)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (components) {
|
|
36
|
+
overwriteShallow(ctx.components, components)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (snippets) {
|
|
40
|
+
overwriteShallow(ctx.snippets, snippets)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (state) {
|
|
44
|
+
const route = state.route
|
|
45
|
+
if (route) (utils.router || router)(route.replace('/state', '') || '/', el, {})
|
|
46
|
+
else if (!(snippets && components && pages)) s.update(state)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (snippets || components || pages) {
|
|
50
|
+
const { pathname, search, hash } = ctx.window.location
|
|
51
|
+
;(utils.router || router)(pathname + search + hash, el, {})
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (designSystem) init(designSystem)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (ctx.editor.verbose && event === 'clients') {
|
|
58
|
+
connectedToSymbols(data, el, s)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export const connectToSocket = (el, s, ctx) => {
|
|
64
|
+
return connect(ctx.key, {
|
|
65
|
+
source: isLocalhost ? 'localhost' : 'client',
|
|
66
|
+
socketUrl: isLocalhost ? 'localhost:13336' : 'socket.symbols.app',
|
|
67
|
+
location: window.location.host,
|
|
68
|
+
onConnect: onConnect(el, s, ctx),
|
|
69
|
+
onDisconnect: onDisconnect(el, s, ctx),
|
|
70
|
+
onChange: onChange(el, s, ctx)
|
|
71
|
+
})
|
|
72
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@symbo.ls/sync",
|
|
3
|
+
"version": "2.11.437",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"module": "index.js",
|
|
6
|
+
"gitHead": "d1b6122e6d2aaca97f342e5e9ebb181797b85e23",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@domql/globals": "latest",
|
|
9
|
+
"@domql/router": "latest",
|
|
10
|
+
"@domql/utils": "latest",
|
|
11
|
+
"@symbo.ls/init": "latest",
|
|
12
|
+
"@symbo.ls/scratch": "latest",
|
|
13
|
+
"@symbo.ls/socket": "latest",
|
|
14
|
+
"@symbo.ls/uikit": "latest"
|
|
15
|
+
}
|
|
16
|
+
}
|