@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.js CHANGED
@@ -6024,6 +6024,7 @@ function hasClassMappings(mappings) {
6024
6024
  if (mappings.course?.trim()) return true;
6025
6025
  if (mappings.lessons && Object.values(mappings.lessons).some((v) => v?.trim())) return true;
6026
6026
  if (mappings.blocks && Object.values(mappings.blocks).some((v) => v?.trim())) return true;
6027
+ if (mappings.blockGroups && mappings.blockGroups.length > 0) return true;
6027
6028
  return false;
6028
6029
  }
6029
6030
  function generateClassMappingsScript(mappings) {
@@ -6045,6 +6046,10 @@ function generateClassMappingsScript(mappings) {
6045
6046
  }
6046
6047
  const hasBlocks = Object.keys(blockMap).length > 0;
6047
6048
  const hasLessons = Object.keys(lessonMap).length > 0;
6049
+ const blockGroups = (mappings.blockGroups || []).filter(
6050
+ (g) => g.blockIds.length >= 2 && g.className.trim() && g.lessonId
6051
+ );
6052
+ const hasGroups = blockGroups.length > 0;
6048
6053
  const parts = [];
6049
6054
  parts.push(`// PA-Patcher: Custom Class Mappings`);
6050
6055
  parts.push(`(function() {`);
@@ -6110,33 +6115,117 @@ function generateClassMappingsScript(mappings) {
6110
6115
  parts.push(` }`);
6111
6116
  parts.push(``);
6112
6117
  }
6118
+ if (hasGroups) {
6119
+ const groupData = blockGroups.map((g) => ({
6120
+ id: g.id,
6121
+ lessonId: g.lessonId,
6122
+ blockIds: g.blockIds,
6123
+ className: g.className.trim()
6124
+ }));
6125
+ parts.push(` // Block groups (adjacent blocks wrapped in container divs)`);
6126
+ parts.push(` var groupMap = ${JSON.stringify(groupData)};`);
6127
+ parts.push(``);
6128
+ parts.push(` function applyBlockGroups() {`);
6129
+ parts.push(` var hash = window.location.hash || '';`);
6130
+ parts.push(` var match = hash.match(/#\\/lessons\\/([^/]+)/);`);
6131
+ parts.push(` var currentLesson = match ? match[1] : null;`);
6132
+ parts.push(` for (var g = 0; g < groupMap.length; g++) {`);
6133
+ parts.push(` var group = groupMap[g];`);
6134
+ parts.push(` if (group.lessonId !== currentLesson) continue;`);
6135
+ parts.push(` if (document.querySelector('[data-pa-group-id="' + group.id + '"]')) continue;`);
6136
+ parts.push(` var blocks = [];`);
6137
+ parts.push(` var allPresent = true;`);
6138
+ parts.push(` for (var b = 0; b < group.blockIds.length; b++) {`);
6139
+ parts.push(` var el = document.querySelector('[data-block-id="' + group.blockIds[b] + '"]');`);
6140
+ parts.push(` if (!el) { allPresent = false; break; }`);
6141
+ parts.push(` blocks.push(el);`);
6142
+ parts.push(` }`);
6143
+ parts.push(` if (!allPresent) continue;`);
6144
+ parts.push(` var parent = blocks[0].parentNode;`);
6145
+ parts.push(` var sameParent = true;`);
6146
+ parts.push(` for (var s = 1; s < blocks.length; s++) {`);
6147
+ parts.push(` if (blocks[s].parentNode !== parent) { sameParent = false; break; }`);
6148
+ parts.push(` }`);
6149
+ parts.push(` if (!sameParent) continue;`);
6150
+ parts.push(` var wrapper = document.createElement('div');`);
6151
+ parts.push(` wrapper.setAttribute('data-pa-group-id', group.id);`);
6152
+ parts.push(` var cls = group.className.split(' ');`);
6153
+ parts.push(` for (var c = 0; c < cls.length; c++) {`);
6154
+ parts.push(` if (cls[c]) wrapper.classList.add(cls[c]);`);
6155
+ parts.push(` }`);
6156
+ parts.push(` parent.insertBefore(wrapper, blocks[0]);`);
6157
+ parts.push(` for (var m = 0; m < blocks.length; m++) {`);
6158
+ parts.push(` wrapper.appendChild(blocks[m]);`);
6159
+ parts.push(` }`);
6160
+ parts.push(` }`);
6161
+ parts.push(` }`);
6162
+ parts.push(``);
6163
+ parts.push(` function teardownBlockGroups() {`);
6164
+ parts.push(` var wrappers = document.querySelectorAll('[data-pa-group-id]');`);
6165
+ parts.push(` for (var w = 0; w < wrappers.length; w++) {`);
6166
+ parts.push(` var wr = wrappers[w];`);
6167
+ parts.push(` var par = wr.parentNode;`);
6168
+ parts.push(` while (wr.firstChild) {`);
6169
+ parts.push(` par.insertBefore(wr.firstChild, wr);`);
6170
+ parts.push(` }`);
6171
+ parts.push(` par.removeChild(wr);`);
6172
+ parts.push(` }`);
6173
+ parts.push(` }`);
6174
+ parts.push(``);
6175
+ }
6113
6176
  parts.push(` // Initialization`);
6114
6177
  parts.push(` function init() {`);
6115
6178
  if (hasBlocks) {
6116
6179
  parts.push(` applyBlockClasses();`);
6117
6180
  }
6181
+ if (hasGroups) {
6182
+ parts.push(` applyBlockGroups();`);
6183
+ }
6118
6184
  if (hasLessons) {
6119
6185
  parts.push(` applyLessonClasses();`);
6186
+ }
6187
+ if (hasLessons || hasGroups) {
6120
6188
  parts.push(``);
6121
6189
  parts.push(` // Watch for Rise SPA navigation`);
6122
6190
  parts.push(` window.addEventListener('hashchange', function() {`);
6123
- parts.push(` applyLessonClasses();`);
6191
+ if (hasGroups) {
6192
+ parts.push(` teardownBlockGroups();`);
6193
+ }
6194
+ if (hasLessons) {
6195
+ parts.push(` applyLessonClasses();`);
6196
+ }
6124
6197
  if (hasBlocks) {
6125
6198
  parts.push(` setTimeout(applyBlockClasses, 200);`);
6126
6199
  }
6200
+ if (hasGroups) {
6201
+ parts.push(` setTimeout(applyBlockGroups, 300);`);
6202
+ }
6127
6203
  parts.push(` });`);
6128
6204
  }
6129
- if (hasBlocks) {
6205
+ if (hasBlocks || hasGroups) {
6130
6206
  parts.push(``);
6131
6207
  parts.push(` // MutationObserver for lazily-rendered Rise blocks`);
6132
- parts.push(` var observer = new MutationObserver(function(mutations) {`);
6133
- parts.push(` for (var i = 0; i < mutations.length; i++) {`);
6134
- parts.push(` if (mutations[i].addedNodes.length > 0) {`);
6135
- parts.push(` applyBlockClasses();`);
6136
- parts.push(` return;`);
6137
- parts.push(` }`);
6138
- parts.push(` }`);
6139
- parts.push(` });`);
6208
+ if (hasGroups) {
6209
+ parts.push(` var debounceTimer = null;`);
6210
+ parts.push(` var observer = new MutationObserver(function() {`);
6211
+ parts.push(` if (debounceTimer) clearTimeout(debounceTimer);`);
6212
+ parts.push(` debounceTimer = setTimeout(function() {`);
6213
+ if (hasBlocks) {
6214
+ parts.push(` applyBlockClasses();`);
6215
+ }
6216
+ parts.push(` applyBlockGroups();`);
6217
+ parts.push(` }, 100);`);
6218
+ parts.push(` });`);
6219
+ } else {
6220
+ parts.push(` var observer = new MutationObserver(function(mutations) {`);
6221
+ parts.push(` for (var i = 0; i < mutations.length; i++) {`);
6222
+ parts.push(` if (mutations[i].addedNodes.length > 0) {`);
6223
+ parts.push(` applyBlockClasses();`);
6224
+ parts.push(` return;`);
6225
+ parts.push(` }`);
6226
+ parts.push(` }`);
6227
+ parts.push(` });`);
6228
+ }
6140
6229
  parts.push(` var container = document.querySelector('#app') || document.body;`);
6141
6230
  parts.push(` observer.observe(container, { childList: true, subtree: true });`);
6142
6231
  }