mockaton 13.3.5 → 13.4.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 +28 -16
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/package.json +1 -1
- package/src/client/ApiCommander.js +1 -1
- package/src/client/ApiConstants.js +2 -2
- package/src/client/IndexHtml.js +18 -18
- package/src/client/app-header.js +3 -3
- package/src/client/app-payload-viewer.js +4 -8
- package/src/client/app-store.js +3 -34
- package/src/client/app.css +5 -3
- package/src/client/app.js +3 -2
- package/src/client/dir/dittoSplitPaths.js +25 -0
- package/src/client/dir/dittoSplitPaths.test.js +28 -0
- package/src/client/{dir-tree.js → dir/groupByFolder.js} +2 -33
- package/src/client/{dir-tree.test.js → dir/groupByFolder.test.js} +2 -26
- package/src/client/graphics.js +5 -5
- package/src/client/utils/LocalStorage.js +69 -0
- package/src/client/utils/css.js +16 -0
- package/src/client/{dom-utils-test.js → utils/css.test.js} +1 -1
- package/src/client/utils/dom.js +68 -0
- package/src/client/utils/watcherDev.js +46 -0
- package/src/server/Api.js +16 -3
- package/src/server/MockDispatcher.js +11 -8
- package/src/server/Mockaton.js +16 -8
- package/src/server/Mockaton.test.js +14 -9
- package/src/server/ProxyRelay.js +9 -3
- package/src/server/{utils/UrlParsers.js → UrlParsers.js} +10 -4
- package/src/server/{utils/UrlParsers.test.js → UrlParsers.test.js} +14 -14
- package/src/server/config.js +2 -0
- package/src/server/utils/HttpServerResponse.js +18 -39
- package/src/server/{WatcherDevClient.js → utils/WatcherDevClient.js} +3 -17
- package/src/server/utils/fs.js +1 -1
- package/src/server/utils/logger.js +4 -4
- package/src/server/utils/mime.js +11 -11
- package/src/server/utils/mime.test.js +15 -11
- package/www/src/assets/openapi.json +147 -147
- package/src/client/dom-utils.js +0 -154
- package/src/client/watcherDev.js +0 -39
package/src/client/dom-utils.js
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
export function t(translation) {
|
|
2
|
-
return translation[0]
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
export function classNames(...args) {
|
|
6
|
-
return args.filter(Boolean).join(' ')
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function createElement(tag, props, ...children) {
|
|
10
|
-
const elem = document.createElement(tag)
|
|
11
|
-
if (props)
|
|
12
|
-
for (const [k, v] of Object.entries(props))
|
|
13
|
-
if (v === undefined) continue
|
|
14
|
-
else if (k === 'ref') v.elem = elem
|
|
15
|
-
else if (k === 'style') Object.assign(elem.style, v)
|
|
16
|
-
else if (k.startsWith('on')) elem.addEventListener(k.slice(2).toLowerCase(), ...[v].flat())
|
|
17
|
-
else if (k in elem) elem[k] = v
|
|
18
|
-
else elem.setAttribute(k, v)
|
|
19
|
-
elem.append(...children.flat().filter(Boolean))
|
|
20
|
-
return elem
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function createSvgElement(tag, props, ...children) {
|
|
24
|
-
const elem = document.createElementNS('http://www.w3.org/2000/svg', tag)
|
|
25
|
-
for (const [k, v] of Object.entries(props))
|
|
26
|
-
elem.setAttribute(k, v)
|
|
27
|
-
elem.append(...children.flat().filter(Boolean))
|
|
28
|
-
return elem
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function Fragment(...args) {
|
|
32
|
-
const frag = new DocumentFragment()
|
|
33
|
-
for (const arg of args)
|
|
34
|
-
if (Array.isArray(arg))
|
|
35
|
-
frag.append(...arg)
|
|
36
|
-
else
|
|
37
|
-
frag.appendChild(arg)
|
|
38
|
-
return frag
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
export function restoreFocus(cb) {
|
|
43
|
-
const focusQuery = selectorFor(document.activeElement)
|
|
44
|
-
cb()
|
|
45
|
-
if (focusQuery)
|
|
46
|
-
document.querySelector(focusQuery)?.focus()
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function selectorFor(elem) {
|
|
50
|
-
if (!(elem instanceof Element))
|
|
51
|
-
return
|
|
52
|
-
const path = []
|
|
53
|
-
while (elem) {
|
|
54
|
-
let qualifier = ''
|
|
55
|
-
if (elem.hasAttribute('key'))
|
|
56
|
-
qualifier = `[key="${elem.getAttribute('key')}"]`
|
|
57
|
-
else {
|
|
58
|
-
let i = 0
|
|
59
|
-
let sib = elem
|
|
60
|
-
while ((sib = sib.previousElementSibling))
|
|
61
|
-
if (sib.tagName === elem.tagName)
|
|
62
|
-
i++
|
|
63
|
-
if (i)
|
|
64
|
-
qualifier = `:nth-of-type(${i + 1})`
|
|
65
|
-
}
|
|
66
|
-
path.push(elem.tagName + qualifier)
|
|
67
|
-
elem = elem.parentElement
|
|
68
|
-
}
|
|
69
|
-
return path.reverse().join('>')
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
export function extractClassNames({ cssRules }) {
|
|
74
|
-
// Class names must begin with _ or a letter, then it can have numbers and hyphens
|
|
75
|
-
// TODO think about tag.className selectors
|
|
76
|
-
const reClassName = /(?:^|[\s,{>])&?\s*\.([a-zA-Z_][\w-]*)/g
|
|
77
|
-
const cNames = {}
|
|
78
|
-
let match
|
|
79
|
-
for (const rule of cssRules)
|
|
80
|
-
while (match = reClassName.exec(rule.cssText))
|
|
81
|
-
cNames[match[1]] = match[1]
|
|
82
|
-
return cNames
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
export class QueryParamBool {
|
|
87
|
-
constructor(param) {
|
|
88
|
-
this.param = param
|
|
89
|
-
this.value = this.#init()
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
#init() {
|
|
93
|
-
const qs = new URLSearchParams(globalThis.location?.search)
|
|
94
|
-
if (qs.has(this.param))
|
|
95
|
-
return qs.get(this.param) !== '0'
|
|
96
|
-
const stored = globalThis.localStorage?.getItem(this.param) !== '0'
|
|
97
|
-
if (!stored)
|
|
98
|
-
this.#applyToUrl(false)
|
|
99
|
-
return stored
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
toggle() {
|
|
103
|
-
this.value = !this.value
|
|
104
|
-
if (this.value)
|
|
105
|
-
globalThis.localStorage?.removeItem(this.param)
|
|
106
|
-
else
|
|
107
|
-
globalThis.localStorage?.setItem(this.param, '0')
|
|
108
|
-
this.#applyToUrl(this.value)
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
#applyToUrl(nextVal) {
|
|
112
|
-
const url = new URL(globalThis.location?.href)
|
|
113
|
-
if (nextVal)
|
|
114
|
-
url.searchParams.delete(this.param)
|
|
115
|
-
else
|
|
116
|
-
url.searchParams.set(this.param, '0')
|
|
117
|
-
history.replaceState(null, '', url)
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
export class LocalStorageSet {
|
|
123
|
-
constructor(key) {
|
|
124
|
-
this.key = key
|
|
125
|
-
this.value = this.#parse()
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
add(item) {
|
|
129
|
-
this.value.add(item)
|
|
130
|
-
this.#persist()
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
delete(item) {
|
|
134
|
-
this.value.delete(item)
|
|
135
|
-
this.#persist()
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
has(item) {
|
|
139
|
-
return this.value.has(item)
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
#parse() {
|
|
143
|
-
try {
|
|
144
|
-
return new Set(JSON.parse(globalThis.localStorage?.getItem(this.key) || '[]'))
|
|
145
|
-
}
|
|
146
|
-
catch {
|
|
147
|
-
return new Set()
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
#persist() {
|
|
152
|
-
globalThis.localStorage?.setItem(this.key, JSON.stringify([...this.value]))
|
|
153
|
-
}
|
|
154
|
-
}
|
package/src/client/watcherDev.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { API } from './ApiConstants.js'
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
let conn = null
|
|
5
|
-
let timer = null
|
|
6
|
-
|
|
7
|
-
window.addEventListener('beforeunload', teardown)
|
|
8
|
-
connect()
|
|
9
|
-
function connect() {
|
|
10
|
-
if (conn) return
|
|
11
|
-
|
|
12
|
-
clearTimeout(timer)
|
|
13
|
-
conn = new EventSource(API.watchHotReload)
|
|
14
|
-
|
|
15
|
-
conn.onmessage = function (event) {
|
|
16
|
-
const file = event.data
|
|
17
|
-
if (file.endsWith('.css'))
|
|
18
|
-
hotReloadCSS(file)
|
|
19
|
-
else if (file)
|
|
20
|
-
location.reload()
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
conn.onerror = function () {
|
|
24
|
-
console.error('hot reload')
|
|
25
|
-
teardown()
|
|
26
|
-
timer = setTimeout(connect, 3000)
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function teardown() {
|
|
31
|
-
clearTimeout(timer)
|
|
32
|
-
conn?.close()
|
|
33
|
-
conn = null
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async function hotReloadCSS(file) {
|
|
37
|
-
const mod = await import(`./${file}?${Date.now()}`, { with: { type: 'css' } })
|
|
38
|
-
document.adoptedStyleSheets = [mod.default]
|
|
39
|
-
}
|