@brightspot/ui 1.3.0 → 1.4.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.
Files changed (109) hide show
  1. package/dist/global.d.ts +10 -0
  2. package/dist/storybook/assets/{Avatar.stories-CpXI9mXR.js → Avatar.stories-DrhezTR1.js} +1 -1
  3. package/dist/storybook/assets/{AvatarGroup.stories-D4NymG47.js → AvatarGroup.stories-DrlxT-mF.js} +1 -1
  4. package/dist/storybook/assets/{Badge.stories-BP4Yixze.js → Badge.stories-DtJcBfOR.js} +1 -1
  5. package/dist/storybook/assets/{Button.stories-DDpQzCOq.js → Button.stories-BKUfLgSY.js} +1 -1
  6. package/dist/storybook/assets/{CircularProgress.stories-B82LXwfS.js → CircularProgress.stories-dpmD-XJT.js} +1 -1
  7. package/dist/storybook/assets/{ClipboardMixin.stories-Cr3efF-v.js → ClipboardMixin.stories-C0pnQ7BY.js} +1 -1
  8. package/dist/storybook/assets/{Color-64QXVMR3-BucypS4O.js → Color-64QXVMR3-Dnd9S2a1.js} +1 -1
  9. package/dist/storybook/assets/{Colors.stories-CeKs5FaB.js → Colors.stories-bKK25qgF.js} +1 -1
  10. package/dist/storybook/assets/{ComponentStatesMixin-BkLj42wt.js → ComponentStatesMixin-C2HZ9ZFb.js} +1 -1
  11. package/dist/storybook/assets/{ComponentStatesMixin.stories--YPoyrpQ.js → ComponentStatesMixin.stories-9mRp2zuB.js} +1 -1
  12. package/dist/storybook/assets/{CopyToClipboard.stories-6vqDwd-F.js → CopyToClipboard.stories-BW3oaT1i.js} +1 -1
  13. package/dist/storybook/assets/Debounce.stories-BXx3CKvQ.js +199 -0
  14. package/dist/storybook/assets/{Events.stories-DD9wfoHi.js → Events.stories-PBeiuWQn.js} +1 -1
  15. package/dist/storybook/assets/{Heading.stories-D-Pvm7NG.js → Heading.stories-Djkl0MoC.js} +1 -1
  16. package/dist/storybook/assets/{Icon.stories-BbR3S56H.js → Icon.stories-Cam1fyud.js} +1 -1
  17. package/dist/storybook/assets/{LinearProgress.stories-B9XHLvVn.js → LinearProgress.stories-BDNoYIJu.js} +1 -1
  18. package/dist/storybook/assets/Rtc.stories-BrTAIAi1.js +281 -0
  19. package/dist/storybook/assets/{ScrollShadow.stories-CHFpB4Zf.js → ScrollShadow.stories-DHcKhkag.js} +1 -1
  20. package/dist/storybook/assets/{Throttle.stories-BGNJSyDp.js → Throttle.stories-cSYT_BXu.js} +1 -1
  21. package/dist/storybook/assets/{WithTooltip-SK46ZJ2J-QQZnlVfm.js → WithTooltip-SK46ZJ2J-Df0E-KJO.js} +5 -5
  22. package/dist/storybook/assets/{formatter-OMEEQ6HG-D3LRXsK-.js → formatter-OMEEQ6HG-DFa_WTfb.js} +1 -1
  23. package/dist/storybook/assets/{iframe-CpEKhsmw.css → iframe-BMxUFmpF.css} +1 -1
  24. package/dist/storybook/assets/{iframe-D-tG1MVV.js → iframe-lTczLWsL.js} +73 -73
  25. package/dist/storybook/assets/{index-mcT8sPvs.js → index-yMswRDPh.js} +1 -1
  26. package/dist/storybook/assets/onFind-C6olvKHR.js +1 -0
  27. package/dist/storybook/assets/{onFind.stories-Dagoyfc5.js → onFind.stories-DfW54CDE.js} +10 -10
  28. package/dist/storybook/assets/onRemove.stories-C7W9KyRr.js +234 -0
  29. package/dist/storybook/assets/onVisible.stories-CIl6R0q4.js +187 -0
  30. package/dist/storybook/assets/{syntaxhighlighter-CAVLW7PM-BoS99i_u.js → syntaxhighlighter-CAVLW7PM-DoI0ixeu.js} +1 -1
  31. package/dist/storybook/iframe.html +2 -2
  32. package/dist/storybook/index.json +1 -1
  33. package/dist/storybook/project.json +1 -1
  34. package/dist/tailwind-plugin-button.js +3 -0
  35. package/dist/tailwind-plugin-button.js.map +1 -1
  36. package/dist/tailwind-plugin-button.ts +4 -0
  37. package/dist/util/Socket.d.ts +29 -0
  38. package/dist/util/Socket.d.ts.map +1 -0
  39. package/dist/util/Socket.js +153 -0
  40. package/dist/util/Socket.js.map +1 -0
  41. package/dist/util/Tether.d.ts +18 -0
  42. package/dist/util/Tether.d.ts.map +1 -0
  43. package/dist/util/Tether.js +102 -0
  44. package/dist/util/Tether.js.map +1 -0
  45. package/dist/util/TetherLayout.d.ts +12 -0
  46. package/dist/util/TetherLayout.d.ts.map +1 -0
  47. package/dist/util/TetherLayout.js +121 -0
  48. package/dist/util/TetherLayout.js.map +1 -0
  49. package/dist/util/debounce.d.ts +3 -0
  50. package/dist/util/debounce.d.ts.map +1 -0
  51. package/dist/util/debounce.js +15 -0
  52. package/dist/util/debounce.js.map +1 -0
  53. package/dist/util/focusable.d.ts +9 -0
  54. package/dist/util/focusable.d.ts.map +1 -0
  55. package/dist/util/focusable.js +19 -0
  56. package/dist/util/focusable.js.map +1 -0
  57. package/dist/util/getComponentKey.d.ts +2 -0
  58. package/dist/util/getComponentKey.d.ts.map +1 -0
  59. package/dist/util/getComponentKey.js +21 -0
  60. package/dist/util/getComponentKey.js.map +1 -0
  61. package/dist/util/keyboard.d.ts +8 -0
  62. package/dist/util/keyboard.d.ts.map +1 -0
  63. package/dist/util/keyboard.js +138 -0
  64. package/dist/util/keyboard.js.map +1 -0
  65. package/dist/util/noise.d.ts +6 -0
  66. package/dist/util/noise.d.ts.map +1 -0
  67. package/dist/util/noise.js +43 -0
  68. package/dist/util/noise.js.map +1 -0
  69. package/dist/util/onFindOnce.d.ts +3 -0
  70. package/dist/util/onFindOnce.d.ts.map +1 -0
  71. package/dist/util/onFindOnce.js +25 -0
  72. package/dist/util/onFindOnce.js.map +1 -0
  73. package/dist/util/onRTEReady.d.ts +22 -0
  74. package/dist/util/onRTEReady.d.ts.map +1 -0
  75. package/dist/util/onRTEReady.js +69 -0
  76. package/dist/util/onRTEReady.js.map +1 -0
  77. package/dist/util/onRemove.d.ts +7 -0
  78. package/dist/util/onRemove.d.ts.map +1 -0
  79. package/dist/util/onRemove.js +24 -0
  80. package/dist/util/onRemove.js.map +1 -0
  81. package/dist/util/onVisible.d.ts +3 -0
  82. package/dist/util/onVisible.d.ts.map +1 -0
  83. package/dist/util/onVisible.js +22 -0
  84. package/dist/util/onVisible.js.map +1 -0
  85. package/dist/util/previousUntil.d.ts +2 -0
  86. package/dist/util/previousUntil.d.ts.map +1 -0
  87. package/dist/util/previousUntil.js +21 -0
  88. package/dist/util/previousUntil.js.map +1 -0
  89. package/dist/util/repaint.d.ts +3 -0
  90. package/dist/util/repaint.d.ts.map +1 -0
  91. package/dist/util/repaint.js +14 -0
  92. package/dist/util/repaint.js.map +1 -0
  93. package/dist/util/rtc.d.ts +10 -0
  94. package/dist/util/rtc.d.ts.map +1 -0
  95. package/dist/util/rtc.js +184 -0
  96. package/dist/util/rtc.js.map +1 -0
  97. package/dist/util/storage.d.ts +6 -0
  98. package/dist/util/storage.d.ts.map +1 -0
  99. package/dist/util/storage.js +18 -0
  100. package/dist/util/storage.js.map +1 -0
  101. package/dist/util/transition.d.ts +2 -0
  102. package/dist/util/transition.d.ts.map +1 -0
  103. package/dist/util/transition.js +4 -0
  104. package/dist/util/transition.js.map +1 -0
  105. package/dist/util/types.d.ts +10 -0
  106. package/dist/util/types.d.ts.map +1 -0
  107. package/dist/util/types.js +2 -0
  108. package/dist/util/types.js.map +1 -0
  109. package/package.json +6 -2
