@c15t/dev-tools 2.0.0-rc.6 → 2.0.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/dist/react.cjs CHANGED
@@ -1969,6 +1969,7 @@ var __webpack_exports__ = {};
1969
1969
  DevTools: ()=>C15TDevTools
1970
1970
  });
1971
1971
  const external_react_namespaceObject = require("react");
1972
+ const external_c15t_namespaceObject = require("c15t");
1972
1973
  const DEVTOOLS_STORAGE_KEY = 'c15t-devtools-position';
1973
1974
  const DRAG_THRESHOLD = 30;
1974
1975
  const VELOCITY_THRESHOLD = 0.15;
@@ -2346,7 +2347,6 @@ var __webpack_exports__ = {};
2346
2347
  }
2347
2348
  return null;
2348
2349
  }
2349
- const version = '2.0.0-rc.6';
2350
2350
  const DEVTOOLS_ICON = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 446 445" aria-label="c15t">
2351
2351
  <path fill="currentColor" d="M223.178.313c39.064 0 70.732 31.668 70.732 70.732-.001 39.064-31.668 70.731-70.732 70.731-12.181 0-23.642-3.079-33.649-8.502l-55.689 55.689a70.267 70.267 0 0 1 5.574 13.441h167.531c8.695-29.217 35.762-50.523 67.804-50.523 39.064 0 70.731 31.668 70.731 70.732s-31.668 70.732-70.731 70.732c-32.042 0-59.108-21.306-67.803-50.523H139.413a70.417 70.417 0 0 1-7.888 17.396l54.046 54.046c10.893-6.851 23.786-10.815 37.605-10.815 39.064 0 70.732 31.669 70.732 70.733 0 39.064-31.668 70.731-70.732 70.731s-70.732-31.667-70.732-70.731c0-10.518 2.296-20.499 6.414-29.471l-57.78-57.78c-8.972 4.117-18.952 6.414-29.47 6.414-39.063 0-70.731-31.668-70.732-70.732 0-39.064 31.669-70.732 70.733-70.732 12.18 0 23.642 3.079 33.649 8.502l55.688-55.688c-5.423-10.007-8.502-21.469-8.502-33.65 0-39.064 31.668-70.733 70.732-70.733Zm0 343.555c-16.742 0-30.314 13.572-30.314 30.314 0 16.741 13.572 30.313 30.314 30.313s30.314-13.572 30.314-30.313c0-16.742-13.572-30.314-30.314-30.314ZM71.611 192.299c-16.742 0-30.315 13.572-30.315 30.314s13.573 30.314 30.315 30.314c16.741 0 30.313-13.572 30.313-30.314 0-16.741-13.572-30.314-30.313-30.314Zm303.138 0c-16.729 0-30.294 13.551-30.315 30.275l.001.039-.001.038c.021 16.725 13.586 30.276 30.315 30.276 16.741 0 30.313-13.572 30.313-30.314 0-16.741-13.572-30.314-30.313-30.314ZM223.178 40.73c-16.742 0-30.314 13.573-30.314 30.315s13.573 30.313 30.314 30.313c16.742 0 30.313-13.572 30.314-30.313 0-16.742-13.572-30.314-30.314-30.315Z"/>
2352
2352
  </svg>`;
@@ -2763,7 +2763,7 @@ var __webpack_exports__ = {};
2763
2763
  }
2764
2764
  }));
2765
2765
  footerElement.appendChild(renderer_span({
2766
- text: `v${version}`
2766
+ text: "v2.0.0"
2767
2767
  }));
2768
2768
  }
2769
2769
  function renderErrorState(container) {
@@ -4068,7 +4068,8 @@ var __webpack_exports__ = {};
4068
4068
  'error',
4069
4069
  'consent',
4070
4070
  'network',
4071
- 'iab'
4071
+ 'iab',
4072
+ "script"
4072
4073
  ];
4073
4074
  function createFilterButton(filter, active, onClick) {
4074
4075
  return createButton({
@@ -4083,6 +4084,7 @@ var __webpack_exports__ = {};
4083
4084
  if ('error' === filter) return 'error' === event.type;
4084
4085
  if ('consent' === filter) return 'consent_set' === event.type || 'consent_save' === event.type || 'consent_reset' === event.type;
4085
4086
  if ('network' === filter) return 'network' === event.type;
4087
+ if ("script" === filter) return "script" === event.type;
4086
4088
  return 'iab' === event.type;
4087
4089
  }
4088
4090
  function matchesSearch(event, query) {
@@ -4206,6 +4208,8 @@ var __webpack_exports__ = {};
4206
4208
  return '◉';
4207
4209
  case 'iab':
4208
4210
  return '◆';
4211
+ case "script":
4212
+ return '⌘';
4209
4213
  default:
4210
4214
  return '○';
4211
4215
  }
@@ -4223,6 +4227,8 @@ var __webpack_exports__ = {};
4223
4227
  return 'var(--c15t-devtools-badge-warning, #f59e0b)';
4224
4228
  case 'iab':
4225
4229
  return 'var(--c15t-devtools-badge-info, #3b82f6)';
4230
+ case "script":
4231
+ return 'var(--c15t-devtools-badge-info, #14b8a6)';
4226
4232
  default:
4227
4233
  return 'var(--c15t-text-muted)';
4228
4234
  }
@@ -5523,6 +5529,20 @@ var __webpack_exports__ = {};
5523
5529
  <polyline points="8 6 2 12 8 18"></polyline>
5524
5530
  </svg>`;
