@spfx-fast/spfx-workbench 0.0.0-stage → 0.1.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 (41) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +240 -2
  3. package/bin/spfx-workbench-auth.mjs +143 -0
  4. package/bin/spfx-workbench-capture.mjs +5 -0
  5. package/bin/spfx-workbench-debug.mjs +155 -0
  6. package/bin/spfx-workbench-doctor.mjs +2 -0
  7. package/bin/spfx-workbench-heft-target.mjs +2 -0
  8. package/bin/spfx-workbench-replay.mjs +2 -0
  9. package/bin/spfx-workbench.mjs +97 -0
  10. package/docs/mock-data-and-capture.md +52 -0
  11. package/docs/sharepoint-behavior-snapshot-2026-11-15-1455Z.md +67 -0
  12. package/fixtures/library-items.synthetic.json +23 -0
  13. package/index.html +13 -0
  14. package/package.json +58 -4
  15. package/scripts/benchmark-capture-import.mjs +50 -0
  16. package/scripts/benchmark-consumer-hmr.mjs +251 -0
  17. package/scripts/benchmark-mock-api.mjs +114 -0
  18. package/scripts/check-tarball-install.mjs +413 -0
  19. package/scripts/diagnose-consumer.mjs +228 -0
  20. package/scripts/diff-captures.mjs +452 -0
  21. package/scripts/import-synthetic-capture.mjs +60 -0
  22. package/scripts/minimal-playwright-state.mjs +15 -0
  23. package/scripts/mock-contract.mjs +375 -0
  24. package/scripts/replay-sharepoint-capture.mjs +123 -0
  25. package/scripts/resolve-chromium.mjs +22 -0
  26. package/scripts/resolve-serve-target.mjs +70 -0
  27. package/scripts/spfx-node-runtime.mjs +19 -0
  28. package/scripts/watch-sharepoint-capture.mjs +395 -0
  29. package/scripts/write-local-capture.mjs +121 -0
  30. package/src/auth-state.mjs +44 -0
  31. package/src/contracts/sharepoint-rest.d.ts +38 -0
  32. package/src/contracts/simulator-context.d.ts +38 -0
  33. package/src/data-source-label.mjs +10 -0
  34. package/src/format-modified.mjs +8 -0
  35. package/src/lifecycle-webpart.jsx +43 -0
  36. package/src/main.jsx +14 -0
  37. package/src/simulator-context.mjs +94 -0
  38. package/src/spfx-preview-shims.mjs +21 -0
  39. package/src/workbench.css +187 -0
  40. package/src/workbench.jsx +222 -0
  41. package/vite.config.js +399 -0
