websocket-text-relay 1.1.0 → 1.1.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/README.md CHANGED
@@ -6,17 +6,13 @@ front end changes evaluated immediately as they type, without having to first sa
6
6
  It's a similar concept to sites like CodePen and JsFiddle, except you can develop locally using your own text editor with all
7
7
  of your personalized plugins instead of having to use an in browser code editor.
8
8
 
9
- ## Alpha
10
-
11
- Note: This tool is still in alpha state. Some features like the VsCode extension have not been published yet. Documentation is still a work in progress
12
-
13
9
  ## Usage
14
10
 
15
11
  ### 1. Install the extension for your text editor
16
12
 
17
13
  WTR currently has plugins for Neovim and VSCode.
18
14
  - [websocket-text-relay.nvim](https://github.com/niels4/websocket-text-relay.nvim)
19
- - VSCode extension coming soon!
15
+ - [websocket-text-relay-vscode](https://github.com/niels4/websocket-text-relay-vscode)
20
16
 
21
17
  ### 2. Verify the webserver is running with the status UI
22
18
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "websocket-text-relay",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "An LSP server for sending live file updates from your text editor to the front end via websockets.",
5
5
  "bin": {
6
6
  "websocket-text-relay": "./start.js"
@@ -1,7 +1,7 @@
1
1
  const { exportDeps, drawSvgElement, drawCircle, drawLinearPath, coordsToPathData, drawText, drawToolTip } = window.__WTR__
2
2
 
3
3
  const drawValueWithTooltip = ({x, y, label, direction, parentNode}) => {
4
- const tooltipWrapperGroup = drawSvgElement("g", undefined, "tooltip_wrapper_group", parentNode)
4
+ const tooltipWrapperGroup = drawSvgElement({tag: "g", className: "tooltip_wrapper_group", parent: parentNode})
5
5
  drawToolTip({x: x, y: y - 0.0032, text: label, direction, parentNode: tooltipWrapperGroup})
6
6
  return drawText({x: x, y: y, dominantBaseline: "middle", text: "0", className: "timeseries_value", parentNode: tooltipWrapperGroup})
7
7
  }
@@ -67,9 +67,9 @@ class ActivityTimeseriesGraph {
67
67
  const minY = -height / 2
68
68
  const maxY = minY + height
69
69
 
70
- const clipPath = drawSvgElement("clipPath", {id: innerCircleClipPathId}, undefined, this.parentNode)
70
+ const clipPath = drawSvgElement({tag: "clipPath", attributes: {id: innerCircleClipPathId}, parent: this.parentNode})
71
71
  drawCircle({cx: 0, cy: 0, r: this.innerRingRadius - 0.005, parentNode: clipPath})
72
- drawSvgElement("rect", {"clip-path": `url(#${innerCircleClipPathId})`, x: minX, y: minY, height, width}, "timeseries_bg", this.parentNode)
72
+ drawSvgElement({tag: "rect", attributes: {"clip-path": `url(#${innerCircleClipPathId})`, x: minX, y: minY, height, width}, className: "timeseries_bg", parent: this.parentNode})
73
73
 
74
74
  const series = this.dataWindow
75
75
  const {startTime, endTime, maxValue} = getSeriesWindowInfo(series)
@@ -90,13 +90,12 @@ class ActivityTimeseriesGraph {
90
90
  const onTickUpdate = () => {
91
91
  scheduleNextTick()
92
92
 
93
- console.log("data tick", Date.now())
94
93
  const series = this.dataWindow
95
94
  const prevEndTime = series.at(-1).time
96
95
  const newTime = prevEndTime + dataWindowInterval
97
96
  series.shift()
98
97
  series.push({time: newTime, value: window.currentActivityCount})
99
- currentValueElement.innerHTML = window.currentActivityCount
98
+ currentValueElement.textContent = window.currentActivityCount
100
99
  window.currentActivityCount = 0
101
100
 
102
101
  const pathCoords = series.map(({time, value}) => {
@@ -110,7 +109,7 @@ class ActivityTimeseriesGraph {
110
109
  requestAnimationFrame(() => {
111
110
  requestAnimationFrame(() => {
112
111
  const {startTime, endTime, maxValue} = getSeriesWindowInfo(series)
113
- maxValueElement.innerHTML = maxValue
112
+ maxValueElement.textContent = maxValue
114
113
 
115
114
  valueScale = createLinearScale(0, maxValue, maxY, minY) // in svg, y increases as it goes down, so we need to flip max and min in the range
116
115
  timeScale = createLinearScale(startTime, endTime, minX, maxX)
@@ -138,12 +137,7 @@ class ActivityTimeseriesGraph {
138
137
 
139
138
  triggerActivity () {
140
139
  window.currentActivityCount++
141
- console.log("time series graph activity")
142
140
  }
143
141
  }
144
142
 
145
143
  exportDeps({ActivityTimeseriesGraph})
146
-
147
- /*
148
- *
149
- */
@@ -9,14 +9,7 @@ class HeaderSummary {
9
9
  draw () {
10
10
  this.parentNode.innerHTML = ""
11
11
  drawText({x: -.86, y: -.73, text: "editors", parentNode: this.parentNode})
12
- // this.editorCountNode = drawText({x: -.96, y: -.62, text: "0", className: "header_number", parentNode: this.parentNode})
13
12
  drawText({x: .86, y: -.73, text: "clients", className: "right_header", parentNode: this.parentNode})
14
- // this.clientCountNode = drawText({x: .96, y: -.62, text: "0", className: ["right_header", "header_number"], parentNode: this.parentNode})
15
- }
16
-
17
- update (/* data */) {
18
- // this.editorCountNode.innerHTML = data.editors.length
19
- // this.clientCountNode.innerHTML = data.clients.length
20
13
  }
21
14
  }
22
15
 
@@ -21,7 +21,7 @@ class ServerStatus {
21
21
  this.valueElement.classList.remove(valueTextClass)
22
22
  this.offlineElement.classList.add(offlineTextClass)
23
23
  } else {
24
- this.valueElement.innerHTML = pid
24
+ this.valueElement.textContent = pid
25
25
  this.valueElement.classList.add(valueTextClass)
26
26
  this.offlineElement.classList.remove(offlineTextClass)
27
27
  }
@@ -2,7 +2,7 @@ const { exportDeps, polarToCartesian, coordsToPathData, drawLinearPath, drawCirc
2
2
 
3
3
  // a value with a colored circle and tooltip
4
4
  const drawSummaryValue = ({x, y, label, circleClass, parentNode}) => {
5
- const tooltipWrapperGroup = drawSvgElement("g", undefined, "tooltip_wrapper_group", parentNode)
5
+ const tooltipWrapperGroup = drawSvgElement({tag: "g", className: "tooltip_wrapper_group", parent: parentNode})
6
6
  drawCircle({cx: x, cy: y - 0.0032, r: summaryCircleRadius, className: circleClass, parentNode: tooltipWrapperGroup})
7
7
  drawToolTip({x: x, y: y - 0.0032, text: label, parentNode: tooltipWrapperGroup})
8
8
  return drawText({x: x + summaryCircleRadius * 2, y: y, dominantBaseline: "middle", text: "0", className: "summary_text_value", parentNode: tooltipWrapperGroup})
@@ -10,13 +10,13 @@ const drawSummaryValue = ({x, y, label, circleClass, parentNode}) => {
10
10
 
11
11
  // similar to summary value, but with an update function that automatically handles moving the circle on the left as the text size changes
12
12
  const drawRightAlignedSummaryValue = ({x, y, label, circleClass, parentNode}) => {
13
- const tooltipWrapperGroup = drawSvgElement("g", undefined, "tooltip_wrapper_group", parentNode)
13
+ const tooltipWrapperGroup = drawSvgElement({tag: "g", className: "tooltip_wrapper_group", parent: parentNode})
14
14
  drawToolTip({x: x, y: y - 0.0032, text: label, parentNode: tooltipWrapperGroup})
15
15
  const textElement = drawText({x: x + summaryCircleRadius * 2, y: y, dominantBaseline: "middle", text: "0", textAnchor: "end", className: "summary_text_value", parentNode: tooltipWrapperGroup})
16
16
  const xDiff = textElement.getBBox().width
17
17
  const labelCircle = drawCircle({cx: x - xDiff, cy: y - 0.0032, r: summaryCircleRadius, className: circleClass, parentNode: tooltipWrapperGroup})
18
18
  const update = (value) => {
19
- textElement.innerHTML = value
19
+ textElement.textContent = value
20
20
  const xDiff = textElement.getBBox().width
21
21
  labelCircle.setAttribute("cx", x - xDiff)
22
22
  }
@@ -67,7 +67,7 @@ class ClientLabel {
67
67
  const watchedCountBbox = this.watchedCountElement.getBBox()
68
68
 
69
69
  const xDiff = summaryValueSpacing + watchedCountBbox.width
70
- this.activeCountTranslateWrapper = drawSvgElement("g", {transform: `translate(${xDiff}, 0)`}, undefined, this.parentNode)
70
+ this.activeCountTranslateWrapper = drawSvgElement({tag: "g", attributes: {transform: `translate(${xDiff}, 0)`}, parent: this.parentNode})
71
71
  this.activeCountElement = drawSummaryValue({x: summaryStartX, y: summaryMidY, label: "Active Files", circleClass: "summary_active_circle", parentNode: this.activeCountTranslateWrapper})
72
72
  }
73
73
 
@@ -81,13 +81,13 @@ class ClientLabel {
81
81
  const halfIndex = Math.floor(name.length / 2)
82
82
  const nameFirstHalf = name.substring(0, halfIndex)
83
83
  const nameSecondHalf = name.substring(halfIndex, name.length)
84
- this.topNameElement.innerHTML = nameFirstHalf
85
- this.nameTextElement.innerHTML = nameSecondHalf
84
+ this.topNameElement.textContent = nameFirstHalf
85
+ this.nameTextElement.textContent = nameSecondHalf
86
86
  this.nameTextElement.classList.add("small_text")
87
87
  } else {
88
88
  this.topNameElement.innerHTML = ""
89
89
  this.nameTextElement.classList.remove("small_text")
90
- this.nameTextElement.innerHTML = name
90
+ this.nameTextElement.textContent = name
91
91
  }
92
92
 
93
93
  const textBbox = addPadding(this.nameTextElement.getBBox(), 0.00, underlinePadding)
@@ -95,8 +95,8 @@ class ClientLabel {
95
95
  const newUnderlinePathData = coordsToPathData(underlineCoords)
96
96
  this.underlinePath.setAttribute("d", newUnderlinePathData)
97
97
 
98
- this.watchedCountElement.innerHTML = client.watchCount
99
- this.activeCountElement.innerHTML = client.activeWatchCount
98
+ this.watchedCountElement.textContent = client.watchCount
99
+ this.activeCountElement.textContent = client.activeWatchCount
100
100
 
101
101
  const xDiff = summaryValueSpacing + this.watchedCountElement.getBBox().width
102
102
  this.activeCountTranslateWrapper.setAttribute("transform", `translate(${xDiff}, 0)`)
@@ -129,7 +129,7 @@ class EditorLabel {
129
129
 
130
130
  this.activeCountSummaryValue = drawRightAlignedSummaryValue({x: summaryStartX, y: summaryMidY, label: "Active Files", circleClass: "summary_active_circle", parentNode: this.parentNode})
131
131
  const xDiff = this.activeCountSummaryValue.textElement.getBBox().width + summaryCircleRadius + editorSummaryPadding * 2
132
- this.openFilesTransformGroup = drawSvgElement('g', {transform: `translate(${-xDiff})`}, undefined, this.parentNode)
132
+ this.openFilesTransformGroup = drawSvgElement({tag: 'g', attributes: {transform: `translate(${-xDiff})`}, parent: this.parentNode})
133
133
  this.openCountSummaryValue = drawRightAlignedSummaryValue({x: summaryStartX, y: summaryMidY, label: "Open Files", circleClass: "summary_watched_circle", parentNode: this.openFilesTransformGroup})
134
134
  }
135
135
 
@@ -147,13 +147,13 @@ class EditorLabel {
147
147
  const halfIndex = Math.floor(name.length / 2)
148
148
  const nameFirstHalf = name.substring(0, halfIndex)
149
149
  const nameSecondHalf = name.substring(halfIndex, name.length)
150
- this.topNameElement.innerHTML = nameFirstHalf
151
- this.nameTextElement.innerHTML = nameSecondHalf
150
+ this.topNameElement.textContent = nameFirstHalf
151
+ this.nameTextElement.textContent = nameSecondHalf
152
152
  this.nameTextElement.classList.add("small_text")
153
153
  } else {
154
154
  this.topNameElement.innerHTML = ""
155
155
  this.nameTextElement.classList.remove("small_text")
156
- this.nameTextElement.innerHTML = name
156
+ this.nameTextElement.textContent = name
157
157
  }
158
158
 
159
159
  const textBbox = addPadding(this.nameTextElement.getBBox(), 0.00, underlinePadding)
@@ -46,7 +46,7 @@ class SessionWedges {
46
46
  const wedgeAngleDelta = (totalAngleDelta / numWedges) - wedgeSpacing
47
47
  const innerRadius = this.outerRingRadius - wedgeWidth / 2
48
48
  for (let i = 0; i < numWedges; i++) {
49
- const group = drawSvgElement("g", undefined, "single_wedge_group", this.parentNode)
49
+ const group = drawSvgElement({tag: "g", className: "single_wedge_group", parent: this.parentNode})
50
50
 
51
51
  let startAngle = totalStartAngle + this.direction * (i + 1) * wedgeSpacing + this.direction * i * wedgeAngleDelta
52
52
  if (this.direction === -1) {
package/src/ui/js/main.js CHANGED
@@ -9,7 +9,7 @@ gridGroup.innerHTML = ""
9
9
  // drawGrid(gridGroup)
10
10
 
11
11
  const headerSummaryNode = document.getElementById('header_summary_group')
12
- const headerSummary = new HeaderSummary({parentNode: headerSummaryNode})
12
+ new HeaderSummary({parentNode: headerSummaryNode})
13
13
 
14
14
  const statusRingNode = document.getElementById('status_ring_group')
15
15
  const statusRing = new StatusRing({innerRingRadius, outerRingRadius, outerArcSize, parentNode: statusRingNode})
@@ -70,7 +70,6 @@ const handleStatusData = (rawData) => {
70
70
  window.__WTR__.lastStatusData = rawData
71
71
  const data = statusDataTranform(rawData)
72
72
  console.log("status data updated", data)
73
- headerSummary.update(data)
74
73
  statusRing.update(data)
75
74
  clientWedges.update(data.clients)
76
75
  editorWedges.update(data.editors)
@@ -3,8 +3,8 @@ const { exportDeps } = window.__WTR__
3
3
  const TWO_PI = 2 * Math.PI
4
4
  const MAX_ANGLE_DELTA = .99999
5
5
 
6
- const drawSvgElement = (tagName, attributes = {}, className, parentNode) => {
7
- const element = document.createElementNS("http://www.w3.org/2000/svg", tagName)
6
+ const drawSvgElement = ({tag, attributes = {}, className, parent}) => {
7
+ const element = document.createElementNS("http://www.w3.org/2000/svg", tag)
8
8
 
9
9
  if (className && className.length > 0) {
10
10
  if (Array.isArray(className)) {
@@ -20,51 +20,32 @@ const drawSvgElement = (tagName, attributes = {}, className, parentNode) => {
20
20
  }
21
21
  })
22
22
 
23
- if (parentNode) {
24
- parentNode.append(element)
23
+ if (parent) {
24
+ parent.append(element)
25
25
  }
26
26
 
27
27
  return element
28
28
  }
29
29
 
30
- const drawText = ({x, y, text, dominantBaseline, textAnchor, className, parentNode}) => {
31
- const textElement = drawSvgElement("text", {x, y, "dominant-baseline": dominantBaseline, "text-anchor": textAnchor}, className, parentNode)
32
- textElement.innerHTML = text
30
+ const drawText = ({x, y, text, dominantBaseline, textAnchor, className, parentNode: parent}) => {
31
+ const textElement = drawSvgElement({tag: "text", attributes: {x, y, "dominant-baseline": dominantBaseline, "text-anchor": textAnchor}, className, parent})
32
+ textElement.textContent = text
33
33
  return textElement
34
34
  }
35
35
 
36
- const drawLine = ({x1, y1, x2, y2, className, parentNode}) => {
37
- return drawSvgElement("line", {x1, y1, x2, y2}, className, parentNode)
36
+ const drawLine = ({x1, y1, x2, y2, className, parentNode: parent}) => {
37
+ return drawSvgElement({tag: "line", attributes: {x1, y1, x2, y2}, className, parent})
38
38
  }
39
39
 
40
- const drawCircle = ({cx, cy, r, className, parentNode}) => {
41
- return drawSvgElement("circle", {cx, cy, r}, className, parentNode)
40
+ const drawCircle = ({cx, cy, r, className, parentNode: parent}) => {
41
+ return drawSvgElement({tag: "circle", attributes: {cx, cy, r}, className, parent})
42
42
  }
43
43
 
44
44
  const coordsToPathData = (coords) => "M " + coords.map(coord => coord.join(',')).join(" L ")
45
45
 
46
- const drawLinearPath = ({coords, className, parentNode}) => {
46
+ const drawLinearPath = ({coords, className, parentNode: parent}) => {
47
47
  const d = coordsToPathData(coords)
48
- return drawSvgElement("path", {d}, className, parentNode)
49
- }
50
-
51
- const drawPolarLine = ({startAngle, startRadius, endAngle, endRadius, className, parentNode}) => {
52
- const startAngleRadians = (startAngle % 1) * TWO_PI
53
- const endAngleRadians = (endAngle % 1) * TWO_PI
54
- const x1 = Math.cos(startAngleRadians) * startRadius
55
- const y1 = -Math.sin(startAngleRadians) * startRadius
56
- const x2 = Math.cos(endAngleRadians) * endRadius
57
- const y2 = -Math.sin(endAngleRadians) * endRadius
58
-
59
- return drawSvgElement("line", {x1, y1, x2, y2}, className, parentNode)
60
- }
61
-
62
- const drawPolarCircle = ({angle, radius, r, className, parentNode}) => {
63
- const angleRadians = (angle % 1) * TWO_PI
64
- const cx = Math.cos(angleRadians) * radius
65
- const cy = -Math.sin(angleRadians) * radius
66
-
67
- return drawSvgElement("circle", {cx, cy, r}, className, parentNode)
48
+ return drawSvgElement({tag: "path", attributes: {d}, className, parent})
68
49
  }
69
50
 
70
51
  const polarToCartesian = (angle, radius) => {
@@ -74,23 +55,29 @@ const polarToCartesian = (angle, radius) => {
74
55
  return [x, y]
75
56
  }
76
57
 
77
- const drawWedge = ({startAngle, angleDelta, innerRadius, radiusDelta, className, parentNode}) => {
58
+ const drawPolarLine = ({startAngle, startRadius, endAngle, endRadius, className, parentNode: parent}) => {
59
+ const [x1, y1] = polarToCartesian(startAngle, startRadius)
60
+ const [x2, y2] = polarToCartesian(endAngle, endRadius)
61
+
62
+ return drawSvgElement({tag: "line", attributes: {x1, y1, x2, y2}, className, parent})
63
+ }
64
+
65
+ const drawPolarCircle = ({angle, radius, r, className, parentNode: parent}) => {
66
+ const [cx, cy] = polarToCartesian(angle, radius)
67
+ return drawSvgElement({tag: "circle", attributes: {cx, cy, r}, className, parent})
68
+ }
69
+
70
+ const drawWedge = ({startAngle, angleDelta, innerRadius, radiusDelta, className, parentNode: parent}) => {
78
71
  if (angleDelta < 0) { angleDelta = 0 }
79
72
  if (angleDelta > MAX_ANGLE_DELTA) {angleDelta = MAX_ANGLE_DELTA }
80
-
81
- const startAngleRadians = (startAngle % 1) * TWO_PI
82
- const endAngleRadians = ((startAngle + angleDelta) % 1) * TWO_PI
73
+ const endAngle = startAngle + angleDelta
83
74
  const outerRadius = innerRadius + radiusDelta
84
75
  const largeArcFlag = (angleDelta % 1) > .5 ? "1" : "0"
85
76
 
86
- const startX1 = Math.cos(startAngleRadians) * innerRadius
87
- const startY1 = -Math.sin(startAngleRadians) * innerRadius
88
- const startX2 = Math.cos(startAngleRadians) * outerRadius
89
- const startY2 = -Math.sin(startAngleRadians) * outerRadius
90
- const endX1 = Math.cos(endAngleRadians) * innerRadius
91
- const endY1 = -Math.sin(endAngleRadians) * innerRadius
92
- const endX2 = Math.cos(endAngleRadians) * outerRadius
93
- const endY2 = -Math.sin(endAngleRadians) * outerRadius
77
+ const [startX1, startY1] = polarToCartesian(startAngle, innerRadius)
78
+ const [startX2, startY2] = polarToCartesian(startAngle, outerRadius)
79
+ const [endX1, endY1] = polarToCartesian(endAngle, innerRadius)
80
+ const [endX2, endY2] = polarToCartesian(endAngle, outerRadius)
94
81
 
95
82
  const d = `
96
83
  M ${startX1} ${startY1},
@@ -100,28 +87,28 @@ A ${outerRadius} ${outerRadius} 0 ${largeArcFlag} 1 ${startX2} ${startY2},
100
87
  Z
101
88
  `
102
89
 
103
- return drawSvgElement("path", {d}, className, parentNode)
90
+ return drawSvgElement({tag: "path", attributes: {d}, className, parent})
104
91
  }
105
92
 
106
93
  const triangleHeight = 0.06
107
94
  const verticalPadding = 0.01
108
95
  const horizontalPadding = 0.04
109
96
 
110
- const drawToolTip = ({x, y, text, direction = "below", parentNode}) => {
97
+ const drawToolTip = ({x, y, text, direction = "below", parentNode: parent}) => {
111
98
  const directionMultiplier = direction === "above" ? -1 : 1
112
- const tooltipDisplayGroup = drawSvgElement("g", undefined, "tooltip_display_group", parentNode)
99
+ const tooltipDisplayGroup = drawSvgElement("g", undefined, "tooltip_display_group", parent)
113
100
  const bgPlaceholder = drawSvgElement("g", undefined, undefined, tooltipDisplayGroup)
114
101
  const textY = y + (triangleHeight + verticalPadding) * directionMultiplier
115
102
  const textElement = drawText({x, y: textY, text, className: "tooltip_text", parentNode: tooltipDisplayGroup})
116
103
  const textBbox = textElement.getBBox()
117
- const rectAttributes = {
104
+ const attributes = {
118
105
  x: textBbox.x - horizontalPadding,
119
106
  y: textBbox.y - verticalPadding,
120
107
  width: textBbox.width + horizontalPadding * 2,
121
108
  height: textBbox.height + verticalPadding * 2,
122
109
  rx: 0.015
123
110
  }
124
- drawSvgElement("rect", rectAttributes, "tooltip_outline", bgPlaceholder)
111
+ drawSvgElement({tag: "rect", attributes, className: "tooltip_outline", parent: bgPlaceholder})
125
112
  }
126
113
 
127
114
  exportDeps({drawSvgElement, drawLine, drawCircle, drawLinearPath, drawPolarLine, drawPolarCircle, drawWedge,