@@ -0,0 +1,199 @@
1
+ import{x as c}from"./iframe-lTczLWsL.js";import"./preload-helper-PPVm8Dsz.js";function p(n,e){if(n<=0)return e;let t;return function(){clearTimeout(t),t=setTimeout(()=>{t=void 0,e.apply(this,[...arguments])},n)}}const g={title:"Utilities/Debounce",tags:["autodocs"],parameters:{docs:{subtitle:"The `debounce` utility delays function execution until a specified wait period has elapsed since the last invocation. Useful for search inputs, form validation, and window resize handlers."},controls:{expanded:!0}},argTypes:{wait:{control:{type:"number",min:0,max:2e3,step:50},description:"Debounce wait time in milliseconds"}},args:{wait:300}},o={render:n=>{const e=`debounce-${Math.random().toString(36).substring(2,9)}`;let t=0,i=0;const d=()=>{const a=document.getElementById(`${e}-normal-count`),r=document.getElementById(`${e}-debounced-count`);a&&(a.textContent=String(t)),r&&(r.textContent=String(i))},l=p(n.wait,()=>{i++,d()}),u=()=>{t++,d(),l()};return c`
2
+ <div class="space-y-4">
3
+ <div class="text-base">
4
+ <p class="mb-2">
5
+ Type in the input below. The normal counter increments on every keystroke, while the debounced counter only
6
+ fires after ${n.wait}ms of inactivity.
7
+ </p>
8
+ </div>
9
+
10
+ <input
11
+ @input=${u}
12
+ type="text"
13
+ placeholder="Start typing..."
14
+ class="w-full rounded border-2 border-gray-300 px-4 py-2 focus:border-blue-500 focus:outline-none"
15
+ />
16
+
17
+ <div class="flex justify-around">
18
+ <div>
19
+ <div class="text-xs text-gray-500">Keystrokes</div>
20
+ <div id="${e}-normal-count" class="text-2xl font-bold text-gray-900">0</div>
21
+ </div>
22
+ <div>
23
+ <div class="text-xs text-gray-500">Debounced calls (${n.wait}ms)</div>
24
+ <div id="${e}-debounced-count" class="text-primary-600 text-2xl font-bold">0</div>
25
+ </div>
26
+ </div>
27
+
28
+ <button
29
+ @click=${()=>{t=0,i=0,d()}}
30
+ class="rounded bg-gray-200 px-4 py-2 hover:bg-gray-300"
31
+ >
32
+ Reset Counters
33
+ </button>
34
+ </div>
35
+ `},parameters:{docs:{description:{story:"Interactive example showing debounce in action. Type rapidly in the input to see how the debounced handler waits for a pause before executing."}}}},s={render:()=>c`
36
+ <div class="space-y-4 text-sm">
37
+ <div>
38
+ <h3 class="mb-2 font-bold">Basic Usage</h3>
39
+ <pre
40
+ class="overflow-x-auto rounded bg-gray-900 p-4 text-gray-100"
41
+ ><code>import { debounce } from '@brightspot/ui/dist/util/debounce.js'
42
+
43
+ const handleSearch = debounce(300, () => {
44
+ console.log('Search triggered after 300ms of inactivity')
45
+ })
46
+
47
+ input.addEventListener('input', handleSearch)</code></pre>
48
+ </div>
49
+
50
+ <div>
51
+ <h3 class="mb-2 font-bold">Debounce vs Throttle</h3>
52
+ <ul class="list-inside list-disc space-y-1 text-gray-700">
53
+ <li><strong>Debounce</strong>: Waits until activity stops, then fires once</li>
54
+ <li><strong>Throttle</strong>: Fires at regular intervals during activity</li>
55
+ <li>Use debounce for search inputs, form validation, window resize end</li>
56
+ <li>Use throttle for scroll handlers, mouse tracking, progress updates</li>
57
+ </ul>
58
+ </div>
59
+
60
+ <div>
61
+ <h3 class="mb-2 font-bold">Parameters</h3>
62
+ <ul class="space-y-2">
63
+ <li>
64
+ <code class="rounded bg-gray-200 px-1">wait</code> (number): Delay in milliseconds. If 0, the function
65
+ passes through unchanged.
66
+ </li>
67
+ <li><code class="rounded bg-gray-200 px-1">fn</code> (function): The function to debounce</li>
68
+ </ul>
69
+ </div>
70
+
71
+ <div>
72
+ <h3 class="mb-2 font-bold">Returns</h3>
73
+ <p class="text-gray-700">
74
+ A debounced version of the input function that delays execution until
75
+ <code class="rounded bg-gray-200 px-1">wait</code> milliseconds have elapsed since the last call.
76
+ </p>
77
+ </div>
78
+ </div>
79
+ `,parameters:{docs:{description:{story:"Code examples and documentation for using the debounce utility."}}}};o.parameters={...o.parameters,docs:{...o.parameters?.docs,source:{originalSource:`{
80
+ render: args => {
81
+ const instanceId = \`debounce-\${Math.random().toString(36).substring(2, 9)}\`;
82
+ let normalCount = 0;
83
+ let debouncedCount = 0;
84
+ const updateCounts = () => {
85
+ const normalEl = document.getElementById(\`\${instanceId}-normal-count\`);
86
+ const debouncedEl = document.getElementById(\`\${instanceId}-debounced-count\`);
87
+ if (normalEl) normalEl.textContent = String(normalCount);
88
+ if (debouncedEl) debouncedEl.textContent = String(debouncedCount);
89
+ };
90
+ const handleDebounced = debounce(args.wait, () => {
91
+ debouncedCount++;
92
+ updateCounts();
93
+ });
94
+ const handleInput = () => {
95
+ normalCount++;
96
+ updateCounts();
97
+ handleDebounced();
98
+ };
99
+ return html\`
100
+ <div class="space-y-4">
101
+ <div class="text-base">
102
+ <p class="mb-2">
103
+ Type in the input below. The normal counter increments on every keystroke, while the debounced counter only
104
+ fires after \${args.wait}ms of inactivity.
105
+ </p>
106
+ </div>
107
+
108
+ <input
109
+ @input=\${handleInput}
110
+ type="text"
111
+ placeholder="Start typing..."
112
+ class="w-full rounded border-2 border-gray-300 px-4 py-2 focus:border-blue-500 focus:outline-none"
113
+ />
114
+
115
+ <div class="flex justify-around">
116
+ <div>
117
+ <div class="text-xs text-gray-500">Keystrokes</div>
118
+ <div id="\${instanceId}-normal-count" class="text-2xl font-bold text-gray-900">0</div>
119
+ </div>
120
+ <div>
121
+ <div class="text-xs text-gray-500">Debounced calls (\${args.wait}ms)</div>
122
+ <div id="\${instanceId}-debounced-count" class="text-primary-600 text-2xl font-bold">0</div>
123
+ </div>
124
+ </div>
125
+
126
+ <button
127
+ @click=\${() => {
128
+ normalCount = 0;
129
+ debouncedCount = 0;
130
+ updateCounts();
131
+ }}
132
+ class="rounded bg-gray-200 px-4 py-2 hover:bg-gray-300"
133
+ >
134
+ Reset Counters
135
+ </button>
136
+ </div>
137
+ \`;
138
+ },
139
+ parameters: {
140
+ docs: {
141
+ description: {
142
+ story: \`Interactive example showing debounce in action. Type rapidly in the input to see how the debounced handler waits for a pause before executing.\`
143
+ }
144
+ }
145
+ }
146
+ }`,...o.parameters?.docs?.source}}};s.parameters={...s.parameters,docs:{...s.parameters?.docs,source:{originalSource:`{
147
+ render: () => html\`
148
+ <div class="space-y-4 text-sm">
149
+ <div>
150
+ <h3 class="mb-2 font-bold">Basic Usage</h3>
151
+ <pre
152
+ class="overflow-x-auto rounded bg-gray-900 p-4 text-gray-100"
153
+ ><code>import { debounce } from '@brightspot/ui/dist/util/debounce.js'
154
+
155
+ const handleSearch = debounce(300, () => {
156
+ console.log('Search triggered after 300ms of inactivity')
157
+ })
158
+
159
+ input.addEventListener('input', handleSearch)</code></pre>
160
+ </div>
161
+
162
+ <div>
163
+ <h3 class="mb-2 font-bold">Debounce vs Throttle</h3>
164
+ <ul class="list-inside list-disc space-y-1 text-gray-700">
165
+ <li><strong>Debounce</strong>: Waits until activity stops, then fires once</li>
166
+ <li><strong>Throttle</strong>: Fires at regular intervals during activity</li>
167
+ <li>Use debounce for search inputs, form validation, window resize end</li>
168
+ <li>Use throttle for scroll handlers, mouse tracking, progress updates</li>
169
+ </ul>
170
+ </div>
171
+
172
+ <div>
173
+ <h3 class="mb-2 font-bold">Parameters</h3>
174
+ <ul class="space-y-2">
175
+ <li>
176
+ <code class="rounded bg-gray-200 px-1">wait</code> (number): Delay in milliseconds. If 0, the function
177
+ passes through unchanged.
178
+ </li>
179
+ <li><code class="rounded bg-gray-200 px-1">fn</code> (function): The function to debounce</li>
180
+ </ul>
181
+ </div>
182
+
183
+ <div>
184
+ <h3 class="mb-2 font-bold">Returns</h3>
185
+ <p class="text-gray-700">
186
+ A debounced version of the input function that delays execution until
187
+ <code class="rounded bg-gray-200 px-1">wait</code> milliseconds have elapsed since the last call.
188
+ </p>
189
+ </div>
190
+ </div>
191
+ \`,
192
+ parameters: {
193
+ docs: {
194
+ description: {
195
+ story: \`Code examples and documentation for using the debounce utility.\`
196
+ }
197
+ }
198
+ }
199
+ }`,...s.parameters?.docs?.source}}};const h=["Interactive","UsageExample"];export{o as Interactive,s as UsageExample,h as __namedExportsOrder,g as default};
@@ -1,4 +1,4 @@
1
- import{x as d}from"./iframe-D-tG1MVV.js";import"./preload-helper-PPVm8Dsz.js";var n=Object.freeze,r=Object.defineProperty,s=(t,i)=>n(r(t,"raw",{value:n(t.slice())})),o;const l={title:"Mixins/Events",tags:["autodocs"],parameters:{docs:{subtitle:"Events inherited from EventEmitterMixin",description:{component:`
1
+ import{x as d}from"./iframe-lTczLWsL.js";import"./preload-helper-PPVm8Dsz.js";var n=Object.freeze,r=Object.defineProperty,s=(t,i)=>n(r(t,"raw",{value:n(t.slice())})),o;const l={title:"Mixins/Events",tags:["autodocs"],parameters:{docs:{subtitle:"Events inherited from EventEmitterMixin",description:{component:`
2
2
  <h3>EventEmitterMixin Events</h3>
3
3
 
4
4
  <p>All Brightspot UI components that extend EventEmitterMixin emit the following lifecycle events in addition to those inherited from LitElement. These events use CustomEvent and bubble through the DOM with <code>composed: true</code>, meaning they cross shadow DOM boundaries.</p>
@@ -1,3 +1,3 @@
1
- import{x as s}from"./iframe-D-tG1MVV.js";import"./preload-helper-PPVm8Dsz.js";const r=({size:t})=>s` <div class=${[`btu-heading-${t}`].join(" ")}>Heading</div> `,o={title:"CSS Plugins/Heading",component:"btu-heading",tags:["autodocs"],parameters:{docs:{subtitle:"This Tailwind CSS plugin provides the `.btu-heading` utility class for styling headings. It supports five different sizes, from 1 (largest) to 5 (smallest). Apply the class to `<h1>` through `<h5>` elements to style them accordingly."},controls:{expanded:!0}},render:t=>r(t),argTypes:{size:{control:{type:"range",min:1,max:5,step:1},description:"Heading size from 1 to 5, where 1 is the largest and 5 is the smallest."}},args:{size:1}},e={args:{}};e.parameters={...e.parameters,docs:{...e.parameters?.docs,source:{originalSource:`{
1
+ import{x as s}from"./iframe-lTczLWsL.js";import"./preload-helper-PPVm8Dsz.js";const r=({size:t})=>s` <div class=${[`btu-heading-${t}`].join(" ")}>Heading</div> `,o={title:"CSS Plugins/Heading",component:"btu-heading",tags:["autodocs"],parameters:{docs:{subtitle:"This Tailwind CSS plugin provides the `.btu-heading` utility class for styling headings. It supports five different sizes, from 1 (largest) to 5 (smallest). Apply the class to `<h1>` through `<h5>` elements to style them accordingly."},controls:{expanded:!0}},render:t=>r(t),argTypes:{size:{control:{type:"range",min:1,max:5,step:1},description:"Heading size from 1 to 5, where 1 is the largest and 5 is the smallest."}},args:{size:1}},e={args:{}};e.parameters={...e.parameters,docs:{...e.parameters?.docs,source:{originalSource:`{
2
2
  args: {}
3
3
  }`,...e.parameters?.docs?.source}}};const n=["Default"];export{e as Default,n as __namedExportsOrder,o as default};
@@ -1,4 +1,4 @@
1
- import{g as d,x as r}from"./iframe-D-tG1MVV.js";import"./preload-helper-PPVm8Dsz.js";const p="0.508.0",b={version:p},l=b.version,{events:u,args:m,argTypes:t}=d("btu-icon"),g=["xs","sm","md","lg","xl"],x=["ai","error","gray","primary","purple","rose","success","teal","warning"],v={title:"Components/Icon",component:"btu-icon",tags:["autodocs"],parameters:{docs:{subtitle:"An icon component using Lucide icons with built-in support for custom colors and sizes.",description:{component:`
1
+ import{g as d,x as r}from"./iframe-lTczLWsL.js";import"./preload-helper-PPVm8Dsz.js";const p="0.508.0",b={version:p},l=b.version,{events:u,args:m,argTypes:t}=d("btu-icon"),g=["xs","sm","md","lg","xl"],x=["ai","error","gray","primary","purple","rose","success","teal","warning"],v={title:"Components/Icon",component:"btu-icon",tags:["autodocs"],parameters:{docs:{subtitle:"An icon component using Lucide icons with built-in support for custom colors and sizes.",description:{component:`
2
2
  <strong>When to use:</strong>
3
3
  <ul>
4
4
  <li>To visually reinforce actions, states, or categories</li>
@@ -1,4 +1,4 @@
1
- import{g as I,E as h,x as T}from"./iframe-D-tG1MVV.js";import"./preload-helper-PPVm8Dsz.js";const{events:D,args:V,argTypes:g}=I("btu-linear-progress"),k={title:"Components/Linear Progress",component:"btu-linear-progress",tags:["autodocs"],parameters:{docs:{subtitle:"A horizontal progress bar for showing task completion",description:{component:`
1
+ import{g as I,E as h,x as T}from"./iframe-lTczLWsL.js";import"./preload-helper-PPVm8Dsz.js";const{events:D,args:V,argTypes:g}=I("btu-linear-progress"),k={title:"Components/Linear Progress",component:"btu-linear-progress",tags:["autodocs"],parameters:{docs:{subtitle:"A horizontal progress bar for showing task completion",description:{component:`
2
2
  <h3>When to use:</h3>
3
3
  <ul>
4
4
  <li>To show progress of a specific task with known completion percentage</li>
@@ -0,0 +1,281 @@
1
+ import{x as o}from"./iframe-lTczLWsL.js";import"./preload-helper-PPVm8Dsz.js";const r={title:"Utilities/RTC",tags:["autodocs"],parameters:{docs:{subtitle:"The `rtc` module provides real-time communication between browser tabs and the Brightspot CMS server. Uses BroadcastChannel for cross-tab coordination with leader election, and Server-Sent Events for server communication."},controls:{expanded:!0}}},e={render:()=>o`
2
+ <div class="space-y-6 text-sm">
3
+ <div>
4
+ <h3 class="mb-2 font-bold">Overview</h3>
5
+ <p class="mb-4 text-gray-700">
6
+ The RTC module manages real-time updates between the CMS server and multiple browser tabs. It uses a
7
+ leader-election pattern so only one tab maintains a server connection, then broadcasts messages to other tabs
8
+ via BroadcastChannel.
9
+ </p>
10
+ </div>
11
+
12
+ <div class="rounded border border-gray-200 bg-gray-50 p-4">
13
+ <h4 class="mb-2 font-bold">Architecture Diagram</h4>
14
+ <pre class="text-xs leading-relaxed text-gray-700">
15
+ ┌─────────────────────────────────────────────────┐
16
+ │ CMS Server │
17
+ │ (Server-Sent Events) │
18
+ └────────────────────┬────────────────────────────┘
19
+
20
+ ┌──────┴──────┐
21
+ │ Leader Tab │ ← Socket connection
22
+ │ (Tab 1) │
23
+ └──────┬──────┘
24
+ │ BroadcastChannel
25
+ ┌──────────┼──────────┐
26
+ │ │ │
27
+ ┌────┴───┐ ┌───┴────┐ ┌──┴─────┐
28
+ │ Tab 2 │ │ Tab 3 │ │ Tab 4 │
29
+ └────────┘ └────────┘ └────────┘</pre
30
+ >
31
+ </div>
32
+
33
+ <div>
34
+ <h3 class="mb-2 font-bold">Key Concepts</h3>
35
+ <ul class="list-inside list-disc space-y-1 text-gray-700">
36
+ <li><strong>Leader election</strong>: One tab owns the server connection; others communicate through it</li>
37
+ <li>
38
+ <strong>State restore</strong>: When connecting, each tab restores its subscribed states from the server
39
+ </li>
40
+ <li><strong>Broadcasts</strong>: Server pushes events (publish, assignment, conversation) to all tabs</li>
41
+ <li>
42
+ <strong>Graceful degradation</strong>: When RTC is disabled or no user session exists, all methods become
43
+ no-ops
44
+ </li>
45
+ </ul>
46
+ </div>
47
+ </div>
48
+ `,parameters:{docs:{description:{story:"High-level architecture of the RTC (Real-Time Communication) system."}}}},t={render:()=>o`
49
+ <div class="space-y-4 text-sm">
50
+ <div>
51
+ <h3 class="mb-2 font-bold">Receiving Broadcasts</h3>
52
+ <pre
53
+ class="overflow-x-auto rounded bg-gray-900 p-4 text-gray-100"
54
+ ><code>import rtc from '@brightspot/ui/dist/util/rtc.js'
55
+
56
+ // Listen for content publish events
57
+ rtc.receive('com.psddev.cms.tool.page.content.PublishBroadcast', (data) => {
58
+ console.log('Content published:', data)
59
+ refreshContent()
60
+ })
61
+
62
+ // Listen once (single-fire)
63
+ rtc.receiveOnce('com.psddev.cms.conversation.PostBroadcast', () => {
64
+ showNotification('New conversation post')
65
+ })</code></pre>
66
+ </div>
67
+
68
+ <div>
69
+ <h3 class="mb-2 font-bold">State Management</h3>
70
+ <pre
71
+ class="overflow-x-auto rounded bg-gray-900 p-4 text-gray-100"
72
+ ><code>// Initialize a stateful connection (auto-disconnects on page unload)
73
+ rtc.initialize('com.example.MyState', { id: '123' }, () => {
74
+ console.log('State restored from server')
75
+ })
76
+
77
+ // Restore state without unload handling
78
+ rtc.restore('com.example.MyState', { id: '123' }, () => {
79
+ console.log('State restored')
80
+ })</code></pre>
81
+ </div>
82
+
83
+ <div>
84
+ <h3 class="mb-2 font-bold">Executing Actions</h3>
85
+ <pre class="overflow-x-auto rounded bg-gray-900 p-4 text-gray-100"><code>// Send an action to the server
86
+ rtc.execute('com.example.MyAction', { id: '123', value: 'updated' })</code></pre>
87
+ </div>
88
+
89
+ <div>
90
+ <h3 class="mb-2 font-bold">API Reference</h3>
91
+ <ul class="space-y-2">
92
+ <li>
93
+ <code class="rounded bg-gray-200 px-1">rtc.initialize(state, data, callback)</code> — Connect to server
94
+ state with automatic unload cleanup
95
+ </li>
96
+ <li>
97
+ <code class="rounded bg-gray-200 px-1">rtc.restore(state, data, callback)</code> — Restore state from server
98
+ without unload handling
99
+ </li>
100
+ <li>
101
+ <code class="rounded bg-gray-200 px-1">rtc.receive(broadcast, callback)</code> — Subscribe to broadcast
102
+ events (fires on every occurrence)
103
+ </li>
104
+ <li>
105
+ <code class="rounded bg-gray-200 px-1">rtc.receiveOnce(broadcast, callback)</code> — Subscribe to a
106
+ broadcast event (fires once)
107
+ </li>
108
+ <li>
109
+ <code class="rounded bg-gray-200 px-1">rtc.execute(action, data)</code> — Send an action to the server
110
+ </li>
111
+ </ul>
112
+ </div>
113
+
114
+ <div>
115
+ <h3 class="mb-2 font-bold">Configuration</h3>
116
+ <ul class="list-inside list-disc space-y-1 text-gray-700">
117
+ <li>
118
+ <code class="rounded bg-gray-200 px-1">window.DISABLE_RTC</code> — Set to
119
+ <code class="rounded bg-gray-200 px-1">true</code> to disable all RTC functionality
120
+ </li>
121
+ <li>
122
+ <code class="rounded bg-gray-200 px-1">window.ROOT_PATH</code> — Server root path for the
123
+ <code class="rounded bg-gray-200 px-1">/_rtc</code> endpoint
124
+ </li>
125
+ <li>
126
+ <code class="rounded bg-gray-200 px-1">data-user-id</code> on
127
+ <code class="rounded bg-gray-200 px-1">&lt;html&gt;</code> — Required for RTC to activate
128
+ </li>
129
+ </ul>
130
+ </div>
131
+ </div>
132
+ `,parameters:{docs:{description:{story:"Code examples and API documentation for the RTC module."}}}};e.parameters={...e.parameters,docs:{...e.parameters?.docs,source:{originalSource:`{
133
+ render: () => html\`
134
+ <div class="space-y-6 text-sm">
135
+ <div>
136
+ <h3 class="mb-2 font-bold">Overview</h3>
137
+ <p class="mb-4 text-gray-700">
138
+ The RTC module manages real-time updates between the CMS server and multiple browser tabs. It uses a
139
+ leader-election pattern so only one tab maintains a server connection, then broadcasts messages to other tabs
140
+ via BroadcastChannel.
141
+ </p>
142
+ </div>
143
+
144
+ <div class="rounded border border-gray-200 bg-gray-50 p-4">
145
+ <h4 class="mb-2 font-bold">Architecture Diagram</h4>
146
+ <pre class="text-xs leading-relaxed text-gray-700">
147
+ ┌─────────────────────────────────────────────────┐
148
+ │ CMS Server │
149
+ │ (Server-Sent Events) │
150
+ └────────────────────┬────────────────────────────┘
151
+
152
+ ┌──────┴──────┐
153
+ │ Leader Tab │ ← Socket connection
154
+ │ (Tab 1) │
155
+ └──────┬──────┘
156
+ │ BroadcastChannel
157
+ ┌──────────┼──────────┐
158
+ │ │ │
159
+ ┌────┴───┐ ┌───┴────┐ ┌──┴─────┐
160
+ │ Tab 2 │ │ Tab 3 │ │ Tab 4 │
161
+ └────────┘ └────────┘ └────────┘</pre
162
+ >
163
+ </div>
164
+
165
+ <div>
166
+ <h3 class="mb-2 font-bold">Key Concepts</h3>
167
+ <ul class="list-inside list-disc space-y-1 text-gray-700">
168
+ <li><strong>Leader election</strong>: One tab owns the server connection; others communicate through it</li>
169
+ <li>
170
+ <strong>State restore</strong>: When connecting, each tab restores its subscribed states from the server
171
+ </li>
172
+ <li><strong>Broadcasts</strong>: Server pushes events (publish, assignment, conversation) to all tabs</li>
173
+ <li>
174
+ <strong>Graceful degradation</strong>: When RTC is disabled or no user session exists, all methods become
175
+ no-ops
176
+ </li>
177
+ </ul>
178
+ </div>
179
+ </div>
180
+ \`,
181
+ parameters: {
182
+ docs: {
183
+ description: {
184
+ story: \`High-level architecture of the RTC (Real-Time Communication) system.\`
185
+ }
186
+ }
187
+ }
188
+ }`,...e.parameters?.docs?.source}}};t.parameters={...t.parameters,docs:{...t.parameters?.docs,source:{originalSource:`{
189
+ render: () => html\`
190
+ <div class="space-y-4 text-sm">
191
+ <div>
192
+ <h3 class="mb-2 font-bold">Receiving Broadcasts</h3>
193
+ <pre
194
+ class="overflow-x-auto rounded bg-gray-900 p-4 text-gray-100"
195
+ ><code>import rtc from '@brightspot/ui/dist/util/rtc.js'
196
+
197
+ // Listen for content publish events
198
+ rtc.receive('com.psddev.cms.tool.page.content.PublishBroadcast', (data) => {
199
+ console.log('Content published:', data)
200
+ refreshContent()
201
+ })
202
+
203
+ // Listen once (single-fire)
204
+ rtc.receiveOnce('com.psddev.cms.conversation.PostBroadcast', () => {
205
+ showNotification('New conversation post')
206
+ })</code></pre>
207
+ </div>
208
+
209
+ <div>
210
+ <h3 class="mb-2 font-bold">State Management</h3>
211
+ <pre
212
+ class="overflow-x-auto rounded bg-gray-900 p-4 text-gray-100"
213
+ ><code>// Initialize a stateful connection (auto-disconnects on page unload)
214
+ rtc.initialize('com.example.MyState', { id: '123' }, () => {
215
+ console.log('State restored from server')
216
+ })
217
+
218
+ // Restore state without unload handling
219
+ rtc.restore('com.example.MyState', { id: '123' }, () => {
220
+ console.log('State restored')
221
+ })</code></pre>
222
+ </div>
223
+
224
+ <div>
225
+ <h3 class="mb-2 font-bold">Executing Actions</h3>
226
+ <pre class="overflow-x-auto rounded bg-gray-900 p-4 text-gray-100"><code>// Send an action to the server
227
+ rtc.execute('com.example.MyAction', { id: '123', value: 'updated' })</code></pre>
228
+ </div>
229
+
230
+ <div>
231
+ <h3 class="mb-2 font-bold">API Reference</h3>
232
+ <ul class="space-y-2">
233
+ <li>
234
+ <code class="rounded bg-gray-200 px-1">rtc.initialize(state, data, callback)</code> — Connect to server
235
+ state with automatic unload cleanup
236
+ </li>
237
+ <li>
238
+ <code class="rounded bg-gray-200 px-1">rtc.restore(state, data, callback)</code> — Restore state from server
239
+ without unload handling
240
+ </li>
241
+ <li>
242
+ <code class="rounded bg-gray-200 px-1">rtc.receive(broadcast, callback)</code> — Subscribe to broadcast
243
+ events (fires on every occurrence)
244
+ </li>
245
+ <li>
246
+ <code class="rounded bg-gray-200 px-1">rtc.receiveOnce(broadcast, callback)</code> — Subscribe to a
247
+ broadcast event (fires once)
248
+ </li>
249
+ <li>
250
+ <code class="rounded bg-gray-200 px-1">rtc.execute(action, data)</code> — Send an action to the server
251
+ </li>
252
+ </ul>
253
+ </div>
254
+
255
+ <div>
256
+ <h3 class="mb-2 font-bold">Configuration</h3>
257
+ <ul class="list-inside list-disc space-y-1 text-gray-700">
258
+ <li>
259
+ <code class="rounded bg-gray-200 px-1">window.DISABLE_RTC</code> — Set to
260
+ <code class="rounded bg-gray-200 px-1">true</code> to disable all RTC functionality
261
+ </li>
262
+ <li>
263
+ <code class="rounded bg-gray-200 px-1">window.ROOT_PATH</code> — Server root path for the
264
+ <code class="rounded bg-gray-200 px-1">/_rtc</code> endpoint
265
+ </li>
266
+ <li>
267
+ <code class="rounded bg-gray-200 px-1">data-user-id</code> on
268
+ <code class="rounded bg-gray-200 px-1">&lt;html&gt;</code> — Required for RTC to activate
269
+ </li>
270
+ </ul>
271
+ </div>
272
+ </div>
273
+ \`,
274
+ parameters: {
275
+ docs: {
276
+ description: {
277
+ story: \`Code examples and API documentation for the RTC module.\`
278
+ }
279
+ }
280
+ }
281
+ }`,...t.parameters?.docs?.source}}};const n=["Architecture","UsageExample"];export{e as Architecture,t as UsageExample,n as __namedExportsOrder,r as default};
@@ -1,4 +1,4 @@
1
- import{x as a}from"./iframe-D-tG1MVV.js";import"./preload-helper-PPVm8Dsz.js";const l=({theme:e="btu-scrollshadow-25"})=>{const r=new Array(100).fill(0).map((s,t)=>`Item ${t+1}`);return a`
1
+ import{x as a}from"./iframe-lTczLWsL.js";import"./preload-helper-PPVm8Dsz.js";const l=({theme:e="btu-scrollshadow-25"})=>{const r=new Array(100).fill(0).map((s,t)=>`Item ${t+1}`);return a`
2
2
  <style>
3
3
  :root {
4
4
  --can-scroll: ;
@@ -1,4 +1,4 @@
1
- import{x as u}from"./iframe-D-tG1MVV.js";import"./preload-helper-PPVm8Dsz.js";function v(e,t){if(e<=0)return t;let n,o=0;return function(){if(n)return;const r=Date.now(),s=e-r+o;s<=0?(o=r,t.apply(this,[...arguments])):n=setTimeout(()=>{o=r,n=void 0,t.apply(this,[...arguments])},s)}}const x={title:"Utilities/Throttle",tags:["autodocs"],parameters:{docs:{subtitle:"The `throttle` utility function limits how often a function can execute, ensuring it runs at most once per specified interval. Useful for high-frequency events like scroll, resize, or mousemove."},controls:{expanded:!0}},argTypes:{interval:{control:{type:"number",min:0,max:2e3,step:50},description:"Throttle interval in milliseconds"}},args:{interval:200}},a={render:e=>{const t=`throttle-${Math.random().toString(36).substring(2,9)}`;let n=0,o=0;const r=()=>{const h=document.getElementById(`${t}-normal-count`),m=document.getElementById(`${t}-throttled-count`);h&&(h.textContent=String(n)),m&&(m.textContent=String(o))},s=v(e.interval,()=>{o++,r()}),d=()=>{n++,r()},l=()=>{d(),s()};return u`
1
+ import{x as u}from"./iframe-lTczLWsL.js";import"./preload-helper-PPVm8Dsz.js";function v(e,t){if(e<=0)return t;let n,o=0;return function(){if(n)return;const r=Date.now(),s=e-r+o;s<=0?(o=r,t.apply(this,[...arguments])):n=setTimeout(()=>{o=r,n=void 0,t.apply(this,[...arguments])},s)}}const x={title:"Utilities/Throttle",tags:["autodocs"],parameters:{docs:{subtitle:"The `throttle` utility function limits how often a function can execute, ensuring it runs at most once per specified interval. Useful for high-frequency events like scroll, resize, or mousemove."},controls:{expanded:!0}},argTypes:{interval:{control:{type:"number",min:0,max:2e3,step:50},description:"Throttle interval in milliseconds"}},args:{interval:200}},a={render:e=>{const t=`throttle-${Math.random().toString(36).substring(2,9)}`;let n=0,o=0;const r=()=>{const h=document.getElementById(`${t}-normal-count`),m=document.getElementById(`${t}-throttled-count`);h&&(h.textContent=String(n)),m&&(m.textContent=String(o))},s=v(e.interval,()=>{o++,r()}),d=()=>{n++,r()},l=()=>{d(),s()};return u`
2
2
  <div class="space-y-4">
3
3
  <div class="text-base">
4
4
  <p class="mb-2">