@@ -0,0 +1,43 @@
1
+ import { useEffect, useRef, useState } from 'react';
2
+ import { createSimulatorContext } from './simulator-context.mjs';
3
+
4
+ export default function LifecycleWebPart({ Component, properties }) {
5
+ const host = useRef(null);
6
+ const [error, setError] = useState('');
7
+
8
+ useEffect(() => {
9
+ let active = true;
10
+ let instance;
11
+ let observer;
12
+ (async () => {
13
+ try {
14
+ instance = new Component();
15
+ const context = createSimulatorContext({
16
+ domElement: host.current,
17
+ manifest: Component.manifest ?? Component.Manifest ?? null,
18
+ });
19
+ Object.defineProperties(instance, {
20
+ context: { configurable: true, value: context },
21
+ properties: { configurable: true, writable: true, value: properties ?? {} },
22
+ });
23
+ await instance.onInit?.();
24
+ if (!active) return;
25
+ instance.render();
26
+ if (typeof instance.onAfterResize === 'function' && globalThis.ResizeObserver) {
27
+ observer = new globalThis.ResizeObserver((entries) => instance.onAfterResize(entries[0]?.contentRect.width ?? 0));
28
+ observer.observe(host.current);
29
+ }
30
+ } catch (cause) {
31
+ if (active) setError(cause?.stack ?? String(cause));
32
+ }
33
+ })();
34
+ return () => {
35
+ active = false;
36
+ observer?.disconnect();
37
+ try { instance?.onDispose?.(); }
38
+ catch (cause) { console.error('SPFx Workbench onDispose failed', cause); }
39
+ };
40
+ }, []);
41
+
42
+ return <div ref={host} className="spfx-lifecycle-host" role={error ? 'alert' : undefined}>{error}</div>;
43
+ }
package/src/main.jsx ADDED
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ import { createRoot } from 'react-dom/client';
3
+ import Workbench from './workbench.jsx';
4
+ import './workbench.css';
5
+ import ConsumerComponent from 'virtual:spfx-workbench-consumer';
6
+ import { createSimulatorContext } from './simulator-context.mjs';
7
+ const componentTitle = import.meta.env.VITE_SPFX_WORKBENCH_TITLE || 'Component preview';
8
+
9
+ const root = createRoot(document.getElementById('root'));
10
+ root.render(
11
+ <React.StrictMode>
12
+ <Workbench context={createSimulatorContext()} PreviewComponent={ConsumerComponent} ComponentTitle={componentTitle}/>
13
+ </React.StrictMode>,
14
+ );
@@ -0,0 +1,94 @@
1
+ import { CAPTURED_READ_POST_ROUTES, MOCK_HAR_API_PATH, MOCK_WEB_TITLE } from '../scripts/mock-contract.mjs';
2
+
3
+ const supportedPageContext = {
4
+ web: { title: MOCK_WEB_TITLE, absoluteUrl: 'https://contoso.sharepoint.test/sites/workbench', serverRelativeUrl: '/sites/workbench' },
5
+ site: { absoluteUrl: 'https://contoso.sharepoint.test', serverRelativeUrl: '/' },
6
+ user: { displayName: 'Workbench User', loginName: 'workbench.user@contoso.invalid' },
7
+ };
8
+
9
+ function supported(label, values) {
10
+ return new Proxy(values, {
11
+ get(target, key) {
12
+ if (typeof key === 'symbol' || Object.hasOwn(target, key)) return target[key];
13
+ throw new Error(`SPFx Workbench simulator does not support ${label}.${String(key)}. Supply a supported component prop or run the component through Heft on a SharePoint page.`);
14
+ },
15
+ set(_target, key) {
16
+ throw new Error(`SPFx Workbench simulator context is read-only; cannot set ${label}.${String(key)}.`);
17
+ },
18
+ deleteProperty(_target, key) {
19
+ throw new Error(`SPFx Workbench simulator context is read-only; cannot delete ${label}.${String(key)}.`);
20
+ },
21
+ defineProperty(_target, key) {
22
+ throw new Error(`SPFx Workbench simulator context is read-only; cannot define ${label}.${String(key)}.`);
23
+ },
24
+ });
25
+ }
26
+
27
+ function createCapturedSPHttpClient() {
28
+ const webUrl = new URL(supportedPageContext.web.absoluteUrl);
29
+ const sessionId = globalThis.crypto?.randomUUID?.() ?? `${Date.now()}-0000-4000-8000-000000000001`;
30
+ const replay = async (method, requestUrl, configuration, options) => {
31
+ if (typeof requestUrl !== 'string' || !configuration || typeof configuration !== 'object' || Array.isArray(configuration)) {
32
+ throw new Error(`SPFx Workbench simulator spHttpClient.${method.toLowerCase()} requires a URL and an SPHttpClientConfiguration object.`);
33
+ }
34
+ let requestBody = '';
35
+ if (method === 'GET' && options !== undefined) {
36
+ throw new Error('SPFx Workbench simulator spHttpClient.get does not support request options.');
37
+ }
38
+ if (method === 'POST') {
39
+ if (!options || typeof options !== 'object' || Array.isArray(options) || typeof options.body !== 'string'
40
+ || Object.keys(options).some((key) => !['body', 'headers'].includes(key))) {
41
+ throw new Error('SPFx Workbench simulator spHttpClient.post supports captured read-only POSTs with a string body and optional headers only.');
42
+ }
43
+ let parsedBody;
44
+ try { parsedBody = JSON.parse(options.body); } catch {}
45
+ if (!parsedBody || typeof parsedBody !== 'object' || Array.isArray(parsedBody)) {
46
+ throw new Error('SPFx Workbench simulator spHttpClient.post requires a JSON object body for captured replay.');
47
+ }
48
+ requestBody = options.body;
49
+ }
50
+
51
+ let target;
52
+ try { target = new URL(requestUrl, `${webUrl.href.replace(/\/$/, '')}/`); }
53
+ catch { throw new Error(`SPFx Workbench simulator spHttpClient.${method.toLowerCase()} received an invalid URL.`); }
54
+ if (!['http:', 'https:'].includes(target.protocol) || target.username || target.password || target.hash
55
+ || !target.pathname.includes('/_api/')) {
56
+ throw new Error(`SPFx Workbench simulator supports only HTTP(S) SharePoint REST ${method} URLs.`);
57
+ }
58
+ if (method === 'POST' && !CAPTURED_READ_POST_ROUTES.some(({ pattern }) => pattern.test(target.pathname))) {
59
+ throw new Error('SPFx Workbench simulator spHttpClient.post supports only captured read-only API routes.');
60
+ }
61
+
62
+ return fetch(MOCK_HAR_API_PATH, {
63
+ method: 'POST',
64
+ cache: 'no-store',
65
+ credentials: 'omit',
66
+ redirect: 'error',
67
+ headers: { 'Content-Type': 'application/json' },
68
+ body: JSON.stringify({ url: target.href, sessionId, method, requestBody }),
69
+ });
70
+ };
71
+ return supported('context.spHttpClient', {
72
+ get: (requestUrl, configuration, options) => replay('GET', requestUrl, configuration, options),
73
+ post: (requestUrl, configuration, options) => replay('POST', requestUrl, configuration, options),
74
+ });
75
+ }
76
+
77
+ /** Read-only context subset modeled from SPFx 1.24.1 declarations; captured REST calls replay locally before synthetic fallback. */
78
+ export function createSimulatorContext({ domElement = null, manifest = null, displayMode = 2 } = {}) {
79
+ const pageContext = supported('context.pageContext', {
80
+ web: supported('context.pageContext.web', supportedPageContext.web),
81
+ site: supported('context.pageContext.site', supportedPageContext.site),
82
+ user: supported('context.pageContext.user', supportedPageContext.user),
83
+ });
84
+ return supported('context', {
85
+ pageContext,
86
+ instanceId: '00000000-0000-4000-8000-000000000001',
87
+ domElement,
88
+ manifest,
89
+ displayMode,
90
+ isServedFromLocalhost: true,
91
+ sdks: supported('context.sdks', { microsoftTeams: undefined }),
92
+ spHttpClient: createCapturedSPHttpClient(),
93
+ });
94
+ }
@@ -0,0 +1,21 @@
1
+ export class BaseClientSideWebPart {
2
+ get domElement() { return this.context?.domElement ?? null; }
3
+ }
4
+
5
+ export class Version {
6
+ constructor(value) { this.value = String(value); }
7
+ static parse(value) { return new Version(value); }
8
+ toString() { return this.value; }
9
+ }
10
+
11
+ export function PropertyPaneTextField(target, options = {}) {
12
+ return { type: 'TextField', target, ...options };
13
+ }
14
+
15
+ export function escape(value) {
16
+ return String(value).replace(/[&<>"']/g, (character) => ({
17
+ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;',
18
+ })[character]);
19
+ }
20
+
21
+ export const IReadonlyTheme = Object.freeze({});
@@ -0,0 +1,187 @@
1
+ :root {
2
+ font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
3
+ color: #323130;
4
+ background: #f3f2f1;
5
+ font-synthesis: none;
6
+ text-rendering: optimizeLegibility;
7
+ font-optical-sizing: auto;
8
+ }
9
+ * { box-sizing: border-box; }
10
+ body { min-width: 320px; min-height: 100vh; margin: 0; }
11
+ button, input, select { font: inherit; }
12
+ button, select { color: inherit; cursor: pointer; }
13
+ button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--theme-primary); outline-offset: 2px; }
14
+ .workbench { min-height: 100vh; --theme-primary: #0078d4; --theme-dark: #005a9e; --theme-light: #eff6fc; }
15
+ .workbench-bar { height: 52px; padding: 0 20px; display: flex; align-items: center; gap: 22px; background: #fff; border-bottom: 1px solid #edebe9; }
16
+ .workbench-name { display: flex; align-items: center; gap: 10px; white-space: nowrap; font-size: 14px; }
17
+ .workbench-mark { width: 26px; height: 26px; display: grid; place-items: center; border-radius: 2px; background: var(--theme-primary); color: white; font-size: 14px; font-weight: 700; }
18
+ .simulation-status { display: flex; align-items: center; gap: 7px; margin-left: auto; color: #605e5c; font-size: 12px; white-space: nowrap; }
19
+ .simulation-status i, .webpart-caption i { width: 8px; height: 8px; border-radius: 50%; background: #107c10; }
20
+ .simulation-status.is-error i { background: #a4262c; }
21
+ .theme-picker { display: flex; align-items: center; gap: 7px; color: #605e5c; font-size: 12px; white-space: nowrap; }
22
+ .theme-picker select { max-width: 145px; height: 34px; padding: 0 25px 0 8px; border: 1px solid #8a8886; border-radius: 2px; background: white; font-size: 12px; }
23
+ .workbench-layout { min-height: calc(100vh - 52px); display: flex; }
24
+ .canvas-area { min-width: 0; flex: 1; padding: 28px 24px 50px; }
25
+ .canvas-toolbar { max-width: 1204px; margin: 0 auto 16px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
26
+ .canvas-toolbar h1 { margin: 0; font-size: 20px; line-height: 1.3; font-weight: 600; letter-spacing: -0.02em; }
27
+ .canvas-toolbar p { margin: 4px 0 0; color: #605e5c; font-size: 13px; }
28
+ .page-actions { display: flex; align-items: center; gap: 8px; }
29
+ .outline-action, .primary-action { min-height: 36px; padding: 0 10px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; border: 1px solid var(--theme-primary); border-radius: 2px; font-size: 12px; font-weight: 600; white-space: nowrap; }
30
+ .outline-action { background: white; color: var(--theme-dark); }
31
+ .outline-action:hover { background: var(--theme-light); }
32
+ .primary-action { background: var(--theme-primary); color: white; }
33
+ .primary-action:hover { background: var(--theme-dark); }
34
+ .primary-action:disabled { cursor: not-allowed; opacity: .55; }
35
+ .outline-action svg, .primary-action svg, .canvas-add svg, .column-add svg, .webpart-choice > svg { width: 16px; height: 16px; flex: 0 0 16px; }
36
+ .page-canvas { width: 100%; max-width: 1204px; min-height: min(680px, calc(100vh - 160px)); margin: 0 auto; border: 1px solid #edebe9; background: white; }
37
+ .section-group { width: 100%; }
38
+ .page-section { width: 100%; margin: 0 0 16px; padding: 8px 10px 14px; background: white; color: #323130; }
39
+ .section-width-oneThird { width: 33.333333%; }
40
+ .section-width-oneHalf { width: 50%; }
41
+ .section-width-twoThirds { width: 66.666667%; }
42
+ .section-width-full { width: 100%; }
43
+ .page-section.is-selected { outline: 1px solid #c8c6c4; outline-offset: 0; }
44
+ .page-section.emphasis-neutral { background: #f3f2f1; }
45
+ .page-section.emphasis-soft { background: var(--theme-light); }
46
+ .page-section.emphasis-strong { background: var(--theme-primary); color: white; }
47
+ .page-section.section-full-screen { position: relative; left: 50%; width: 100vw; max-width: none; margin-left: -50vw; padding-right: max(20px, calc((100vw - 1204px) / 2)); padding-left: max(20px, calc((100vw - 1204px) / 2)); }
48
+ .section-insert-row { position: relative; min-height: 44px; margin: -8px 0 8px; display: grid; place-items: center; }
49
+ .section-insert-row::before { position: absolute; right: 0; left: 0; border-top: 1px solid #edebe9; content: ""; }
50
+ .section-insert { z-index: 1; width: 30px; height: 30px; padding: 6px; display: grid; place-items: center; border: 1px solid #8a8886; border-radius: 50%; background: white; color: var(--theme-dark); }
51
+ .section-insert svg { width: 16px; height: 16px; }
52
+ .section-insert:hover { border-color: var(--theme-primary); background: var(--theme-light); }
53
+ .section-toolbar { min-height: 36px; margin-bottom: 9px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
54
+ .section-name, .section-edit { min-height: 34px; padding: 0 9px; border: 0; background: transparent; color: inherit; font-size: 11px; }
55
+ .section-name { font-weight: 600; }
56
+ .section-edit { color: var(--theme-dark); }
57
+ .emphasis-strong .section-edit { color: white; }
58
+ .section-name:hover, .section-edit:hover { background: #0000000b; }
59
+ .section-columns { display: grid; grid-template-columns: minmax(0, 1fr); align-items: start; gap: 16px; }
60
+ .layout-twoColumns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
61
+ .layout-threeColumns { grid-template-columns: repeat(3, minmax(0, 1fr)); }
62
+ .layout-oneThirdLeftColumn { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }
63
+ .layout-oneThirdRightColumn { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
64
+ .layout-fullWidth { grid-template-columns: minmax(0, 1fr); }
65
+ .section-column { min-width: 0; container-type: inline-size; }
66
+ .simulated-webpart { min-width: 0; margin-bottom: 12px; border: 1px solid #edebe9; background: white; color: #323130; }
67
+ .consumer-component-host { min-width: 0; padding: 14px; overflow-wrap: anywhere; }
68
+ .webpart-heading { min-height: 62px; padding: 10px 14px; display: flex; align-items: center; justify-content: space-between; gap: 10px; border-bottom: 1px solid #edebe9; }
69
+ .webpart-heading > div { min-width: 0; }
70
+ .webpart-heading h2 { margin: 0; overflow-wrap: anywhere; font-size: 17px; line-height: 1.35; font-weight: 600; }
71
+ .webpart-heading p { margin: 3px 0 0; color: #605e5c; font-size: 11px; }
72
+ .webpart-settings { min-height: 34px; padding: 0 9px; border: 1px solid #8a8886; border-radius: 2px; background: white; font-size: 11px; }
73
+ .webpart-settings:hover, .pane-close:hover { background: #f3f2f1; }
74
+ .document-list { width: 100%; }
75
+ .document-row { min-height: 43px; display: grid; grid-template-columns: minmax(0, 1fr) minmax(120px, 190px) minmax(80px, 120px); align-items: center; gap: 10px; padding: 0 14px; border-bottom: 1px solid #edebe9; color: #605e5c; font-size: 12px; }
76
+ .document-row:last-child { border-bottom: 0; }
77
+ .document-row strong { min-width: 0; overflow: hidden; color: #323130; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
78
+ .document-header { min-height: 36px; background: #faf9f8; color: #605e5c; font-size: 11px; font-weight: 600; }
79
+ .is-compact .document-row { min-height: 32px; }
80
+ .is-compact .document-header { min-height: 30px; }
81
+ .document-tiles { padding: 14px; display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; }
82
+ .document-tile { min-width: 0; min-height: 112px; padding: 12px; display: flex; flex-direction: column; align-items: flex-start; gap: 7px; border: 1px solid #edebe9; background: white; }
83
+ .tile-file { width: 34px; height: 40px; display: grid; place-items: center; border: 1px solid var(--theme-primary); color: var(--theme-dark); font-size: 15px; }
84
+ .document-tile strong { width: 100%; overflow: hidden; font-size: 12px; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
85
+ .document-tile small { color: #605e5c; font-size: 10px; }
86
+ .canvas-message { padding: 30px 14px; color: #605e5c; font-size: 12px; text-align: center; }
87
+ .webpart-caption { min-height: 30px; padding: 0 14px; display: flex; align-items: center; gap: 7px; border-top: 1px solid #edebe9; color: #605e5c; font-size: 10px; }
88
+ .webpart-caption i { width: 7px; height: 7px; }
89
+ .column-add, .canvas-add { min-height: 40px; width: 100%; padding: 0 10px; display: flex; align-items: center; justify-content: center; gap: 8px; border: 1px dashed #8a8886; background: #ffffffcc; color: var(--theme-dark); font-size: 12px; }
90
+ .column-add:hover, .canvas-add:hover { border-color: var(--theme-primary); background: var(--theme-light); }
91
+ .canvas-add { max-width: 260px; margin: 20px auto; }
92
+ .side-pane { position: fixed; z-index: 6; top: 52px; bottom: 0; width: 280px; overflow: auto; padding: 18px; background: white; box-shadow: 0 8px 24px #0002; }
93
+ .toolbox { left: 0; }
94
+ .inspector { right: 0; }
95
+ .pane-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
96
+ .pane-title h2 { margin: 0; font-size: 15px; font-weight: 600; }
97
+ .pane-close { width: 36px; height: 36px; border: 0; background: transparent; font-size: 22px; line-height: 1; }
98
+ .pane-description { margin: 6px 0 18px; color: #605e5c; font-size: 12px; line-height: 1.5; }
99
+ .webpart-catalog { max-height: calc(100vh - 210px); overflow-y: auto; display: grid; gap: 6px; padding: 1px; }
100
+ .webpart-choice { width: 100%; min-height: 62px; padding: 8px; display: flex; align-items: center; gap: 10px; border: 1px solid #c8c6c4; border-radius: 2px; background: white; text-align: left; }
101
+ .webpart-choice:hover { border-color: var(--theme-primary); background: var(--theme-light); }
102
+ .webpart-choice:disabled { opacity: .68; cursor: not-allowed; }
103
+ .webpart-choice.is-in-development { border-color: var(--theme-primary); background: var(--theme-light); }
104
+ .webpart-icon { width: 36px; height: 36px; display: grid; place-items: center; background: var(--theme-light); color: var(--theme-dark); }
105
+ .webpart-icon svg { width: 20px; height: 20px; }
106
+ .webpart-choice span:nth-child(2) { min-width: 0; flex: 1; }
107
+ .webpart-choice strong, .webpart-choice small { display: block; }
108
+ .webpart-choice strong { font-size: 12px; }
109
+ .webpart-choice small { margin-top: 4px; color: #605e5c; font-size: 10px; }
110
+ .development-badge { padding: 3px 6px; border-radius: 2px; background: var(--theme-primary); color: white; font-size: 9px; font-weight: 700; white-space: nowrap; }
111
+ .webpart-choice > svg { color: var(--theme-dark); }
112
+ .setting-field { margin: 0 0 16px; display: grid; gap: 6px; color: #605e5c; font-size: 11px; }
113
+ .setting-field select, .setting-field input { width: 100%; min-height: 36px; padding: 0 8px; border: 1px solid #8a8886; border-radius: 2px; background: white; color: #323130; font-size: 12px; }
114
+ .property-list { margin: 8px 0; }
115
+ .property-list div { padding: 10px 0; border-bottom: 1px solid #edebe9; }
116
+ .property-list dt { margin-bottom: 4px; color: #605e5c; font-size: 10px; }
117
+ .property-list dd { margin: 0; overflow-wrap: anywhere; color: #323130; font-size: 11px; }
118
+ .inspector h3 { margin: 18px 0 7px; font-size: 12px; }
119
+ .supported-reads { margin: 0; padding-left: 17px; color: #605e5c; font-size: 11px; line-height: 1.8; }
120
+ .boundary-note { margin: 14px 0; padding: 9px; background: #f3f2f1; color: #605e5c; font-size: 10px; line-height: 1.5; }
121
+ .remove-webpart { min-height: 36px; width: 100%; border: 1px solid #a4262c; border-radius: 2px; background: white; color: #a4262c; font-size: 11px; }
122
+ .remove-webpart:hover { background: #fdf3f4; }
123
+ .pane-backdrop { position: fixed; z-index: 5; inset: 52px 0 0; display: block; border: 0; background: #0003; }
124
+ .sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
125
+
126
+ @media (max-width: 1023px) {
127
+ .layout-threeColumns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
128
+ }
129
+ @media (max-width: 860px) {
130
+ .side-pane { width: min(300px, 84vw); }
131
+ }
132
+ @media (min-width: 1366px) {
133
+ .canvas-area { padding-right: 32px; padding-left: 32px; }
134
+ }
135
+ @media (max-width: 700px) {
136
+ .simulation-status { display: none; }
137
+ .workbench-bar { padding-right: 12px; padding-left: 12px; gap: 12px; }
138
+ .theme-picker { margin-left: auto; }
139
+ }
140
+ @media (max-width: 639px) {
141
+ .layout-twoColumns, .layout-threeColumns, .layout-oneThirdLeftColumn, .layout-oneThirdRightColumn { grid-template-columns: minmax(0, 1fr); }
142
+ }
143
+ @container (max-width: 360px) {
144
+ .webpart-heading { gap: 4px; padding: 8px; }
145
+ .webpart-heading h2 { font-size: 15px; }
146
+ .document-row { min-height: 42px; grid-template-columns: minmax(0, 1fr) minmax(78px, 105px); gap: 6px; padding: 0 9px; font-size: 10px; }
147
+ .document-row > :nth-child(3) { display: none; }
148
+ .document-header { font-size: 10px; }
149
+ }
150
+ @media (min-width: 480px) and (max-width: 767px) {
151
+ .canvas-area { padding-right: 16px; padding-left: 16px; }
152
+ }
153
+ @media (max-width: 479px) {
154
+ .workbench-name { gap: 7px; font-size: 12px; }
155
+ .workbench-mark { width: 23px; height: 23px; }
156
+ .theme-picker { gap: 4px; font-size: 10px; }
157
+ .theme-picker select { max-width: 118px; height: 32px; font-size: 10px; }
158
+ .canvas-area { padding: 20px 20px 32px; }
159
+ .canvas-toolbar { align-items: flex-start; flex-direction: column; margin-bottom: 12px; }
160
+ .canvas-toolbar h1 { font-size: 18px; }
161
+ .canvas-toolbar p { font-size: 12px; }
162
+ .page-actions { width: 100%; }
163
+ .page-actions button { flex: 1; }
164
+ .page-canvas { min-height: calc(100vh - 170px); }
165
+ .page-section { padding: 6px 0 10px; }
166
+ .webpart-heading { align-items: flex-start; padding: 10px; }
167
+ .document-row { min-height: 42px; grid-template-columns: minmax(0, 1fr) minmax(78px, 105px); gap: 6px; padding: 0 9px; font-size: 10px; }
168
+ .document-row > :nth-child(3) { display: none; }
169
+ .document-header { font-size: 10px; }
170
+ .document-tiles { grid-template-columns: repeat(auto-fill, minmax(105px, 1fr)); gap: 8px; padding: 9px; }
171
+ .document-tile { min-height: 100px; padding: 8px; }
172
+ .section-full-screen { padding-right: 20px; padding-left: 20px; }
173
+ }
174
+ @media (max-width: 639px) {
175
+ .section-width-oneThird, .section-width-oneHalf, .section-width-twoThirds { width: 100%; }
176
+ }
177
+ @media (max-width: 360px) {
178
+ .theme-picker > span { display: none; }
179
+ .theme-picker select { max-width: 100px; }
180
+ }
181
+ @media (min-width: 361px) and (max-width: 479px) {
182
+ .theme-picker select { max-width: 140px; }
183
+ }
184
+ @media (pointer: coarse) {
185
+ .theme-picker select, .outline-action, .primary-action, .section-name, .section-edit, .section-insert, .webpart-settings, .column-add, .canvas-add, .pane-close, .webpart-choice, .setting-field select, .setting-field input, .remove-webpart { min-height: 44px; }
186
+ .section-insert { width: 44px; }
187
+ }
@@ -0,0 +1,222 @@
1
+ import { useEffect, useRef, useState } from 'react';
2
+ import { dataSourceLabel } from './data-source-label.mjs';
3
+ import { formatModified } from './format-modified.mjs';
4
+
5
+ const fileKinds = { aspx: 'Page', doc: 'Document', docx: 'Document', ppt: 'Presentation', pptx: 'Presentation', xls: 'Spreadsheet', xlsx: 'Spreadsheet' };
6
+ const layouts = [
7
+ ['oneColumn', 'One column', 1], ['twoColumns', 'One-half / one-half', 2], ['threeColumns', 'Three columns', 3],
8
+ ['oneThirdLeftColumn', 'One-third / two-thirds', 2], ['oneThirdRightColumn', 'Two-thirds / one-third', 2], ['fullWidth', 'Full-width column', 1],
9
+ ];
10
+ const sectionWidths = [['oneThird', 'One-third'], ['oneHalf', 'One-half'], ['twoThirds', 'Two-thirds'], ['full', 'Full width'], ['fullScreen', 'Full screen']];
11
+ const emphasis = [['none', 'None'], ['neutral', 'Neutral'], ['soft', 'Soft'], ['strong', 'Strong']];
12
+ const views = [['details', 'List'], ['compact', 'Compact list'], ['tiles', 'Tiles']];
13
+ const themes = {
14
+ blue: { name: 'SharePoint blue', primary: '#0078d4', dark: '#005a9e', light: '#eff6fc' },
15
+ teal: { name: 'Teal', primary: '#038387', dark: '#006b70', light: '#eff9f8' },
16
+ purple: { name: 'Purple', primary: '#5c2d91', dark: '#4b2378', light: '#f5f0fa' },
17
+ };
18
+
19
+ function mapListItem(item) {
20
+ const fileName = item.FileLeafRef ?? '';
21
+ const extension = fileName.split('.').pop()?.toLowerCase() ?? '';
22
+ return { id: item.Id, title: item.Title || fileName || `Item ${item.Id}`, modified: formatModified(item.Modified), kind: fileKinds[extension] ?? 'File' };
23
+ }
24
+
25
+ function AddIcon() {
26
+ return <svg aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round"><path d="M12 5v14M5 12h14"/></svg>;
27
+ }
28
+
29
+ function SectionOptions({ section, onWidth, onLayout, onEmphasis }) {
30
+ return <>
31
+ <label className="setting-field">Section width<select value={section.width} onChange={(event) => onWidth(event.target.value)}>{sectionWidths.map(([value, label]) => <option key={value} value={value}>{label}</option>)}</select></label>
32
+ <label className="setting-field">Section layout<select value={section.layout} onChange={(event) => onLayout(event.target.value)}>{layouts.map(([value, label]) => <option key={value} value={value}>{label}</option>)}</select></label>
33
+ <label className="setting-field">Background<select value={section.emphasis} onChange={(event) => onEmphasis(event.target.value)}>{emphasis.map(([value, label]) => <option key={value} value={value}>{label}</option>)}</select></label>
34
+ </>;
35
+ }
36
+
37
+ export default function App({ context, PreviewComponent, ComponentTitle = 'Component preview' }) {
38
+ const [rows, setRows] = useState([]);
39
+ const [dataSource, setDataSource] = useState('loading');
40
+ const [dataError, setDataError] = useState(false);
41
+ const [query, setQuery] = useState('');
42
+ const [theme, setTheme] = useState('blue');
43
+ const [sections, setSections] = useState(() => [{ id: 1, width: 'full', layout: 'oneColumn', emphasis: 'none', columns: [[PreviewComponent ? { id: 1, type: 'consumer-component', title: ComponentTitle } : { id: 1, type: 'document-library', view: 'details' }]] }]);
44
+ const [selectedSectionId, setSelectedSectionId] = useState(1);
45
+ const [selectedPartId, setSelectedPartId] = useState(null);
46
+ const [showToolbox, setShowToolbox] = useState(false);
47
+ const [inspectorOpen, setInspectorOpen] = useState(false);
48
+ const [target, setTarget] = useState({ sectionId: 1, columnIndex: 0 });
49
+ const nextSectionId = useRef(2);
50
+ const nextPartId = useRef(2);
51
+ const selectedSection = sections.find((section) => section.id === selectedSectionId);
52
+ const selectedPart = selectedSection?.columns.flat().find((part) => part.id === selectedPartId);
53
+ const pageContext = context?.pageContext;
54
+ const hasLibrary = sections.some((section) => section.columns.flat().some((part) => part.type === 'document-library'));
55
+ const visibleRows = rows.filter((row) => `${row.title} ${row.kind}`.toLowerCase().includes(query.toLowerCase()));
56
+ const themeColors = themes[theme];
57
+ const visibleWebparts = [{ name: 'Document library' }, ...(PreviewComponent ? [{ name: ComponentTitle }] : [])];
58
+ const needsListRows = sections.some((section) => section.columns.flat().some((part) => part.type === 'document-library'));
59
+
60
+ useEffect(() => {
61
+ if (!needsListRows) return;
62
+ let current = true;
63
+ fetch('/__spfx_workbench/api/library-items')
64
+ .then((response) => {
65
+ if (!response.ok) throw new Error('mock response unavailable');
66
+ const source = response.headers.get('X-SPFx-Workbench-Data') ?? 'local mock';
67
+ return response.json().then((body) => ({ body, source }));
68
+ })
69
+ .then(({ body, source }) => {
70
+ if (!current) return;
71
+ setRows((body.value ?? []).map(mapListItem));
72
+ setDataSource(source);
73
+ })
74
+ .catch(() => { if (current) { setDataError(true); setDataSource('unavailable'); } });
75
+ return () => { current = false; };
76
+ }, [needsListRows]);
77
+
78
+ function updateSection(sectionId, update) {
79
+ setSections((current) => current.map((section) => section.id === sectionId ? { ...section, ...update(section) } : section));
80
+ }
81
+
82
+ function changeLayout(section, layout) {
83
+ const columns = layouts.find(([value]) => value === layout)[2];
84
+ const parts = section.columns.flat();
85
+ const nextColumns = Array.from({ length: columns }, (_, columnIndex) => parts.filter((_, index) => index % columns === columnIndex));
86
+ updateSection(section.id, () => ({ layout, columns: nextColumns }));
87
+ }
88
+
89
+ function addSection(afterSectionId) {
90
+ const id = nextSectionId.current++;
91
+ setSections((current) => {
92
+ const afterIndex = current.findIndex((section) => section.id === afterSectionId);
93
+ const insertAt = afterIndex < 0 ? current.length : afterIndex + 1;
94
+ return [...current.slice(0, insertAt), { id, width: 'full', layout: 'oneColumn', emphasis: 'none', columns: [[]] }, ...current.slice(insertAt)];
95
+ });
96
+ setSelectedSectionId(id);
97
+ setSelectedPartId(null);
98
+ setInspectorOpen(true);
99
+ }
100
+
101
+ function openToolbox(sectionId, columnIndex) {
102
+ setTarget({ sectionId, columnIndex });
103
+ setSelectedSectionId(sectionId);
104
+ setSelectedPartId(null);
105
+ setShowToolbox(true);
106
+ setInspectorOpen(false);
107
+ }
108
+
109
+ function addLibrary() {
110
+ const id = nextPartId.current++;
111
+ setSections((current) => current.map((section) => {
112
+ if (section.id !== target.sectionId) return section;
113
+ return { ...section, columns: section.columns.map((column, index) => index === target.columnIndex ? [...column, { id, type: 'document-library', title: 'Document library', view: 'details' }] : column) };
114
+ }));
115
+ setSelectedSectionId(target.sectionId);
116
+ setSelectedPartId(id);
117
+ setShowToolbox(false);
118
+ setInspectorOpen(true);
119
+ }
120
+
121
+ function addComponent() {
122
+ if (!PreviewComponent) return;
123
+ const id = nextPartId.current++;
124
+ setSections((current) => current.map((section) => section.id !== target.sectionId ? section : { ...section, columns: section.columns.map((column, index) => index === target.columnIndex ? [...column, { id, type: 'consumer-component', title: ComponentTitle }] : column) }));
125
+ setSelectedSectionId(target.sectionId);
126
+ setSelectedPartId(id);
127
+ setShowToolbox(false);
128
+ setInspectorOpen(true);
129
+ }
130
+
131
+ function removeSelectedPart() {
132
+ setSections((current) => current.map((section) => ({ ...section, columns: section.columns.map((column) => column.filter((part) => part.id !== selectedPartId)) })));
133
+ setSelectedPartId(null);
134
+ setInspectorOpen(false);
135
+ }
136
+
137
+ const rootStyle = { '--theme-primary': themeColors.primary, '--theme-dark': themeColors.dark, '--theme-light': themeColors.light };
138
+
139
+ return <div className="workbench" style={rootStyle}>
140
+ <header className="workbench-bar">
141
+ <div className="workbench-name"><span className="workbench-mark" aria-hidden="true">S</span><strong>SharePoint Workbench</strong></div>
142
+ <span className={`simulation-status${dataError ? ' is-error' : ''}`} role="status"><i aria-hidden="true"/>Local simulation · {PreviewComponent && !hasLibrary ? 'Fast Refresh ready' : dataSourceLabel(dataSource)}</span>
143
+ <label className="theme-picker"><span>Theme</span><select aria-label="Local site theme" value={theme} onChange={(event) => setTheme(event.target.value)}>{Object.entries(themes).map(([value, item]) => <option key={value} value={value}>{item.name}</option>)}</select></label>
144
+ </header>
145
+
146
+ <div className="workbench-layout">
147
+ {showToolbox && <aside className="side-pane toolbox" aria-label="Web part toolbox">
148
+ <div className="pane-title"><h2>Add a web part</h2><button className="pane-close" onClick={() => setShowToolbox(false)} aria-label="Close toolbox">×</button></div>
149
+ <p className="pane-description">Add the deterministic local document library or your component under development.</p>
150
+ <div className="webpart-catalog" aria-label="Available SharePoint web parts">
151
+ {visibleWebparts.map((entry) => {
152
+ const title = entry.name;
153
+ const inDevelopment = Boolean(PreviewComponent && title.toLowerCase() === ComponentTitle.toLowerCase());
154
+ return <button className={`webpart-choice${inDevelopment ? ' is-in-development' : ''}`} key={title} onClick={inDevelopment ? addComponent : addLibrary}>
155
+ <span className="webpart-icon" aria-hidden="true"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6"><rect x="4" y="3" width="16" height="18" rx="1"/><path d="M8 8h8M8 12h8M8 16h5"/></svg></span>
156
+ <span><strong>{title}</strong><small>{inDevelopment ? 'In development' : 'Deterministic local fixture'}</small></span>
157
+ {inDevelopment ? <span className="development-badge">In development</span> : <AddIcon/>}
158
+ </button>;
159
+ })}
160
+ {!visibleWebparts.length && <p className="pane-description">No matching web parts.</p>}
161
+ </div>
162
+ </aside>}
163
+
164
+ <main className="canvas-area">
165
+ <div className="canvas-toolbar">
166
+ <div><h1>Workbench page</h1><p>Arrange web parts in SharePoint page sections.</p></div>
167
+ <div className="page-actions"><button className="primary-action" onClick={() => openToolbox(selectedSection?.id ?? 0, 0)} disabled={!selectedSection}><AddIcon/>Add a web part</button></div>
168
+ </div>
169
+ <div className="page-canvas" aria-label="SharePoint page canvas">
170
+ {sections.length === 0 && <button className="canvas-add" onClick={() => addSection(null)}><AddIcon/><span>Add a section</span></button>}
171
+ {sections.map((section, sectionIndex) => <div className="section-group" key={section.id}><section className={`page-section section-width-${section.width} emphasis-${section.emphasis}${section.width === 'fullScreen' ? ' section-full-screen' : ''}${selectedSectionId === section.id ? ' is-selected' : ''}`} aria-label={`Section ${sectionIndex + 1}`}>
172
+ <div className="section-toolbar">
173
+ <button className="section-name" onClick={() => { setSelectedSectionId(section.id); setSelectedPartId(null); setInspectorOpen(true); }}>Section {sectionIndex + 1}</button>
174
+ <button className="section-edit" onClick={() => { setSelectedSectionId(section.id); setSelectedPartId(null); setInspectorOpen(true); }}>Edit section</button>
175
+ </div>
176
+ <div className={`section-columns layout-${section.layout}`}>
177
+ {section.columns.map((column, columnIndex) => <div className="section-column" key={`${section.id}-${columnIndex}`}>
178
+ {column.map((part) => part.type === 'consumer-component' ? <article className="simulated-webpart consumer-webpart" aria-label="Consumer component web part" key={part.id}>
179
+ <div className="webpart-heading"><div><h2>{part.title ?? ComponentTitle}</h2><p>Local simulator</p></div><button className="webpart-settings" onClick={() => { setSelectedSectionId(section.id); setSelectedPartId(part.id); setInspectorOpen(true); }}>Properties</button></div>
180
+ <div className="consumer-component-host"><PreviewComponent context={context}/></div>
181
+ <div className="webpart-caption"><i aria-hidden="true"/>Local consumer component · Fast Refresh</div>
182
+ </article> : <article className={`simulated-webpart view-${part.view}`} aria-label="Document library web part" key={part.id}>
183
+ <div className="webpart-heading"><div><h2>{part.properties?.title || 'Documents'}</h2><p>{visibleRows.length} items</p></div><button className="webpart-settings" onClick={() => { setSelectedSectionId(section.id); setSelectedPartId(part.id); setInspectorOpen(true); }}>Properties</button></div>
184
+ {dataError ? <div className="canvas-message" role="alert">The local fixture could not be loaded. Check the capture or committed fixture.</div>
185
+ : dataSource === 'loading' ? <div className="canvas-message" role="status">Loading deterministic fixture…</div>
186
+ : visibleRows.length === 0 ? <div className="canvas-message">No documents match “{query}”.</div>
187
+ : part.view === 'tiles' ? <div className="document-tiles">{visibleRows.map((row) => <div className="document-tile" key={row.id}><span className="tile-file" aria-hidden="true"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5"><path d="M5 3h9l5 5v13H5zM14 3v6h5M8 13h8M8 17h8"/></svg></span><strong>{row.title}</strong><small>{row.kind}</small></div>)}</div>
188
+ : <div className={`document-list${part.view === 'compact' ? ' is-compact' : ''}`}><div className="document-row document-header"><span>Name</span><span>Modified</span><span>Type</span></div>
189
+ {visibleRows.map((row) => <div className="document-row" key={row.id}><strong>{row.title}</strong><span>{row.modified}</span><span>{row.kind}</span></div>)}</div>}
190
+ <div className="webpart-caption"><i aria-hidden="true"/>Synthetic SharePoint data · {dataSourceLabel(dataSource)}</div>
191
+ </article>)}
192
+ <button className="column-add" onClick={() => openToolbox(section.id, columnIndex)}><AddIcon/>Add a web part</button>
193
+ </div>)}
194
+ </div>
195
+ </section><div className="section-insert-row"><button className="section-insert" aria-label={`Add section after section ${sectionIndex + 1}`} title="Add a new section" onClick={() => addSection(section.id)}><AddIcon/></button></div></div>)}
196
+ </div>
197
+ </main>
198
+
199
+ {(showToolbox || inspectorOpen) && <button className="pane-backdrop" aria-label="Close panel" onClick={() => { setShowToolbox(false); setInspectorOpen(false); }}/>}
200
+ {inspectorOpen && selectedSection && <aside className="side-pane inspector" aria-label="Properties">
201
+ <div className="pane-title"><h2>{selectedPart?.type === 'consumer-component' ? selectedPart.title ?? ComponentTitle : selectedPart ? 'Document library' : 'Section properties'}</h2><button className="pane-close" onClick={() => setInspectorOpen(false)} aria-label="Close properties">×</button></div>
202
+ {selectedPart ? <>
203
+ {selectedPart.type === 'consumer-component' ? <><p className="pane-description">Consumer component inside the local SharePoint page editor.</p><dl className="property-list"><div><dt>Refresh</dt><dd>React Fast Refresh</dd></div><div><dt>Context</dt><dd>Local simulator subset</dd></div></dl><p className="boundary-note">For tenant-backed debugging, use the consumer project’s Heft serve flow on a modern SharePoint page.</p><button className="remove-webpart" onClick={removeSelectedPart}>Remove web part</button></>
204
+ : <>
205
+ <p className="pane-description">Web part settings and simulator data</p>
206
+ <label className="setting-field">View<select value={selectedPart.view} onChange={(event) => updateSection(selectedSection.id, (section) => ({ columns: section.columns.map((column) => column.map((part) => part.id === selectedPart.id ? { ...part, view: event.target.value } : part)) }))}>{views.map(([value, label]) => <option key={value} value={value}>{label}</option>)}</select></label>
207
+ <label className="setting-field">Filter documents<input value={query} onChange={(event) => setQuery(event.target.value)} placeholder="Search titles and types"/></label>
208
+ <dl className="property-list"><div><dt>Data source</dt><dd>{dataSourceLabel(dataSource)}</dd></div><div><dt>Web title</dt><dd>{pageContext?.web?.title ?? 'Workbench Site'}</dd></div><div><dt>Context mode</dt><dd>Read-only simulator subset</dd></div></dl>
209
+ <h3>Mock API reads</h3><ul className="supported-reads"><li>List items</li><li>Web title</li><li>List metadata</li></ul>
210
+ <p className="boundary-note">Host context and tenant APIs are not active. Use Heft and a modern SharePoint page for live debugging.</p>
211
+ <button className="remove-webpart" onClick={removeSelectedPart}>Remove web part</button>
212
+ </>}
213
+ </> : <>
214
+ <p className="pane-description">Section {sections.findIndex((section) => section.id === selectedSection.id) + 1} · SharePoint layout grid</p>
215
+ <SectionOptions section={selectedSection} onWidth={(value) => updateSection(selectedSection.id, () => ({ width: value }))} onLayout={(value) => changeLayout(selectedSection, value)} onEmphasis={(value) => updateSection(selectedSection.id, () => ({ emphasis: value }))}/>
216
+ <p className="boundary-note">Ratio-based widths are local preview presets. A connected SharePoint page controls its own column grid, theme, and context.</p>
217
+ <button className="remove-webpart" onClick={() => { setSections((current) => current.filter((section) => section.id !== selectedSection.id)); setSelectedSectionId(sections.find((section) => section.id !== selectedSection.id)?.id ?? null); setInspectorOpen(false); }}>Remove section</button>
218
+ </>}
219
+ </aside>}
220
+ </div>
221
+ </div>;
222
+ }