@json-layout/core 0.3.0 → 0.4.0
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/package.json +3 -4
- package/src/compile/index.js +1 -2
- package/src/compile/serialize.js +2 -2
- package/src/index.js +1 -0
- package/src/utils/clone.js +65 -0
- package/types/compile/index.d.ts.map +1 -1
- package/types/index.d.ts +1 -0
- package/types/utils/clone.d.ts +3 -0
- package/types/utils/clone.d.ts.map +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@json-layout/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Compilation and state management utilities for JSON Layout.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
},
|
|
48
48
|
"homepage": "https://github.com/json-layout/json-layout#readme",
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@json-layout/vocabulary": "^0.
|
|
50
|
+
"@json-layout/vocabulary": "^0.4.0",
|
|
51
51
|
"@types/markdown-it": "^13.0.1",
|
|
52
52
|
"ajv": "^8.12.0",
|
|
53
53
|
"ajv-errors": "^3.0.0",
|
|
@@ -58,8 +58,7 @@
|
|
|
58
58
|
"magicast": "^0.3.0",
|
|
59
59
|
"markdown-it": "^13.0.2",
|
|
60
60
|
"mitt": "^3.0.1",
|
|
61
|
-
"recast": "^0.23.4"
|
|
62
|
-
"rfdc": "^1.3.0"
|
|
61
|
+
"recast": "^0.23.4"
|
|
63
62
|
},
|
|
64
63
|
"devDependencies": {
|
|
65
64
|
"@types/debug": "^4.1.7",
|
package/src/compile/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// compileStatic is meant to produce a serializable result
|
|
2
2
|
|
|
3
3
|
import ajvModule from 'ajv'
|
|
4
|
-
import rfdc from 'rfdc'
|
|
5
4
|
// import { Parser as ExprEvalParser } from 'expr-eval'
|
|
6
5
|
import addFormats from 'ajv-formats'
|
|
7
6
|
import ajvErrors from 'ajv-errors'
|
|
@@ -10,6 +9,7 @@ import MarkdownIt from 'markdown-it'
|
|
|
10
9
|
import i18n from '../i18n/index.js'
|
|
11
10
|
import { makeSkeletonTree } from './skeleton-tree.js'
|
|
12
11
|
import { resolveRefs } from './utils/resolve-refs.js'
|
|
12
|
+
import clone from '../utils/clone.js'
|
|
13
13
|
|
|
14
14
|
export { resolveRefs } from './utils/resolve-refs.js'
|
|
15
15
|
|
|
@@ -29,7 +29,6 @@ const ajvLocalize = /** @type {typeof ajvLocalizeModule.default} */ (ajvLocalize
|
|
|
29
29
|
|
|
30
30
|
const expressionsParams = ['data', 'options', 'context', 'display']
|
|
31
31
|
|
|
32
|
-
const clone = rfdc()
|
|
33
32
|
// const exprEvalParser = new ExprEvalParser()
|
|
34
33
|
|
|
35
34
|
/**
|
package/src/compile/serialize.js
CHANGED
|
@@ -29,8 +29,8 @@ export function serialize (compiledLayout) {
|
|
|
29
29
|
// some internal imports to ajv are not translated to esm, we do it here
|
|
30
30
|
// cf https://github.com/ajv-validator/ajv-formats/pull/73
|
|
31
31
|
if (code.includes('require("ajv-formats/dist/formats")')) {
|
|
32
|
-
code = 'import
|
|
33
|
-
code = code.replace(/require\("ajv-formats\/dist\/formats"\)\.fullFormats/g, 'fullFormats')
|
|
32
|
+
code = 'import ajvFormats from "ajv-formats/dist/formats.js";\n' + code
|
|
33
|
+
code = code.replace(/require\("ajv-formats\/dist\/formats"\)\.fullFormats/g, 'ajvFormats.fullFormats')
|
|
34
34
|
}
|
|
35
35
|
if (code.includes('require("ajv/dist/runtime/ucs2length")')) {
|
|
36
36
|
code = 'import ucs2length from "ajv/dist/runtime/ucs2length.js";\n' + code
|
package/src/index.js
CHANGED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/* eslint-disable jsdoc/require-jsdoc */
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
|
|
4
|
+
// a copy of https://github.com/davidmarkclements/rfdc/blob/master/index.js
|
|
5
|
+
// but lighter and with ESM export
|
|
6
|
+
|
|
7
|
+
function copyBuffer (cur) {
|
|
8
|
+
if (cur instanceof Buffer) {
|
|
9
|
+
return Buffer.from(cur)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return new cur.constructor(cur.buffer.slice(), cur.byteOffset, cur.length)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function rfdc () {
|
|
16
|
+
return clone
|
|
17
|
+
|
|
18
|
+
function cloneArray (a, fn) {
|
|
19
|
+
const keys = Object.keys(a)
|
|
20
|
+
const a2 = new Array(keys.length)
|
|
21
|
+
for (let i = 0; i < keys.length; i++) {
|
|
22
|
+
const k = keys[i]
|
|
23
|
+
const cur = a[k]
|
|
24
|
+
if (typeof cur !== 'object' || cur === null) {
|
|
25
|
+
a2[k] = cur
|
|
26
|
+
} else if (cur instanceof Date) {
|
|
27
|
+
a2[k] = new Date(cur)
|
|
28
|
+
} else if (ArrayBuffer.isView(cur)) {
|
|
29
|
+
a2[k] = copyBuffer(cur)
|
|
30
|
+
} else {
|
|
31
|
+
a2[k] = fn(cur)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return a2
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function clone (o) {
|
|
38
|
+
if (typeof o !== 'object' || o === null) return o
|
|
39
|
+
if (o instanceof Date) return new Date(o)
|
|
40
|
+
if (Array.isArray(o)) return cloneArray(o, clone)
|
|
41
|
+
if (o instanceof Map) return new Map(cloneArray(Array.from(o), clone))
|
|
42
|
+
if (o instanceof Set) return new Set(cloneArray(Array.from(o), clone))
|
|
43
|
+
const o2 = {}
|
|
44
|
+
for (const k in o) {
|
|
45
|
+
if (Object.hasOwnProperty.call(o, k) === false) continue
|
|
46
|
+
const cur = o[k]
|
|
47
|
+
if (typeof cur !== 'object' || cur === null) {
|
|
48
|
+
o2[k] = cur
|
|
49
|
+
} else if (cur instanceof Date) {
|
|
50
|
+
o2[k] = new Date(cur)
|
|
51
|
+
} else if (cur instanceof Map) {
|
|
52
|
+
o2[k] = new Map(cloneArray(Array.from(cur), clone))
|
|
53
|
+
} else if (cur instanceof Set) {
|
|
54
|
+
o2[k] = new Set(cloneArray(Array.from(cur), clone))
|
|
55
|
+
} else if (ArrayBuffer.isView(cur)) {
|
|
56
|
+
o2[k] = copyBuffer(cur)
|
|
57
|
+
} else {
|
|
58
|
+
o2[k] = clone(cur)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return o2
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export default rfdc()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/compile/index.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/compile/index.js"],"names":[],"mappings":"AAqEA;;;;GAIG;AACH,iCAJW,MAAM,4EAEJ,cAAc,CA0E1B;;2BAlIY,OAAO,YAAY,EAAE,YAAY;2BACjC,OAAO,YAAY,EAAE,YAAY;6BACjC,OAAO,YAAY,EAAE,cAAc;6BACnC,OAAO,YAAY,EAAE,cAAc;oCACnC,OAAO,YAAY,EAAE,qBAAqB;iCAC1C,OAAO,YAAY,EAAE,kBAAkB"}
|
package/types/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clone.d.ts","sourceRoot":"","sources":["../../src/utils/clone.js"],"names":[],"mappings":"AAoCE,uCAyBC"}
|