@symbo.ls/sync 2.11.464 → 2.11.466

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'
package/Inspect.js ADDED
@@ -0,0 +1,197 @@
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
+ }
@@ -0,0 +1,122 @@
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
+ }
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@symbo.ls/sync",
3
- "version": "2.11.464",
3
+ "version": "2.11.466",
4
4
  "main": "index.js",
5
5
  "module": "index.js",
6
- "gitHead": "7a24490e102fa450e508f8527923647816e26ab9",
6
+ "gitHead": "ecdaeba51ab8c4d65fc84880530fc42b449e89b3",
7
7
  "files": [
8
- "src",
8
+ "*.js",
9
9
  "dist"
10
10
  ],
11
11
  "repository": "https://github.com/symbo-ls/scratch",
@@ -35,7 +35,7 @@
35
35
  "@symbo.ls/init": "^2.11.464",
36
36
  "@symbo.ls/scratch": "^2.11.464",
37
37
  "@symbo.ls/socket": "^2.11.464",
38
- "@symbo.ls/uikit": "^2.11.464"
38
+ "@symbo.ls/uikit": "^2.11.465"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@babel/core": "^7.12.0"