5525
5531
  const scriptsSearchByContainer = new WeakMap();
5532
+ const expandedScriptsByContainer = new WeakMap();
5533
+ const CHEVRON_DOWN_ICON = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
5534
+ <polyline points="6 9 12 15 18 9"></polyline>
5535
+ </svg>`;
5536
+ const CHEVRON_RIGHT_ICON = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
5537
+ <polyline points="9 18 15 12 9 6"></polyline>
5538
+ </svg>`;
5539
+ function getExpandedScripts(container) {
5540
+ const existing = expandedScriptsByContainer.get(container);
5541
+ if (existing) return existing;
5542
+ const expanded = new Set();
5543
+ expandedScriptsByContainer.set(container, expanded);
5544
+ return expanded;
5545
+ }
5526
5546
  function renderScriptsPanel(container, options) {
5527
5547
  const { getState, getEvents } = options;
5528
5548
  clearElement(container);
@@ -5584,6 +5604,10 @@ var __webpack_exports__ = {};
5584
5604
  for (const script of filteredScripts){
5585
5605
  const scriptId = script.id;
5586
5606
  const isLoaded = true === loadedScripts[scriptId];
5607
+ const scriptEvents = getScriptActivityEvents(events, scriptId);
5608
+ const latestActivity = scriptEvents[scriptEvents.length - 1];
5609
+ const expandedScripts = getExpandedScripts(container);
5610
+ const isExpanded = expandedScripts.has(scriptId);
5587
5611
  const category = script.category;
5588
5612
  const categoryDisplay = 'string' == typeof category ? category : JSON.stringify(category);
5589
5613
  let status = 'pending';
@@ -5605,7 +5629,7 @@ var __webpack_exports__ = {};
5605
5629
  text: status.charAt(0).toUpperCase() + status.slice(1),
5606
5630
  variant: statusVariant
5607
5631
  });
5608
- const row = renderer_div({
5632
+ const header = renderer_div({
5609
5633
  style: {
5610
5634
  display: 'flex',
5611
5635
  alignItems: 'center',
@@ -5644,19 +5668,57 @@ var __webpack_exports__ = {};
5644
5668
  whiteSpace: 'nowrap'
5645
5669
  },
5646
5670
  text: `Category: ${categoryDisplay}`
5647
- })
5671
+ }),
5672
+ ...latestActivity && scriptEvents.length > 0 ? [
5673
+ renderer_div({
5674
+ style: {
5675
+ fontSize: 'var(--c15t-devtools-font-size-xs)',
5676
+ color: 'var(--c15t-text-muted)',
5677
+ overflow: 'hidden',
5678
+ textOverflow: 'ellipsis',
5679
+ whiteSpace: 'nowrap'
5680
+ },
5681
+ text: `Activity: ${latestActivity.message} (${scriptEvents.length} event${1 === scriptEvents.length ? '' : 's'})`
5682
+ })
5683
+ ] : []
5648
5684
  ]
5649
5685
  }),
5650
5686
  renderer_div({
5651
5687
  style: {
5652
- flexShrink: '0'
5688
+ flexShrink: '0',
5689
+ display: 'flex',
5690
+ alignItems: 'center',
5691
+ gap: '8px'
5653
5692
  },
5654
5693
  children: [
5655
- badge
5694
+ badge,
5695
+ ...scriptEvents.length > 0 ? [
5696
+ createAccordionToggle({
5697
+ scriptId,
5698
+ isExpanded,
5699
+ onToggle: ()=>{
5700
+ if (isExpanded) expandedScripts.delete(scriptId);
5701
+ else expandedScripts.add(scriptId);
5702
+ renderScriptsPanel(container, options);
5703
+ }
5704
+ })
5705
+ ] : []
5656
5706
  ]
5657
5707
  })
