@patch-adams/core 1.6.0 → 1.6.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/dist/cli.cjs +99 -10
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +99 -10
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +99 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -2
- package/dist/index.d.ts +17 -2
- package/dist/index.js +99 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -6034,6 +6034,7 @@ function hasClassMappings(mappings) {
|
|
|
6034
6034
|
if (mappings.course?.trim()) return true;
|
|
6035
6035
|
if (mappings.lessons && Object.values(mappings.lessons).some((v) => v?.trim())) return true;
|
|
6036
6036
|
if (mappings.blocks && Object.values(mappings.blocks).some((v) => v?.trim())) return true;
|
|
6037
|
+
if (mappings.blockGroups && mappings.blockGroups.length > 0) return true;
|
|
6037
6038
|
return false;
|
|
6038
6039
|
}
|
|
6039
6040
|
function generateClassMappingsScript(mappings) {
|
|
@@ -6055,6 +6056,10 @@ function generateClassMappingsScript(mappings) {
|
|
|
6055
6056
|
}
|
|
6056
6057
|
const hasBlocks = Object.keys(blockMap).length > 0;
|
|
6057
6058
|
const hasLessons = Object.keys(lessonMap).length > 0;
|
|
6059
|
+
const blockGroups = (mappings.blockGroups || []).filter(
|
|
6060
|
+
(g) => g.blockIds.length >= 2 && g.className.trim() && g.lessonId
|
|
6061
|
+
);
|
|
6062
|
+
const hasGroups = blockGroups.length > 0;
|
|
6058
6063
|
const parts = [];
|
|
6059
6064
|
parts.push(`// PA-Patcher: Custom Class Mappings`);
|
|
6060
6065
|
parts.push(`(function() {`);
|
|
@@ -6120,33 +6125,117 @@ function generateClassMappingsScript(mappings) {
|
|
|
6120
6125
|
parts.push(` }`);
|
|
6121
6126
|
parts.push(``);
|
|
6122
6127
|
}
|
|
6128
|
+
if (hasGroups) {
|
|
6129
|
+
const groupData = blockGroups.map((g) => ({
|
|
6130
|
+
id: g.id,
|
|
6131
|
+
lessonId: g.lessonId,
|
|
6132
|
+
blockIds: g.blockIds,
|
|
6133
|
+
className: g.className.trim()
|
|
6134
|
+
}));
|
|
6135
|
+
parts.push(` // Block groups (adjacent blocks wrapped in container divs)`);
|
|
6136
|
+
parts.push(` var groupMap = ${JSON.stringify(groupData)};`);
|
|
6137
|
+
parts.push(``);
|
|
6138
|
+
parts.push(` function applyBlockGroups() {`);
|
|
6139
|
+
parts.push(` var hash = window.location.hash || '';`);
|
|
6140
|
+
parts.push(` var match = hash.match(/#\\/lessons\\/([^/]+)/);`);
|
|
6141
|
+
parts.push(` var currentLesson = match ? match[1] : null;`);
|
|
6142
|
+
parts.push(` for (var g = 0; g < groupMap.length; g++) {`);
|
|
6143
|
+
parts.push(` var group = groupMap[g];`);
|
|
6144
|
+
parts.push(` if (group.lessonId !== currentLesson) continue;`);
|
|
6145
|
+
parts.push(` if (document.querySelector('[data-pa-group-id="' + group.id + '"]')) continue;`);
|
|
6146
|
+
parts.push(` var blocks = [];`);
|
|
6147
|
+
parts.push(` var allPresent = true;`);
|
|
6148
|
+
parts.push(` for (var b = 0; b < group.blockIds.length; b++) {`);
|
|
6149
|
+
parts.push(` var el = document.querySelector('[data-block-id="' + group.blockIds[b] + '"]');`);
|
|
6150
|
+
parts.push(` if (!el) { allPresent = false; break; }`);
|
|
6151
|
+
parts.push(` blocks.push(el);`);
|
|
6152
|
+
parts.push(` }`);
|
|
6153
|
+
parts.push(` if (!allPresent) continue;`);
|
|
6154
|
+
parts.push(` var parent = blocks[0].parentNode;`);
|
|
6155
|
+
parts.push(` var sameParent = true;`);
|
|
6156
|
+
parts.push(` for (var s = 1; s < blocks.length; s++) {`);
|
|
6157
|
+
parts.push(` if (blocks[s].parentNode !== parent) { sameParent = false; break; }`);
|
|
6158
|
+
parts.push(` }`);
|
|
6159
|
+
parts.push(` if (!sameParent) continue;`);
|
|
6160
|
+
parts.push(` var wrapper = document.createElement('div');`);
|
|
6161
|
+
parts.push(` wrapper.setAttribute('data-pa-group-id', group.id);`);
|
|
6162
|
+
parts.push(` var cls = group.className.split(' ');`);
|
|
6163
|
+
parts.push(` for (var c = 0; c < cls.length; c++) {`);
|
|
6164
|
+
parts.push(` if (cls[c]) wrapper.classList.add(cls[c]);`);
|
|
6165
|
+
parts.push(` }`);
|
|
6166
|
+
parts.push(` parent.insertBefore(wrapper, blocks[0]);`);
|
|
6167
|
+
parts.push(` for (var m = 0; m < blocks.length; m++) {`);
|
|
6168
|
+
parts.push(` wrapper.appendChild(blocks[m]);`);
|
|
6169
|
+
parts.push(` }`);
|
|
6170
|
+
parts.push(` }`);
|
|
6171
|
+
parts.push(` }`);
|
|
6172
|
+
parts.push(``);
|
|
6173
|
+
parts.push(` function teardownBlockGroups() {`);
|
|
6174
|
+
parts.push(` var wrappers = document.querySelectorAll('[data-pa-group-id]');`);
|
|
6175
|
+
parts.push(` for (var w = 0; w < wrappers.length; w++) {`);
|
|
6176
|
+
parts.push(` var wr = wrappers[w];`);
|
|
6177
|
+
parts.push(` var par = wr.parentNode;`);
|
|
6178
|
+
parts.push(` while (wr.firstChild) {`);
|
|
6179
|
+
parts.push(` par.insertBefore(wr.firstChild, wr);`);
|
|
6180
|
+
parts.push(` }`);
|
|
6181
|
+
parts.push(` par.removeChild(wr);`);
|
|
6182
|
+
parts.push(` }`);
|
|
6183
|
+
parts.push(` }`);
|
|
6184
|
+
parts.push(``);
|
|
6185
|
+
}
|
|
6123
6186
|
parts.push(` // Initialization`);
|
|
6124
6187
|
parts.push(` function init() {`);
|
|
6125
6188
|
if (hasBlocks) {
|
|
6126
6189
|
parts.push(` applyBlockClasses();`);
|
|
6127
6190
|
}
|
|
6191
|
+
if (hasGroups) {
|
|
6192
|
+
parts.push(` applyBlockGroups();`);
|
|
6193
|
+
}
|
|
6128
6194
|
if (hasLessons) {
|
|
6129
6195
|
parts.push(` applyLessonClasses();`);
|
|
6196
|
+
}
|
|
6197
|
+
if (hasLessons || hasGroups) {
|
|
6130
6198
|
parts.push(``);
|
|
6131
6199
|
parts.push(` // Watch for Rise SPA navigation`);
|
|
6132
6200
|
parts.push(` window.addEventListener('hashchange', function() {`);
|
|
6133
|
-
|
|
6201
|
+
if (hasGroups) {
|
|
6202
|
+
parts.push(` teardownBlockGroups();`);
|
|
6203
|
+
}
|
|
6204
|
+
if (hasLessons) {
|
|
6205
|
+
parts.push(` applyLessonClasses();`);
|
|
6206
|
+
}
|
|
6134
6207
|
if (hasBlocks) {
|
|
6135
6208
|
parts.push(` setTimeout(applyBlockClasses, 200);`);
|
|
6136
6209
|
}
|
|
6210
|
+
if (hasGroups) {
|
|
6211
|
+
parts.push(` setTimeout(applyBlockGroups, 300);`);
|
|
6212
|
+
}
|
|
6137
6213
|
parts.push(` });`);
|
|
6138
6214
|
}
|
|
6139
|
-
if (hasBlocks) {
|
|
6215
|
+
if (hasBlocks || hasGroups) {
|
|
6140
6216
|
parts.push(``);
|
|
6141
6217
|
parts.push(` // MutationObserver for lazily-rendered Rise blocks`);
|
|
6142
|
-
|
|
6143
|
-
|
|
6144
|
-
|
|
6145
|
-
|
|
6146
|
-
|
|
6147
|
-
|
|
6148
|
-
|
|
6149
|
-
|
|
6218
|
+
if (hasGroups) {
|
|
6219
|
+
parts.push(` var debounceTimer = null;`);
|
|
6220
|
+
parts.push(` var observer = new MutationObserver(function() {`);
|
|
6221
|
+
parts.push(` if (debounceTimer) clearTimeout(debounceTimer);`);
|
|
6222
|
+
parts.push(` debounceTimer = setTimeout(function() {`);
|
|
6223
|
+
if (hasBlocks) {
|
|
6224
|
+
parts.push(` applyBlockClasses();`);
|
|
6225
|
+
}
|
|
6226
|
+
parts.push(` applyBlockGroups();`);
|
|
6227
|
+
parts.push(` }, 100);`);
|
|
6228
|
+
parts.push(` });`);
|
|
6229
|
+
} else {
|
|
6230
|
+
parts.push(` var observer = new MutationObserver(function(mutations) {`);
|
|
6231
|
+
parts.push(` for (var i = 0; i < mutations.length; i++) {`);
|
|
6232
|
+
parts.push(` if (mutations[i].addedNodes.length > 0) {`);
|
|
6233
|
+
parts.push(` applyBlockClasses();`);
|
|
6234
|
+
parts.push(` return;`);
|
|
6235
|
+
parts.push(` }`);
|
|
6236
|
+
parts.push(` }`);
|
|
6237
|
+
parts.push(` });`);
|
|
6238
|
+
}
|
|
6150
6239
|
parts.push(` var container = document.querySelector('#app') || document.body;`);
|
|
6151
6240
|
parts.push(` observer.observe(container, { childList: true, subtree: true });`);
|
|
6152
6241
|
}
|