@cu-mkp/editioncrafter 1.0.2 → 1.0.4-beta.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 +7 -7
- package/dist/editioncrafter.js +65802 -0
- package/dist/editioncrafter.umd.cjs +553 -0
- package/dist/es/src/action/DiplomaticActions.js +9 -11
- package/dist/es/src/action/DocumentActions.js +164 -154
- package/dist/es/src/action/GlossaryActions.js +9 -11
- package/dist/es/src/action/initialState/diplomaticInitialState.js +2 -2
- package/dist/es/src/action/initialState/documentInitialState.js +9 -12
- package/dist/es/src/action/initialState/glossaryInitialState.js +3 -3
- package/dist/es/src/action/rootReducer.js +31 -29
- package/dist/es/src/component/AlphabetLinks.js +44 -66
- package/dist/es/src/component/CustomizedTooltops.js +101 -110
- package/dist/es/src/component/DiploMatic.js +64 -91
- package/dist/es/src/component/DocumentView.js +442 -366
- package/dist/es/src/component/EditorComment.js +51 -75
- package/dist/es/src/component/ErrorBoundary.js +37 -61
- package/dist/es/src/component/FigureImage.js +56 -67
- package/dist/es/src/component/GlossaryView.js +157 -149
- package/dist/es/src/component/HelpPopper.js +96 -78
- package/dist/es/src/component/ImageGridView.js +184 -249
- package/dist/es/src/component/ImageView.js +155 -165
- package/dist/es/src/component/ImageZoomControl.js +19 -38
- package/dist/es/src/component/JumpToFolio.js +56 -60
- package/dist/es/src/component/Navigation.js +374 -328
- package/dist/es/src/component/Pagination.js +73 -70
- package/dist/es/src/component/Parser.js +11 -32
- package/dist/es/src/component/RingSpinner.js +31 -32
- package/dist/es/src/component/RouteListener.js +30 -21
- package/dist/es/src/component/SeaDragonComponent.js +33 -56
- package/dist/es/src/component/SinglePaneView.js +15 -33
- package/dist/es/src/component/SplitPaneView.js +151 -170
- package/dist/es/src/component/TranscriptionView.js +190 -179
- package/dist/es/src/component/Watermark.js +21 -30
- package/dist/es/src/component/XMLView.js +60 -82
- package/dist/es/src/hooks/useIsWidthUp.js +9 -7
- package/dist/es/src/icons/ByIcon.js +16 -16
- package/dist/es/src/icons/CcIcon.js +16 -16
- package/dist/es/src/icons/NcIcon.js +16 -16
- package/dist/es/src/icons/SaIcon.js +16 -16
- package/dist/es/src/icons/SideMenuIconLeft.js +30 -38
- package/dist/es/src/icons/SideMenuIconRight.js +32 -38
- package/dist/es/src/index.js +21 -20
- package/dist/es/src/lib/copyObject.js +3 -2
- package/dist/es/src/lib/registerServiceWorker.js +77 -54
- package/dist/es/src/model/DocumentHelper.js +7 -6
- package/dist/es/src/model/Folio.js +64 -86
- package/dist/es/src/model/ReduxStore.js +32 -78
- package/dist/es/src/model/folioLayout.js +275 -280
- package/dist/es/src/saga/RouteListenerSaga.js +89 -193
- package/dist/es/src/saga/rootSaga.js +9 -16
- package/dist/es/src/scss/_imageView.scss +1 -1
- package/dist/es/src/scss/_navigation.scss +1 -1
- package/dist/es/src/scss/editioncrafter.scss +1 -1
- package/dist/style.css +1 -0
- package/package.json +36 -51
- package/dist/editioncrafter.min.js +0 -2
- package/dist/editioncrafter.min.js.LICENSE.txt +0 -144
|
@@ -1,416 +1,411 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import copyObject from '../lib/copyObject';
|
|
9
|
-
var ROW_CODES = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'];
|
|
10
|
-
var emptyMarginFrame = {
|
|
11
|
-
middle: false,
|
|
12
|
-
top: false,
|
|
1
|
+
import copyObject from '../lib/copyObject'
|
|
2
|
+
|
|
3
|
+
const ROW_CODES = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
|
|
4
|
+
|
|
5
|
+
const emptyMarginFrame = {
|
|
6
|
+
'middle': false,
|
|
7
|
+
'top': false,
|
|
13
8
|
'left-middle': false,
|
|
14
9
|
'right-middle': false,
|
|
15
|
-
bottom: false,
|
|
10
|
+
'bottom': false,
|
|
16
11
|
'left-top': false,
|
|
17
12
|
'right-top': false,
|
|
18
13
|
'left-bottom': false,
|
|
19
|
-
'right-bottom': false
|
|
20
|
-
}
|
|
21
|
-
|
|
14
|
+
'right-bottom': false,
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const hintCodes = [
|
|
18
|
+
'tall',
|
|
19
|
+
'extra-tall',
|
|
20
|
+
'wide',
|
|
21
|
+
'full',
|
|
22
|
+
]
|
|
23
|
+
|
|
22
24
|
export function layoutMargin4(html) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
const emptyZoneFrame = [
|
|
26
|
+
['.', '.', '.', '.'],
|
|
27
|
+
['.', '.', '.', '.'],
|
|
28
|
+
['.', '.', '.', '.'],
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
return layoutMargin(html, emptyZoneFrame, layoutDecoder4)
|
|
25
32
|
}
|
|
33
|
+
|
|
26
34
|
export function layoutMargin3(html) {
|
|
27
|
-
|
|
28
|
-
|
|
35
|
+
const emptyZoneFrame = [
|
|
36
|
+
['.', '.', '.'],
|
|
37
|
+
['.', '.', '.'],
|
|
38
|
+
['.', '.', '.'],
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
return layoutMargin(html, emptyZoneFrame, layoutDecoder3)
|
|
29
42
|
}
|
|
43
|
+
|
|
30
44
|
function layoutDecoder4(layoutCode, zoneFrame, hint, block) {
|
|
31
45
|
switch (layoutCode) {
|
|
32
46
|
case 'top':
|
|
33
|
-
zoneFrame[0][1] = block.id
|
|
47
|
+
zoneFrame[0][1] = block.id
|
|
34
48
|
if (hint === 'wide') {
|
|
35
|
-
zoneFrame[0][2] = block.id
|
|
49
|
+
zoneFrame[0][2] = block.id
|
|
36
50
|
}
|
|
37
51
|
if (hint === 'full') {
|
|
38
|
-
zoneFrame[0][0] = block.id
|
|
39
|
-
zoneFrame[0][2] = block.id
|
|
40
|
-
zoneFrame[0][3] = block.id
|
|
52
|
+
zoneFrame[0][0] = block.id
|
|
53
|
+
zoneFrame[0][2] = block.id
|
|
54
|
+
zoneFrame[0][3] = block.id
|
|
41
55
|
}
|
|
42
|
-
break
|
|
56
|
+
break
|
|
43
57
|
case 'left-middle':
|
|
44
|
-
zoneFrame[1][0] = block.id
|
|
45
|
-
if (hint === 'tall')
|
|
46
|
-
zoneFrame[
|
|
47
|
-
|
|
58
|
+
zoneFrame[1][0] = block.id
|
|
59
|
+
if (hint === 'tall') {
|
|
60
|
+
zoneFrame[2][0] = block.id
|
|
61
|
+
}
|
|
62
|
+
else if (hint === 'wide') {
|
|
63
|
+
zoneFrame[1][1] = block.id
|
|
64
|
+
zoneFrame[1][2] = block.id
|
|
48
65
|
}
|
|
49
|
-
break
|
|
66
|
+
break
|
|
50
67
|
case 'right-middle':
|
|
51
|
-
zoneFrame[1][3] = block.id
|
|
52
|
-
if (hint === 'tall')
|
|
53
|
-
|
|
68
|
+
zoneFrame[1][3] = block.id
|
|
69
|
+
if (hint === 'tall')
|
|
70
|
+
zoneFrame[2][3] = block.id
|
|
71
|
+
break
|
|
54
72
|
case 'bottom':
|
|
55
|
-
zoneFrame[2][1] = block.id
|
|
56
|
-
zoneFrame[2][2] = block.id
|
|
73
|
+
zoneFrame[2][1] = block.id
|
|
74
|
+
zoneFrame[2][2] = block.id
|
|
57
75
|
if (hint === 'wide') {
|
|
58
|
-
zoneFrame[2][3] = block.id
|
|
76
|
+
zoneFrame[2][3] = block.id
|
|
59
77
|
}
|
|
60
78
|
if (hint === 'full') {
|
|
61
|
-
zoneFrame[2][0] = block.id
|
|
62
|
-
zoneFrame[2][3] = block.id
|
|
79
|
+
zoneFrame[2][0] = block.id
|
|
80
|
+
zoneFrame[2][3] = block.id
|
|
63
81
|
}
|
|
64
|
-
break
|
|
82
|
+
break
|
|
65
83
|
case 'left-top':
|
|
66
|
-
zoneFrame[0][0] = block.id
|
|
67
|
-
if (hint === 'tall')
|
|
68
|
-
zoneFrame[
|
|
69
|
-
zoneFrame[0][2] = block.id;
|
|
84
|
+
zoneFrame[0][0] = block.id
|
|
85
|
+
if (hint === 'tall') {
|
|
86
|
+
zoneFrame[1][0] = block.id
|
|
70
87
|
}
|
|
71
|
-
|
|
88
|
+
else if (hint === 'wide') {
|
|
89
|
+
zoneFrame[0][1] = block.id
|
|
90
|
+
zoneFrame[0][2] = block.id
|
|
91
|
+
}
|
|
92
|
+
break
|
|
72
93
|
case 'right-top':
|
|
73
|
-
zoneFrame[0][3] = block.id
|
|
74
|
-
if (hint === 'tall')
|
|
75
|
-
|
|
94
|
+
zoneFrame[0][3] = block.id
|
|
95
|
+
if (hint === 'tall')
|
|
96
|
+
zoneFrame[1][3] = block.id
|
|
97
|
+
break
|
|
76
98
|
case 'left-bottom':
|
|
77
|
-
zoneFrame[2][0] = block.id
|
|
99
|
+
zoneFrame[2][0] = block.id
|
|
78
100
|
if (hint === 'wide') {
|
|
79
|
-
zoneFrame[2][1] = block.id
|
|
80
|
-
zoneFrame[2][2] = block.id
|
|
101
|
+
zoneFrame[2][1] = block.id
|
|
102
|
+
zoneFrame[2][2] = block.id
|
|
81
103
|
}
|
|
82
|
-
break
|
|
104
|
+
break
|
|
83
105
|
case 'right-bottom':
|
|
84
|
-
zoneFrame[2][3] = block.id
|
|
85
|
-
break
|
|
106
|
+
zoneFrame[2][3] = block.id
|
|
107
|
+
break
|
|
86
108
|
default:
|
|
87
|
-
zoneFrame[1][1] = block.id
|
|
88
|
-
zoneFrame[1][2] = block.id
|
|
109
|
+
zoneFrame[1][1] = block.id
|
|
110
|
+
zoneFrame[1][2] = block.id
|
|
89
111
|
if (hint === 'wide') {
|
|
90
|
-
zoneFrame[1][3] = block.id
|
|
112
|
+
zoneFrame[1][3] = block.id
|
|
91
113
|
}
|
|
92
114
|
if (hint === 'full') {
|
|
93
|
-
zoneFrame[1][0] = block.id
|
|
94
|
-
zoneFrame[1][3] = block.id
|
|
115
|
+
zoneFrame[1][0] = block.id
|
|
116
|
+
zoneFrame[1][3] = block.id
|
|
95
117
|
}
|
|
96
118
|
}
|
|
97
119
|
}
|
|
120
|
+
|
|
98
121
|
function layoutDecoder3(layoutCode, zoneFrame, hint, block) {
|
|
99
122
|
switch (layoutCode) {
|
|
100
123
|
case 'top':
|
|
101
|
-
zoneFrame[0][1] = block.id
|
|
124
|
+
zoneFrame[0][1] = block.id
|
|
102
125
|
if (hint === 'wide') {
|
|
103
|
-
zoneFrame[0][2] = block.id
|
|
126
|
+
zoneFrame[0][2] = block.id
|
|
104
127
|
}
|
|
105
128
|
if (hint === 'full') {
|
|
106
|
-
zoneFrame[0][0] = block.id
|
|
107
|
-
zoneFrame[0][2] = block.id
|
|
129
|
+
zoneFrame[0][0] = block.id
|
|
130
|
+
zoneFrame[0][2] = block.id
|
|
108
131
|
}
|
|
109
|
-
break
|
|
132
|
+
break
|
|
110
133
|
case 'left-middle':
|
|
111
|
-
zoneFrame[1][0] = block.id
|
|
112
|
-
if (hint === 'tall')
|
|
113
|
-
zoneFrame[
|
|
114
|
-
|
|
134
|
+
zoneFrame[1][0] = block.id
|
|
135
|
+
if (hint === 'tall') {
|
|
136
|
+
zoneFrame[2][0] = block.id
|
|
137
|
+
}
|
|
138
|
+
else if (hint === 'wide') {
|
|
139
|
+
zoneFrame[1][1] = block.id
|
|
140
|
+
zoneFrame[1][2] = block.id
|
|
115
141
|
}
|
|
116
|
-
break
|
|
142
|
+
break
|
|
117
143
|
case 'right-middle':
|
|
118
|
-
zoneFrame[1][2] = block.id
|
|
119
|
-
if (hint === 'tall')
|
|
120
|
-
|
|
144
|
+
zoneFrame[1][2] = block.id
|
|
145
|
+
if (hint === 'tall')
|
|
146
|
+
zoneFrame[2][2] = block.id
|
|
147
|
+
break
|
|
121
148
|
case 'bottom':
|
|
122
|
-
zoneFrame[2][1] = block.id
|
|
149
|
+
zoneFrame[2][1] = block.id
|
|
123
150
|
if (hint === 'wide') {
|
|
124
|
-
zoneFrame[2][2] = block.id
|
|
151
|
+
zoneFrame[2][2] = block.id
|
|
125
152
|
}
|
|
126
153
|
if (hint === 'full') {
|
|
127
|
-
zoneFrame[2][0] = block.id
|
|
128
|
-
zoneFrame[2][2] = block.id
|
|
154
|
+
zoneFrame[2][0] = block.id
|
|
155
|
+
zoneFrame[2][2] = block.id
|
|
129
156
|
}
|
|
130
|
-
break
|
|
157
|
+
break
|
|
131
158
|
case 'left-top':
|
|
132
|
-
zoneFrame[0][0] = block.id
|
|
133
|
-
if (hint === 'tall')
|
|
134
|
-
zoneFrame[
|
|
135
|
-
zoneFrame[0][2] = block.id;
|
|
159
|
+
zoneFrame[0][0] = block.id
|
|
160
|
+
if (hint === 'tall') {
|
|
161
|
+
zoneFrame[1][0] = block.id
|
|
136
162
|
}
|
|
137
|
-
|
|
163
|
+
else if (hint === 'wide') {
|
|
164
|
+
zoneFrame[0][1] = block.id
|
|
165
|
+
zoneFrame[0][2] = block.id
|
|
166
|
+
}
|
|
167
|
+
break
|
|
138
168
|
case 'right-top':
|
|
139
|
-
zoneFrame[0][2] = block.id
|
|
140
|
-
if (hint === 'tall')
|
|
141
|
-
|
|
169
|
+
zoneFrame[0][2] = block.id
|
|
170
|
+
if (hint === 'tall')
|
|
171
|
+
zoneFrame[1][2] = block.id
|
|
172
|
+
break
|
|
142
173
|
case 'left-bottom':
|
|
143
|
-
zoneFrame[2][0] = block.id
|
|
174
|
+
zoneFrame[2][0] = block.id
|
|
144
175
|
if (hint === 'wide') {
|
|
145
|
-
zoneFrame[2][1] = block.id
|
|
146
|
-
zoneFrame[2][2] = block.id
|
|
176
|
+
zoneFrame[2][1] = block.id
|
|
177
|
+
zoneFrame[2][2] = block.id
|
|
147
178
|
}
|
|
148
|
-
break
|
|
179
|
+
break
|
|
149
180
|
case 'right-bottom':
|
|
150
|
-
zoneFrame[2][2] = block.id
|
|
151
|
-
break
|
|
181
|
+
zoneFrame[2][2] = block.id
|
|
182
|
+
break
|
|
152
183
|
default:
|
|
153
|
-
zoneFrame[1][1] = block.id
|
|
154
|
-
zoneFrame[1][2] = block.id
|
|
184
|
+
zoneFrame[1][1] = block.id
|
|
185
|
+
zoneFrame[1][2] = block.id
|
|
155
186
|
if (hint === 'full') {
|
|
156
|
-
zoneFrame[1][0] = block.id
|
|
187
|
+
zoneFrame[1][0] = block.id
|
|
157
188
|
}
|
|
158
189
|
}
|
|
159
190
|
}
|
|
191
|
+
|
|
160
192
|
function layoutMargin(html, emptyZoneFrame, layoutDecoder) {
|
|
161
193
|
// load the surface into a DOM element to retrieve the grid data
|
|
162
|
-
|
|
163
|
-
folioDiv.innerHTML = html
|
|
164
|
-
|
|
194
|
+
const folioDiv = document.createElement('div')
|
|
195
|
+
folioDiv.innerHTML = html
|
|
196
|
+
|
|
197
|
+
let zones
|
|
165
198
|
if (folioDiv.getElementsByTagName('tei-surface').length > 0) {
|
|
166
|
-
zones = [folioDiv.getElementsByTagName('tei-surface')[0]]
|
|
167
|
-
}
|
|
168
|
-
|
|
199
|
+
zones = [folioDiv.getElementsByTagName('tei-surface')[0]]
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
zones = folioDiv.getElementsByTagName('tei-body')[0].children
|
|
169
203
|
}
|
|
170
|
-
|
|
171
|
-
|
|
204
|
+
|
|
205
|
+
const validLayoutCode = function validLayoutCode(block) {
|
|
206
|
+
const layoutCode = block.getAttribute('rend')
|
|
172
207
|
if (Object.keys(emptyMarginFrame).includes(layoutCode)) {
|
|
173
|
-
return layoutCode
|
|
208
|
+
return layoutCode
|
|
174
209
|
}
|
|
175
|
-
return 'middle'
|
|
176
|
-
}
|
|
210
|
+
return 'middle'
|
|
211
|
+
}
|
|
212
|
+
|
|
177
213
|
function validLayoutHint(block) {
|
|
178
|
-
|
|
214
|
+
const layoutHint = block.getAttribute('style')
|
|
179
215
|
if (hintCodes.includes(layoutHint)) {
|
|
180
|
-
return layoutHint
|
|
216
|
+
return layoutHint
|
|
181
217
|
}
|
|
182
|
-
return null
|
|
218
|
+
return null
|
|
183
219
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
220
|
+
|
|
221
|
+
const zoneGrid = []
|
|
222
|
+
let gridContent = ''
|
|
223
|
+
let zoneIndex = 0
|
|
224
|
+
let rowIndex = 0
|
|
188
225
|
// for each zone, take its margin data and populate the grid
|
|
189
226
|
try {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
var hint = validLayoutHint(block);
|
|
208
|
-
block.setAttribute('data-entry-id', entryID);
|
|
209
|
-
|
|
210
|
-
// group all the blocks together that share a layout code
|
|
211
|
-
if (marginFrame[layoutCode]) {
|
|
212
|
-
block.id = marginFrame[layoutCode][0].id;
|
|
213
|
-
marginFrame[layoutCode].push(block);
|
|
214
|
-
} else {
|
|
215
|
-
zoneIndex++;
|
|
216
|
-
block.id = "z".concat(zoneIndex);
|
|
217
|
-
marginFrame[layoutCode] = [block];
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
// decode the layout
|
|
221
|
-
layoutDecoder(layoutCode, zoneFrame, hint, block);
|
|
222
|
-
}
|
|
223
|
-
} catch (err) {
|
|
224
|
-
_iterator2.e(err);
|
|
225
|
-
} finally {
|
|
226
|
-
_iterator2.f();
|
|
227
|
+
for (const zone of zones) {
|
|
228
|
+
// create a rolling frame that is ORed on to grid with each step
|
|
229
|
+
const zoneFrame = copyObject(emptyZoneFrame)
|
|
230
|
+
const marginFrame = copyObject(emptyMarginFrame)
|
|
231
|
+
const entryID = zone.id
|
|
232
|
+
const blocks = zone.children
|
|
233
|
+
const facs = zone.getAttribute('facs')
|
|
234
|
+
|
|
235
|
+
for (const block of blocks) {
|
|
236
|
+
const layoutCode = validLayoutCode(block)
|
|
237
|
+
const hint = validLayoutHint(block)
|
|
238
|
+
block.setAttribute('data-entry-id', entryID)
|
|
239
|
+
|
|
240
|
+
// group all the blocks together that share a layout code
|
|
241
|
+
if (marginFrame[layoutCode]) {
|
|
242
|
+
block.id = marginFrame[layoutCode][0].id
|
|
243
|
+
marginFrame[layoutCode].push(block)
|
|
227
244
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}
|
|
245
|
+
else {
|
|
246
|
+
zoneIndex++
|
|
247
|
+
block.id = `z${zoneIndex}`
|
|
248
|
+
marginFrame[layoutCode] = [block]
|
|
233
249
|
}
|
|
234
250
|
|
|
235
|
-
//
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
251
|
+
// decode the layout
|
|
252
|
+
layoutDecoder(layoutCode, zoneFrame, hint, block)
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
for (const blockSet of Object.values(marginFrame)) {
|
|
256
|
+
if (blockSet) {
|
|
257
|
+
gridContent = gridContent.concat(renderBlockSet(blockSet, facs))
|
|
258
|
+
}
|
|
240
259
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
260
|
+
|
|
261
|
+
// integrate frame into grid
|
|
262
|
+
zoneGrid[rowIndex] = mergeRow(zoneFrame[0], zoneGrid[rowIndex])
|
|
263
|
+
zoneGrid[rowIndex + 1] = mergeRow(zoneFrame[1], zoneGrid[rowIndex + 1])
|
|
264
|
+
zoneGrid[rowIndex + 2] = mergeRow(zoneFrame[2], zoneGrid[rowIndex + 2])
|
|
265
|
+
rowIndex += 1
|
|
245
266
|
}
|
|
246
|
-
} catch (error) {
|
|
247
|
-
console.log(error);
|
|
248
267
|
}
|
|
249
|
-
|
|
268
|
+
catch (error) {
|
|
269
|
+
console.log(error)
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const gridLayout = zoneGridToLayout(zoneGrid)
|
|
250
273
|
|
|
251
274
|
// set the grid-template-areas
|
|
252
275
|
return {
|
|
253
276
|
html: gridContent,
|
|
254
|
-
layout: gridLayout
|
|
255
|
-
}
|
|
277
|
+
layout: gridLayout,
|
|
278
|
+
}
|
|
256
279
|
}
|
|
257
280
|
|
|
258
281
|
// transform zone grid into the grid layout string
|
|
259
282
|
function zoneGridToLayout(zoneGrid) {
|
|
260
|
-
|
|
283
|
+
const zoneGridFinal = [...zoneGrid]
|
|
261
284
|
|
|
262
285
|
// ignore the first row if there are no block sets in it
|
|
263
286
|
if (zoneGrid[0] && zoneGrid[0][0] === '.' && zoneGrid[0][1] === '.') {
|
|
264
|
-
zoneGridFinal.shift()
|
|
287
|
+
zoneGridFinal.shift()
|
|
265
288
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
var row = _step3.value;
|
|
272
|
-
var rowString = row.join(' ');
|
|
273
|
-
gridLayout += " '".concat(rowString, "'");
|
|
274
|
-
}
|
|
275
|
-
} catch (err) {
|
|
276
|
-
_iterator3.e(err);
|
|
277
|
-
} finally {
|
|
278
|
-
_iterator3.f();
|
|
289
|
+
|
|
290
|
+
let gridLayout = ''
|
|
291
|
+
for (const row of zoneGridFinal) {
|
|
292
|
+
const rowString = row.join(' ')
|
|
293
|
+
gridLayout += ` '${rowString}'`
|
|
279
294
|
}
|
|
280
|
-
return gridLayout
|
|
295
|
+
return gridLayout
|
|
281
296
|
}
|
|
297
|
+
|
|
282
298
|
function renderBlockSet(blockSet, facs) {
|
|
283
299
|
// use ID and class from the first block in the set
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
for (
|
|
289
|
-
classStr =
|
|
300
|
+
const firstBlock = blockSet[0]
|
|
301
|
+
const elementID = firstBlock.id
|
|
302
|
+
const entryID = firstBlock.attributes['data-entry-id'].value
|
|
303
|
+
let classStr = ''
|
|
304
|
+
for (let i = 0; i < firstBlock.classList.length; i++) {
|
|
305
|
+
classStr = `${classStr} ${firstBlock.classList.item(i)}`
|
|
290
306
|
}
|
|
291
307
|
|
|
292
308
|
// combine the blocks in the block set. divs are all merged into a single div
|
|
293
309
|
// other element types become children of the single div.
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
} else {
|
|
307
|
-
el = el.concat("".concat(block.outerHTML));
|
|
308
|
-
}
|
|
310
|
+
let el = `<div id="${elementID}" className="${classStr}" data-entry-id="${entryID}" data-facs="${facs || ''}">`
|
|
311
|
+
for (const block of blockSet) {
|
|
312
|
+
if (block.getAttribute('facs')) {
|
|
313
|
+
block.setAttribute('data-facs', block.getAttribute('facs'))
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
block.setAttribute('className', 'block')
|
|
317
|
+
if (block.name === 'div') {
|
|
318
|
+
el = el.concat(`${block.innerHTML} <br/>`)
|
|
319
|
+
}
|
|
320
|
+
else {
|
|
321
|
+
el = el.concat(`${block.outerHTML}`)
|
|
309
322
|
}
|
|
310
|
-
} catch (err) {
|
|
311
|
-
_iterator4.e(err);
|
|
312
|
-
} finally {
|
|
313
|
-
_iterator4.f();
|
|
314
323
|
}
|
|
315
|
-
return el.concat('</div>')
|
|
324
|
+
return el.concat('</div>')
|
|
316
325
|
}
|
|
326
|
+
|
|
317
327
|
function mergeRow(sourceRow, targetRow) {
|
|
318
328
|
if (targetRow) {
|
|
319
|
-
|
|
320
|
-
for (
|
|
329
|
+
const result = []
|
|
330
|
+
for (let i = 0; i < 4; i++) {
|
|
321
331
|
// if the source isn't blank, copy it, otherwise use existing
|
|
322
332
|
if (sourceRow[i] !== '.') {
|
|
323
|
-
result[i] = sourceRow[i]
|
|
324
|
-
}
|
|
325
|
-
|
|
333
|
+
result[i] = sourceRow[i]
|
|
334
|
+
}
|
|
335
|
+
else {
|
|
336
|
+
result[i] = targetRow[i]
|
|
326
337
|
}
|
|
327
338
|
}
|
|
328
|
-
return result
|
|
339
|
+
return result
|
|
329
340
|
}
|
|
330
|
-
return sourceRow
|
|
341
|
+
return sourceRow
|
|
331
342
|
}
|
|
332
343
|
|
|
333
344
|
/// //////////
|
|
334
345
|
// WARNING: This code needs to be refactored, it hasn't been used in the project since early days
|
|
335
346
|
export function layoutGrid(html) {
|
|
336
347
|
// load the surface into a DOM element to retrieve the grid data
|
|
337
|
-
|
|
338
|
-
zoneDiv.innerHTML = html
|
|
339
|
-
|
|
348
|
+
const zoneDiv = document.createElement('div')
|
|
349
|
+
zoneDiv.innerHTML = html
|
|
350
|
+
const zones = zoneDiv.children
|
|
340
351
|
|
|
341
352
|
// move blocks into the gridContent as they are identified.
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
353
|
+
const gridContent = ''
|
|
354
|
+
|
|
355
|
+
const zoneGrid = []
|
|
356
|
+
let index = 0
|
|
345
357
|
// for each zone, take its grid data and populate the grid, throw an error on any dupes
|
|
346
358
|
try {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
368
|
-
var gridDatum = _step7.value;
|
|
369
|
-
var rowIndex = rowCodeToIndex(gridDatum[0]);
|
|
370
|
-
var columnIndex = columnCodeToIndex(gridDatum[1]);
|
|
371
|
-
if (zoneGrid[rowIndex] === undefined) zoneGrid[rowIndex] = ['.', '.', '.'];
|
|
372
|
-
if (zoneGrid[rowIndex][columnIndex] === '.') {
|
|
373
|
-
zoneGrid[rowIndex][columnIndex] = blockID;
|
|
374
|
-
} else {
|
|
375
|
-
throw new Error("Grid location ".concat(gridDatum, " already assigned to ").concat(zoneGrid[rowIndex][columnIndex], "."));
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
} catch (err) {
|
|
379
|
-
_iterator7.e(err);
|
|
380
|
-
} finally {
|
|
381
|
-
_iterator7.f();
|
|
382
|
-
}
|
|
359
|
+
for (const zone of zones) {
|
|
360
|
+
const blocks = zone.children
|
|
361
|
+
for (const block of blocks) {
|
|
362
|
+
const blockID = `z${index++}`
|
|
363
|
+
// TODO renderBlock() definition missing, needs refactoring
|
|
364
|
+
// gridContent = gridContent.concat( renderBlock(blockID, block) );
|
|
365
|
+
const gridData = block.dataset.layout
|
|
366
|
+
if (typeof gridData !== 'string')
|
|
367
|
+
throw new Error(`Grid data not found for zone: ${block}`)
|
|
368
|
+
const gridDataList = gridData.split(' ')
|
|
369
|
+
for (const gridDatum of gridDataList) {
|
|
370
|
+
const rowIndex = rowCodeToIndex(gridDatum[0])
|
|
371
|
+
const columnIndex = columnCodeToIndex(gridDatum[1])
|
|
372
|
+
if (zoneGrid[rowIndex] === undefined)
|
|
373
|
+
zoneGrid[rowIndex] = ['.', '.', '.']
|
|
374
|
+
if (zoneGrid[rowIndex][columnIndex] === '.') {
|
|
375
|
+
zoneGrid[rowIndex][columnIndex] = blockID
|
|
376
|
+
}
|
|
377
|
+
else {
|
|
378
|
+
throw new Error(`Grid location ${gridDatum} already assigned to ${zoneGrid[rowIndex][columnIndex]}.`)
|
|
383
379
|
}
|
|
384
|
-
} catch (err) {
|
|
385
|
-
_iterator6.e(err);
|
|
386
|
-
} finally {
|
|
387
|
-
_iterator6.f();
|
|
388
380
|
}
|
|
389
381
|
}
|
|
390
|
-
} catch (err) {
|
|
391
|
-
_iterator5.e(err);
|
|
392
|
-
} finally {
|
|
393
|
-
_iterator5.f();
|
|
394
382
|
}
|
|
395
|
-
} catch (error) {
|
|
396
|
-
console.log(error);
|
|
397
383
|
}
|
|
398
|
-
|
|
384
|
+
catch (error) {
|
|
385
|
+
console.log(error)
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
const gridLayout = zoneGridToLayout(zoneGrid)
|
|
399
389
|
|
|
400
390
|
// set the grid-template-areas
|
|
401
391
|
return {
|
|
402
392
|
content: gridContent,
|
|
403
|
-
layout: gridLayout
|
|
404
|
-
}
|
|
393
|
+
layout: gridLayout,
|
|
394
|
+
}
|
|
405
395
|
}
|
|
396
|
+
|
|
406
397
|
function rowCodeToIndex(rowCode) {
|
|
407
|
-
if (typeof rowCode !== 'string' || rowCode.length > 1)
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
398
|
+
if (typeof rowCode !== 'string' || rowCode.length > 1)
|
|
399
|
+
throw new Error('Invalid row code, must be a single letter.')
|
|
400
|
+
const index = ROW_CODES.indexOf(rowCode.toLowerCase())
|
|
401
|
+
if (index === -1)
|
|
402
|
+
throw new Error('Invalid row code must be a letter a-j.')
|
|
403
|
+
return index
|
|
411
404
|
}
|
|
405
|
+
|
|
412
406
|
function columnCodeToIndex(columnCode) {
|
|
413
|
-
if (typeof columnCode !== 'string')
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
407
|
+
if (typeof columnCode !== 'string')
|
|
408
|
+
throw new Error('Invalid column code, must be a single digit.')
|
|
409
|
+
const index = Number.parseInt(columnCode, 10) - 1
|
|
410
|
+
return index
|
|
411
|
+
}
|