5658
5708
  ]
5659
5709
  });
5710
+ const details = isExpanded && scriptEvents.length > 0 ? createScriptActivityDetails(scriptEvents) : null;
5711
+ const row = renderer_div({
5712
+ style: {
5713
+ display: 'flex',
5714
+ flexDirection: 'column',
5715
+ borderBottom: '1px solid var(--c15t-border)'
5716
+ },
5717
+ children: [
5718
+ header,
5719
+ details
5720
+ ]
5721
+ });
5660
5722
  scriptsList.appendChild(row);
5661
5723
  }
5662
5724
  const lastRow = scriptsList.lastElementChild;
@@ -5793,13 +5855,172 @@ var __webpack_exports__ = {};
5793
5855
  return 'string' == typeof url ? url : event.message;
5794
5856
  }
5795
5857
  function formatEventTime(timestamp) {
5796
- return new Date(timestamp).toLocaleTimeString('en-US', {
5797
- hour12: false,
5798
- hour: '2-digit',
5799
- minute: '2-digit',
5800
- second: '2-digit'
5858
+ const date = new Date(timestamp);
5859
+ const hours = String(date.getHours()).padStart(2, '0');
5860
+ const minutes = String(date.getMinutes()).padStart(2, '0');
5861
+ const seconds = String(date.getSeconds()).padStart(2, '0');
5862
+ const milliseconds = String(date.getMilliseconds()).padStart(3, '0');
5863
+ return `${hours}:${minutes}:${seconds}.${milliseconds}`;
5864
+ }
5865
+ function getScriptActivityEvents(events, scriptId) {
5866
+ return events.filter((event)=>{
5867
+ if ("script" !== event.type) return false;
5868
+ const data = event.data;
5869
+ if (data?.scriptId !== scriptId) return false;
5870
+ return data?.scope === 'lifecycle' || data?.scope === 'phase';
5871
+ }).sort((left, right)=>left.timestamp - right.timestamp);
5872
+ }
5873
+ function createAccordionToggle(options) {
5874
+ const { scriptId, isExpanded, onToggle } = options;
5875
+ const toggle = renderer_button({
5876
+ ariaLabel: `${isExpanded ? 'Collapse' : 'Expand'} ${scriptId} activity`,
5877
+ ariaExpanded: isExpanded ? 'true' : 'false',
5878
+ style: {
5879
+ display: 'inline-flex',
5880
+ alignItems: 'center',
5881
+ justifyContent: 'center',
5882
+ width: '24px',
5883
+ height: '24px',
5884
+ padding: '0',
5885
+ border: '1px solid var(--c15t-border)',
5886
+ borderRadius: '6px',
5887
+ background: 'transparent',
5888
+ color: 'var(--c15t-text-muted)',
5889
+ cursor: 'pointer',
5890
+ flexShrink: '0'
5891
+ },
5892
+ onClick: onToggle
5893
+ });
5894
+ toggle.innerHTML = isExpanded ? CHEVRON_DOWN_ICON : CHEVRON_RIGHT_ICON;
5895
+ return toggle;
5896
+ }
5897
+ function createScriptActivityDetails(events) {
5898
+ const groupedEvents = groupScriptActivityEvents(events.slice(-8));
5899
+ return renderer_div({
5900
+ style: {
5901
+ display: 'flex',
5902
+ flexDirection: 'column',
5903
+ gap: '6px',
5904
+ padding: '0 0 10px 0',
5905
+ marginLeft: '0'
5906
+ },
5907
+ children: groupedEvents.map(([groupName, groupEvents])=>createScriptActivityGroup(groupName, groupEvents))
5908
+ });
5909
+ }
5910
+ function createScriptActivityGroup(groupName, events) {
5911
+ return renderer_div({
5912
+ style: {
5913
+ display: 'flex',
5914
+ flexDirection: 'column',
5915
+ gap: '4px'
5916
+ },
5917
+ children: [
5918
+ renderer_span({
5919
+ style: {
5920
+ fontSize: 'var(--c15t-devtools-font-size-xs)',
5921
+ fontWeight: '600',
5922
+ color: 'var(--c15t-text)',
5923
+ textTransform: 'none'
5924
+ },
5925
+ text: groupName
5926
+ }),
5927
+ ...events.map((event)=>createScriptActivityRow(event))
5928
+ ]
5801
5929
  });
5802
5930
  }
5931
+ function createScriptActivityRow(event) {
5932
+ const data = event.data ?? {};
5933
+ const scope = 'string' == typeof data.scope ? data.scope : void 0;
5934
+ const phase = 'string' == typeof data.phase ? data.phase : void 0;
5935
+ const stepType = 'string' == typeof data.stepType ? data.stepType : void 0;
5936
+ const metadata = [
5937
+ scope,
5938
+ phase,
5939
+ stepType
5940
+ ].filter(Boolean).join(' / ');
5941
+ return renderer_div({
5942
+ style: {
5943
+ display: 'flex',
5944
+ flexDirection: 'column',
5945
+ gap: '2px',
5946
+ padding: '6px 10px',
5947
+ marginLeft: '0',
5948
+ borderLeft: '2px solid var(--c15t-border)',
5949
+ backgroundColor: 'var(--c15t-devtools-surface-secondary, rgba(127,127,127,0.06))',
5950
+ borderRadius: '0 8px 8px 0'
5951
+ },
5952
+ children: [
5953
+ renderer_div({
5954
+ style: {
5955
+ display: 'flex',
5956
+ alignItems: 'center',
5957
+ justifyContent: 'space-between',
5958
+ gap: '8px'
5959
+ },
5960
+ children: [
5961
+ renderer_span({
5962
+ style: {
5963
+ fontSize: 'var(--c15t-devtools-font-size-xs)',
5964
+ fontWeight: '600',
5965
+ color: 'var(--c15t-text)'
5966
+ },
5967
+ text: event.message
5968
+ }),
5969
+ renderer_span({
5970
+ style: {
5971
+ fontSize: 'var(--c15t-devtools-font-size-xs)',
5972
+ color: 'var(--c15t-text-muted)',
5973
+ flexShrink: '0'
5974
+ },
5975
+ text: formatEventTime(event.timestamp)
5976
+ })
5977
+ ]
5978
+ }),
5979
+ ...metadata ? [
5980
+ renderer_span({
5981
+ style: {
5982
+ fontSize: 'var(--c15t-devtools-font-size-xs)',
5983
+ color: 'var(--c15t-text-muted)'
5984
+ },
5985
+ text: metadata
5986
+ })
5987
+ ] : []
5988
+ ]
5989
+ });
5990
+ }
5991
+ function groupScriptActivityEvents(events) {
5992
+ const groups = new Map();
5993
+ for (const event of events){
5994
+ const groupName = getScriptActivityGroupName(event);
5995
+ const existing = groups.get(groupName);
5996
+ if (existing) existing.push(event);
5997
+ else groups.set(groupName, [
5998
+ event
5999
+ ]);
6000
+ }
6001
+ const orderedGroupNames = [
6002
+ 'onBeforeLoad',
6003
+ 'onLoad',
6004
+ 'onConsentChange',
6005
+ 'other'
6006
+ ];
6007
+ return orderedGroupNames.map((groupName)=>{
6008
+ const groupEvents = groups.get(groupName);
6009
+ return groupEvents ? [
6010
+ groupName,
6011
+ groupEvents
6012
+ ] : null;
6013
+ }).filter((group)=>null !== group);
6014
+ }
6015
+ function getScriptActivityGroupName(event) {
6016
+ const data = event.data ?? {};
6017
+ if ('string' == typeof data.callback) return data.callback;
6018
+ const phase = 'string' == typeof data.phase ? data.phase : '';
6019
+ if ('bootstrap' === phase || 'consent-default' === phase || 'setup' === phase || 'onBeforeLoadGranted' === phase || 'onBeforeLoadDenied' === phase) return 'onBeforeLoad';
6020
+ if ('afterLoad' === phase || 'onLoadGranted' === phase || 'onLoadDenied' === phase) return 'onLoad';
6021
+ if ('consent-update' === phase || 'onConsentChange' === phase || 'onConsentGranted' === phase || 'onConsentDenied' === phase) return 'onConsentChange';
6022
+ return 'other';
6023
+ }
5803
6024
  function scripts_truncateText(text, maxLength) {
5804
6025
  if (text.length <= maxLength) return text;
5805
6026
  return `${text.slice(0, maxLength - 3)}...`;
@@ -6368,6 +6589,7 @@ var __webpack_exports__ = {};
6368
6589
  const state = entry.store.getState();
6369
6590
  state.setCallback('onBannerFetched', entry.originalCallbacks.onBannerFetched);
6370
6591
  state.setCallback('onConsentSet', entry.originalCallbacks.onConsentSet);
6592
+ state.setCallback('onConsentChanged', entry.originalCallbacks.onConsentChanged);
6371
6593
  state.setCallback('onError', entry.originalCallbacks.onError);
6372
6594
  state.setCallback('onBeforeConsentRevocationReload', entry.originalCallbacks.onBeforeConsentRevocationReload);
6373
6595
  const blocker = state.networkBlocker;
@@ -6405,6 +6627,14 @@ var __webpack_exports__ = {};
6405
6627
  });
6406
6628
  if ('function' == typeof entry.originalCallbacks.onConsentSet) entry.originalCallbacks.onConsentSet(payload);
6407
6629
  });
