@01-edu/shared 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.
Files changed (2) hide show
  1. package/graph.js +96 -0
  2. package/package.json +2 -1
package/graph.js ADDED
@@ -0,0 +1,96 @@
1
+ const isCoreObj = (contentShape, coreKey) =>
2
+ typeof contentShape === 'object' && Object.keys(contentShape)[0] === coreKey
3
+ const isSatteliteObj = (contentShape, satteliteKey) =>
4
+ typeof contentShape === 'object' &&
5
+ Object.values(contentShape)[0].some(sat => sat === satteliteKey)
6
+
7
+ export const getCoreSattelites = (coreObject, objectsList) => {
8
+ const { key, parent } = coreObject
9
+ const objects = objectsList || Object.values(parent.children)
10
+ const sattelitesSection = parent.attrs.graph.innerCircle.find(
11
+ s => s.type === 'slice' && s.innerArc.contents.find(c => isCoreObj(c, key)),
12
+ )
13
+ if (!sattelitesSection) return []
14
+ const sattelitesObject = sattelitesSection.innerArc.contents.find(c =>
15
+ isCoreObj(c, key),
16
+ )
17
+ const sattelitesList = new Set(...Object.values(sattelitesObject))
18
+
19
+ return objects.filter(o => sattelitesList.has(o.key))
20
+ }
21
+
22
+ export const getCoreOfSattelite = (satteliteObject, objectsList) => {
23
+ const { key, parent } = satteliteObject
24
+ const objects = objectsList || Object.values(parent.children)
25
+ const sattelitesSection = parent.attrs.graph?.innerCircle?.find(
26
+ s =>
27
+ s.type === 'slice' &&
28
+ s.innerArc?.contents.find(c => isSatteliteObj(c, key)),
29
+ )
30
+ if (!sattelitesSection) return undefined
31
+ const coreObject = sattelitesSection.innerArc.contents.find(c =>
32
+ isSatteliteObj(c, key),
33
+ )
34
+
35
+ return objects.filter(o => o.key === Object.keys(coreObject)[0])
36
+ }
37
+
38
+ export const flatGraphContents = graph => [
39
+ ...(graph.centralPoint ? [graph.centralPoint] : []),
40
+ ...(graph.innerCircle || []).flatMap(section =>
41
+ section.type === 'slice'
42
+ ? [
43
+ ...(section.entryPoint ? [section.entryPoint] : []),
44
+ ...(section.innerArc?.contents || []).flatMap(c =>
45
+ typeof c === 'string' ? c : Object.entries(c)[0].flat(),
46
+ ),
47
+ ...(section.outerArcs || []).flatMap(arc => arc.contents || []),
48
+ ]
49
+ : section.contents,
50
+ ),
51
+ ...(graph.middleCircle || []).flatMap(arc => arc.contents || []),
52
+ ...(graph.outerCircle || []).flatMap(arc => arc.contents || []),
53
+ ]
54
+
55
+ // WARNING: without central point (for linear graph, already destructured)
56
+ export const flatAtomeAndCoreContents = graph => [
57
+ ...(graph.innerCircle || []).flatMap(section =>
58
+ section.type === 'slice'
59
+ ? [
60
+ ...(section.entryPoint ? [section.entryPoint] : []),
61
+ ...(section.innerArc?.contents || []).flatMap(c =>
62
+ typeof c === 'string' ? c : Object.keys(c)[0],
63
+ ),
64
+ ...(section.outerArcs || []).flatMap(arc => arc.contents || []),
65
+ ]
66
+ : section.contents,
67
+ ),
68
+ ...(graph.middleCircle || []).flatMap(arc => arc.contents || []),
69
+ ...(graph.outerCircle || []).flatMap(arc => arc.contents || []),
70
+ ]
71
+
72
+ export const limitations = {
73
+ LINE: {
74
+ maxLinesCount: 6,
75
+ maxContentsCount: 7, // 7 contents max split along a single line
76
+ },
77
+ SLICE: {
78
+ maxSlicesCount: 4,
79
+ innerCircle: {
80
+ maxSubContentsCount: 5, // 5 sub-contents max by content
81
+ maxContentsCount: 30, // 30 contents max spread evenly over the number of inner cirlces of slices
82
+ },
83
+ outerArc: {
84
+ maxArcsCount: 2,
85
+ maxContentsCount: 10, // 10 contents max spread evenly over the 1 or 2 outer arcs
86
+ },
87
+ },
88
+ MIDDLE_CIRCLE: {
89
+ maxArcsCount: 8,
90
+ maxContentsCount: 70, // 70 contents max spread evenly over the number of arcs
91
+ },
92
+ OUTER_CIRCLE: {
93
+ maxArcsCount: 9,
94
+ maxContentsCount: 90, // 90 contents max spread evenly over the number of arcs
95
+ },
96
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@01-edu/shared",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "scripts": {
@@ -13,6 +13,7 @@
13
13
  "./onboarding.js",
14
14
  "./attrs.js",
15
15
  "./attrs-defs.js",
16
+ "./graph.js",
16
17
  "./languages.js",
17
18
  "./definitions-checker.js",
18
19
  "./path.js",