6630
+ store.getState().setCallback('onConsentChanged', (payload)=>{
6631
+ emitEvent(entry, {
6632
+ type: 'consent_save',
6633
+ message: 'Consent preferences changed',
6634
+ data: payload
6635
+ });
6636
+ if ('function' == typeof entry.originalCallbacks.onConsentChanged) entry.originalCallbacks.onConsentChanged(payload);
6637
+ });
6408
6638
  store.getState().setCallback('onError', (payload)=>{
6409
6639
  const errorMessage = payload.error;
6410
6640
  emitEvent(entry, {
@@ -6545,6 +6775,25 @@ var __webpack_exports__ = {};
6545
6775
  loadedScripts: state.loadedScripts
6546
6776
  };
6547
6777
  }
6778
+ function scriptDebugEventToLogEntry(event) {
6779
+ return {
6780
+ type: "script",
6781
+ message: event.message,
6782
+ data: {
6783
+ ...event.data ?? {},
6784
+ source: event.source,
6785
+ scope: event.scope,
6786
+ action: event.action,
6787
+ scriptId: event.scriptId,
6788
+ elementId: event.elementId,
6789
+ hasConsent: event.hasConsent,
6790
+ callback: event.callback,
6791
+ phase: event.phase,
6792
+ stepType: event.stepType,
6793
+ stepIndex: event.stepIndex
6794
+ }
6795
+ };
6796
+ }
6548
6797
  function createDevTools(options = {}) {
6549
6798
  const { namespace = 'c15tStore', position = 'bottom-right', defaultOpen = false } = options;
6550
6799
  const stateManager = state_manager_createStateManager({
@@ -6552,6 +6801,7 @@ var __webpack_exports__ = {};
6552
6801
  isOpen: defaultOpen
6553
6802
  });
6554
6803
  let detachInstrumentation = null;
6804
+ let detachScriptDebug = null;
6555
6805
  const storeConnector = store_connector_createStoreConnector({
6556
6806
  namespace,
6557
6807
  onConnect: (_state, store)=>{
@@ -6563,6 +6813,10 @@ var __webpack_exports__ = {};
6563
6813
  stateManager.addEvent(event);
6564
6814
  }
6565
6815
  });
6816
+ detachScriptDebug?.();
6817
+ detachScriptDebug = (0, external_c15t_namespaceObject.subscribeToScriptDebugEvents)((event)=>{
6818
+ stateManager.addEvent(scriptDebugEventToLogEntry(event));
6819
+ });
6566
6820
  stateManager.setConnected(true);
6567
6821
  stateManager.addEvent({
6568
6822
  type: 'info',
@@ -6599,6 +6853,8 @@ var __webpack_exports__ = {};
6599
6853
  stateManager.setConnected(false);
6600
6854
  detachInstrumentation?.();
6601
6855
  detachInstrumentation = null;
6856
+ detachScriptDebug?.();
6857
+ detachScriptDebug = null;
6602
6858
  stateManager.addEvent({
6603
6859
  type: 'error',
6604
6860
  message: 'Disconnected from c15tStore'
@@ -6688,6 +6944,8 @@ var __webpack_exports__ = {};
6688
6944
  destroy: ()=>{
6689
6945
  detachInstrumentation?.();
6690
6946
  detachInstrumentation = null;
6947
+ detachScriptDebug?.();
6948
+ detachScriptDebug = null;
6691
6949
  panelHeightAnimator.destroy();
6692
6950
  tabsInstance?.destroy();
6693
6951
  panelInstance.destroy();