@platejs/test 0.0.0-stage → 54.0.0-beta.2

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/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) Ziad Beyens, Dylan Schiemann, Joe Anderson, Felix Feng
4
+
5
+ Unless otherwise specified in a LICENSE file within an individual package directory,
6
+ this license applies to all files in this repository outside of those package directories.
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in
16
+ all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ THE SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,284 @@
1
- # Temporary Holding Version
1
+ # @platejs/test
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Plate test utilities for headless, React, DOM, Playwright, and proof work.
4
+
5
+ `@platejs/test` is Plate's test-only distribution. Its root is safe in plain Node. React, browser DOM, Playwright, and release-proof code live behind explicit subpaths so one test environment does not load another.
6
+
7
+ ## Install
8
+
9
+ ```text
10
+ npm install platejs
11
+ npm install -D @platejs/test
12
+ ```
13
+
14
+ Install the peers for the subpath you use:
15
+
16
+ ```text
17
+ npm install -D react react-dom @testing-library/react
18
+ npm install -D @playwright/test
19
+ ```
20
+
21
+ Use the matching command for pnpm, Yarn, or Bun when your project uses another package manager.
22
+
23
+ Import exactly the layer you need:
24
+
25
+ Runtime labels describe where the exported module executes. Node-hosted tools remain headless even when they drive a browser:
26
+
27
+ | Entrypoint | Runtime |
28
+ | -------------------------- | -------- |
29
+ | `@platejs/test` | headless |
30
+ | `@platejs/test/proof` | headless |
31
+ | `@platejs/test/playwright` | headless |
32
+ | `@platejs/test/react` | client |
33
+ | `@platejs/test/browser` | client |
34
+
35
+ ## Package Surface
36
+
37
+ - `@platejs/test`
38
+ - Plate JSX fixtures: `jsx`, `jsxt`, and `hjsx`
39
+ - fixture editor creation: `createEditorFromFixture`
40
+ - selection projection: `projectTestSelectionRange`
41
+ - minimal `DataTransfer` fixtures: `createDataTransfer`
42
+ - `@platejs/test/react`
43
+ - `EditorTest` for rendering an existing Plate editor
44
+ - `createTestEditor` for Testing Library interaction tests
45
+ - `@platejs/test/proof`
46
+ - pure selection helpers: `serializePoint`, `serializeRange`, `isCollapsed`
47
+ - IME and placeholder proof classifiers: `evaluateImeInput`, `evaluatePlaceholderInput`
48
+ - raw-mobile receipt validation: `assertRawMobileProof`, `validateRawMobileProof`, `RAW_MOBILE_SCENARIOS`
49
+ - first-party parity contracts: `assertBrowserFirstPartyParityContracts`
50
+ - feature proof contracts: `defineBrowserFeatureContract`, `createBrowserFeatureContractRegistry`
51
+ - debug snapshot parsers for agent-browser and Appium proof artifacts
52
+ - `@platejs/test/browser`
53
+ - DOM selection snapshots: `takeDOMSelectionSnapshot`, `takeEditorSelectionSnapshot`
54
+ - zero-width placeholder inspection: `inspectZeroWidthPlaceholder`
55
+ - `@platejs/test/playwright`
56
+ - start here for browser proof work
57
+ - `test` and `expect`: Playwright's, plus `editor-state.json` saved in a failed test's results folder
58
+ - editor-first Playwright harness
59
+ - Chromium CDP IME helpers
60
+ - real clipboard write + browser paste helpers
61
+ - real clipboard read helpers
62
+ - readiness contract for mounted examples
63
+ - getter namespace for text/html/selection state
64
+ - selected-text getter
65
+ - displayed-selection getter for native and projected selection proof
66
+ - screenshot attachment helper for visual proof artifacts
67
+ - file-backed JSON attachment helper for replayable proof artifacts
68
+ - native event trace helpers for `selectionchange`, `beforeinput`, `input`, composition, target ranges, DOM deltas, and anomaly labels
69
+ - trusted typing timing and long-task capture through `measureTrustedTyping(...)`
70
+ - block-text getter and assertion helpers
71
+ - snapshot helper for aggregated editor state
72
+ - selection namespace for semantic selection actions and setup
73
+ - DOM namespace for mounted text-path readiness and native caret setup
74
+ - tolerant selection assertions
75
+ - collapsed model/native DOM selection agreement assertions
76
+ - double-highlight selection assertion
77
+ - normalized html equality assertions
78
+ - iframe and scoped-surface support
79
+ - block/text locator helpers: `getBrowserEditable`, `locateBrowserBlock`, `locateBrowserText`
80
+ - replayable scenario steps, including direct DOM text mutation import for contenteditable repair proof
81
+ - replayable selection-contract assertions for model, native selected text, DOM endpoints, visible selection, and double-highlight proof
82
+ - helper types: `ReadyOptions`, `EditorSurfaceOptions`, selection and clipboard snapshot types, native event trace snapshot and anomaly types
83
+ - `withExclusiveClipboardAccess(...)`
84
+
85
+ ## Boundaries
86
+
87
+ - `@platejs/test` is public test infrastructure, not the editor runtime API.
88
+ - The root imports only `platejs` and `platejs/hyperscript`; it does not load React, browser globals, or Playwright.
89
+ - `@platejs/test/react` owns React and Testing Library helpers.
90
+ - `@platejs/test/playwright` owns browser tests. It may depend on Playwright types and test fixtures.
91
+ - `@platejs/test/proof` and `@platejs/test/browser` stay small enough for pure assertions, capability classifiers, and DOM snapshots.
92
+ - Raw-device identity belongs to the executable device runner. Automated device-browser input or IME proof closes only when that gate runs and records the resolved device, OS, and capability scope. Proxy browser evidence does not claim native mobile clipboard, human soft-keyboard, glide typing, or voice input proof.
93
+ - The public package validates raw receipt structure and exact build identity. Repository release profiles, aggregate lane policy, artifact acquisition, and filesystem digest readback stay in release tooling.
94
+
95
+ ## Raw Mobile Device Proof
96
+
97
+ Run the raw gate only in a direct-Appium lane connected to a real Android device running Chrome and a real iOS device running Safari:
98
+
99
+ ```bash
100
+ bun test:mobile-device-proof:raw
101
+ ```
102
+
103
+ The runner reads `test-results/release-proof/mobile-device-proof.json`. The schema requires one receipt for every scenario on both platforms: tap, double tap, long press, forward and backward selection handles, cross-inline and cross-block selection, selection auto-scroll, collapsed and expanded swipes, inline-void boundaries, Enter, Backspace, autocapitalization, composition/IME, and native clipboard.
104
+
105
+ Every receipt records real device, OS, browser, the exact expected source commit, replay steps, native and semantic selection, model and DOM text, semantic update count, event trace, screenshots, video, and SHA-256 digests. The command independently reads every artifact back and verifies its digest. An incomplete matrix, stale commit, viewport emulation, agent-browser proxy, or Appium descriptor without those artifacts fails closed and proves no raw-mobile claim.
106
+
107
+ ## First Playwright Test
108
+
109
+ ```ts
110
+ import { expect, openExample, test } from '@platejs/test/playwright';
111
+
112
+ test('types through the browser editor', async ({ page }) => {
113
+ const editor = await openExample(page, 'plaintext', {
114
+ ready: { editor: 'visible' },
115
+ });
116
+
117
+ await editor.focus();
118
+ await editor.type('Hello from @platejs/test');
119
+
120
+ await editor.assert.text('Hello from @platejs/test');
121
+ await editor.assert.noDoubleSelectionHighlight();
122
+ expect(await editor.get.selectedText()).toBe('');
123
+ });
124
+ ```
125
+
126
+ The page under test installs the browser handle once, at module scope in a test or development entry, before its first editor mounts. Production entries never call it. Without it, `ready: { editor: 'visible' }` fails with "browser handle not installed".
127
+
128
+ ```ts
129
+ import { installBrowserHandle } from 'platejs/react'; // or 'plitejs/react'
130
+
131
+ installBrowserHandle();
132
+ ```
133
+
134
+ Each Playwright project names how `editor.clipboard.pasteText` and `pasteHtml` deliver a paste:
135
+
136
+ ```ts
137
+ import type { BrowserTestOptions } from '@platejs/test/playwright';
138
+ import { defineConfig, devices } from '@playwright/test';
139
+
140
+ export default defineConfig<BrowserTestOptions>({
141
+ projects: [
142
+ {
143
+ name: 'chromium',
144
+ use: {
145
+ ...devices['Desktop Chrome'],
146
+ clipboardTransport: 'native',
147
+ permissions: ['clipboard-read', 'clipboard-write'],
148
+ },
149
+ },
150
+ {
151
+ name: 'webkit',
152
+ use: { ...devices['Desktop Safari'], clipboardTransport: 'event' },
153
+ },
154
+ ],
155
+ });
156
+ ```
157
+
158
+ `'native'` writes the clipboard and presses the paste shortcut. `'event'` dispatches `paste`, then `beforeinput` when nothing cancels it. `'handle'` calls the editor directly and is labeled a stand-in. A paste fails when its transport did not apply it or the page threw, and each test records its transport in a `clipboard-transport` annotation.
159
+
160
+ ## Proof Style
161
+
162
+ Use the `ready` contract for maintained callsites and examples. For editor surfaces, do not use Playwright `locator.fill()` as proof. The editor owns model input through `beforeinput`, selection import, and editor commands; `fill()` can bypass or mis-model that path, especially in Firefox. Use `editor.type(...)` or `page.keyboard.type(...)` when the claim is real keyboard behavior: typing, selected-text replacement, undoable key input, focus/caret routing, Enter follow-up text, or visual caret proof. Use `page.keyboard.insertText(...)` only when the row deliberately bypasses keydown: native `beforeinput` / `targetRange` traces, IME or CDP input, Unicode/layout insertion that Playwright cannot key-dispatch consistently, direct browser DOM mutation import, undo grouping as one text insertion, or model-latency probes. Then assert model text, native selection, and native event trace when the behavior depends on browser input. Use `measureTrustedTyping({ page, root, text })` after explicit editor readiness, selection, focus, and warmup when a route needs exact per-key DOM target/model readiness, a post-readiness paint boundary, trusted input, an unthrottled burst budget, and fail-closed long-task coverage. Pair it with an exact final model assertion for the whole measured text. Model-owned input binds to the runtime's recorded event selection; native input also requires its DOM target range to resolve to that same path and offset. Native event traces are browser contracts, not one-size-fits-all strings: Chromium/WebKit `insertText` may produce only `beforeinput`, while Firefox can report `insertCompositionText` and a trailing `input` event for the same Playwright call. Clipboard helpers prove delivery path and editor ownership, not feature semantics by themselves. `editor.clipboard.pasteHtml(...)` writes a rich clipboard payload and triggers the browser paste path; the route-specific test must still assert the expected parser behavior. Do not treat it as proof that a surface supports every rich HTML mark, element, sanitizer, or table policy. Use replayable scenario steps for generated stress. For direct browser DOM mutation/import proof, use `mutateTextDOM` so the artifact stays replayable; use `editor.scenario.runImperative(...)` for arbitrary browser work. Imperative scenario results are explicitly non-replayable, non-reducible, and ineligible for release proof. Generated stress artifacts carry reduction candidates. Replay the full artifact with `STRESS_REPLAY=<artifact> pnpm --filter plite test:plite-browser:project <project> tests/plite-browser/donor/stress/replay.test.ts`. Replay one candidate with `STRESS_REPLAY=<artifact> STRESS_REDUCTION=<label> pnpm --filter plite test:plite-browser:project <project> tests/plite-browser/donor/stress/replay.test.ts`. Reduced replays write a separate `.reduction-<label>.result.json` trace beside the full replay result. Decode imported JSON with `decodeScenarioReplay(...)`; never cast replay values into scenario steps. The decoder rejects unknown steps, stale metadata, non-JSON payloads, and assertion shapes that cannot prove anything.
163
+
164
+ Example:
165
+
166
+ ```ts
167
+ import {
168
+ attachBrowserJsonArtifact,
169
+ attachPageScreenshot,
170
+ openExample,
171
+ startBrowserNativeEventTrace,
172
+ stopBrowserNativeEventTrace,
173
+ takeBrowserNativeEventTrace,
174
+ } from '@platejs/test/playwright';
175
+
176
+ const editor = await openExample(page, 'placeholder', {
177
+ ready: {
178
+ editor: 'visible',
179
+ placeholder: 'visible',
180
+ },
181
+ });
182
+
183
+ await editor.focus();
184
+ await editor.type('Hello Editor Browser');
185
+ await editor.selection.select({
186
+ anchor: { path: [0, 0], offset: 0 },
187
+ focus: { path: [0, 0], offset: 5 },
188
+ });
189
+ await editor.dom.waitForTextPath([0, 0]);
190
+ await editor.dom.collapseAtTextPath({ path: [0, 0], offset: 5 });
191
+
192
+ await editor.assert.text('Hello Editor Browser');
193
+ await editor.assert.blockTexts(['Hello Editor Browser']);
194
+ expect(await editor.get.selectedText()).toBe('Hello');
195
+ expect((await editor.selection.displayed()).source).toBe('native');
196
+ await editor.assert.noDoubleSelectionHighlight();
197
+ await attachPageScreenshot(page, testInfo, 'selection-proof.png');
198
+
199
+ await startBrowserNativeEventTrace(editor.root);
200
+ await editor.type('!');
201
+ const nativeTrace = await takeBrowserNativeEventTrace(editor.root);
202
+ expect(nativeTrace.entries.some((entry) => entry.type === 'beforeinput')).toBe(
203
+ true
204
+ );
205
+ await stopBrowserNativeEventTrace(editor.root);
206
+
207
+ await editor.assert.htmlContains('data-editor-string="true"');
208
+ await editor.assert.selection({
209
+ anchor: { path: [0, 0], offset: [0, 1] },
210
+ focus: { path: [0, 0], offset: [4, 5] },
211
+ });
212
+ await editor.assert.collapsedModelDOMSelection({
213
+ offset: [4, 5],
214
+ path: [0, 0],
215
+ text: 'Hello Editor Browser',
216
+ });
217
+ await editor.assert.htmlEquals(
218
+ '<div data-editor-node="element"><span data-editor-node="text"><span data-editor-leaf="true"><span data-editor-string="true">Hello Editor Browser</span></span></span></div>',
219
+ { ignoreClasses: true, ignoreInlineStyles: true, ignoreDir: true }
220
+ );
221
+
222
+ const snapshot = await editor.snapshot();
223
+ expect(snapshot.selection).not.toBeNull();
224
+ await attachBrowserJsonArtifact(testInfo, 'editor-snapshot-proof', snapshot);
225
+
226
+ const secondBlock = editor.locator.block([1]);
227
+ await secondBlock.click({ clickCount: 3 });
228
+ await editor.selection.doubleClickDragTextRange({
229
+ doubleClickOffset: 'This is edit'.length,
230
+ endOffset: 'This is editable plain'.length,
231
+ text: 'This is editable plain text, just like a <textarea>!',
232
+ });
233
+ await editor.selection.dragTextRange({
234
+ endOffset: 5,
235
+ endText: ' text, ',
236
+ startOffset: 8,
237
+ text: 'This is editable ',
238
+ });
239
+ await editor.selection.dragTextRange({
240
+ direction: 'backward',
241
+ endOffset: 'hyperlink'.length,
242
+ startOffset: 0,
243
+ text: 'hyperlink',
244
+ });
245
+ await editor.scenario.run([
246
+ {
247
+ expectation: {
248
+ domSelection: {
249
+ anchorNodeText: 'This is editable ',
250
+ anchorOffset: 8,
251
+ focusNodeText: ' text, ',
252
+ focusOffset: 5,
253
+ },
254
+ noDoubleSelectionHighlight: true,
255
+ selectedText: 'editable rich text',
256
+ },
257
+ kind: 'assertSelectionContract',
258
+ },
259
+ ]);
260
+
261
+ await editor.clipboard.pasteText('more');
262
+ await editor.clipboard.copy();
263
+ expect(await editor.clipboard.readText()).toContain('more');
264
+ ```
265
+
266
+ For Tab-away or blur proof, use `editor.assert.noVisibleCaretInRoot()` after focus leaves the editor. It asserts the editor no longer owns a paintable focused caret even if the browser keeps a stale DOM range.
267
+
268
+ Package commands:
269
+
270
+ - `pnpm --filter @platejs/test build`
271
+ - `pnpm --filter @platejs/test test`
272
+ - `pnpm --filter @platejs/test test:node`
273
+ - `pnpm --filter @platejs/test test:react`
274
+ - `pnpm --filter @platejs/test test:proof`
275
+ - `pnpm --filter @platejs/test test:dom`
276
+ - `pnpm --filter @platejs/test test:selection`
277
+
278
+ The package-local `test` script covers:
279
+
280
+ - `test:node`
281
+ - `test:react`
282
+ - `test:dom`
283
+
284
+ Run `test:selection` for the focused browser-selection lane.
@@ -0,0 +1,25 @@
1
+ import { n as inspectZeroWidthPlaceholder, t as PlaceholderShape } from "../zero-width-BGyZc7Mb.js";
2
+ //#region src/browser/selection.d.ts
3
+ /** Editor model selection endpoint captured from the DOM. */
4
+ type EditorSelectionPoint = {
5
+ path: number[];
6
+ offset: number;
7
+ };
8
+ /** Editor model selection snapshot resolved from browser selection endpoints. */
9
+ type EditorSelectionSnapshot = {
10
+ anchor: EditorSelectionPoint;
11
+ focus: EditorSelectionPoint;
12
+ };
13
+ /** Browser-native selection endpoint snapshot for debug proof. */
14
+ type DOMSelectionSnapshot = {
15
+ anchorNodeText: string | null;
16
+ anchorOffset: number;
17
+ focusNodeText: string | null;
18
+ focusOffset: number;
19
+ };
20
+ /** Capture the browser-native selection endpoints for debugging. */
21
+ declare const takeDOMSelectionSnapshot: (selection: Selection | null) => DOMSelectionSnapshot | null;
22
+ /** Resolve browser selection endpoints back to editor text paths and offsets. */
23
+ declare const takeEditorSelectionSnapshot: (root: ParentNode, selection: Selection | null) => EditorSelectionSnapshot | null;
24
+ //#endregion
25
+ export { type DOMSelectionSnapshot, type EditorSelectionPoint, type EditorSelectionSnapshot, type PlaceholderShape, inspectZeroWidthPlaceholder, takeDOMSelectionSnapshot, takeEditorSelectionSnapshot };
@@ -0,0 +1,69 @@
1
+ //#region src/browser/selection.ts
2
+ const parseEditorPath = (value) => {
3
+ const path = value.split(",").map((part) => Number.parseInt(part, 10));
4
+ if (path.some((part) => !Number.isInteger(part))) throw new Error("Invalid editor DOM path");
5
+ return path;
6
+ };
7
+ const findZeroWidthMarker = (node) => {
8
+ return (node?.nodeType === 1 ? node : node?.parentElement)?.closest("[data-editor-zero-width]") ?? null;
9
+ };
10
+ const toEditorOffset = (node, offset) => findZeroWidthMarker(node) ? 0 : offset;
11
+ const findTextPath = (root, node) => {
12
+ const owner = node?.nodeType === 1 ? node.closest("[data-editor-node=\"text\"]") : node?.parentElement?.closest("[data-editor-node=\"text\"]");
13
+ if (!owner) throw new Error("Cannot resolve selection to a editor text node");
14
+ if (!root.contains(owner)) throw new Error("Selection text node is outside the editor root");
15
+ const pathAttribute = owner.getAttribute("data-editor-path");
16
+ if (pathAttribute) return parseEditorPath(pathAttribute);
17
+ throw new Error("Cannot resolve selection to a editor DOM path");
18
+ };
19
+ const findTextPathOrNull = (root, node) => {
20
+ try {
21
+ return findTextPath(root, node);
22
+ } catch {
23
+ return null;
24
+ }
25
+ };
26
+ /** Capture the browser-native selection endpoints for debugging. */
27
+ const takeDOMSelectionSnapshot = (selection) => {
28
+ if (!selection || selection.rangeCount === 0) return null;
29
+ return {
30
+ anchorNodeText: selection.anchorNode?.textContent ?? null,
31
+ anchorOffset: selection.anchorOffset,
32
+ focusNodeText: selection.focusNode?.textContent ?? null,
33
+ focusOffset: selection.focusOffset
34
+ };
35
+ };
36
+ /** Resolve browser selection endpoints back to editor text paths and offsets. */
37
+ const takeEditorSelectionSnapshot = (root, selection) => {
38
+ if (!selection || selection.rangeCount === 0) return null;
39
+ const anchorPath = findTextPathOrNull(root, selection.anchorNode);
40
+ const focusPath = findTextPathOrNull(root, selection.focusNode);
41
+ if (anchorPath === null || focusPath === null) return null;
42
+ return {
43
+ anchor: {
44
+ path: anchorPath,
45
+ offset: toEditorOffset(selection.anchorNode, selection.anchorOffset)
46
+ },
47
+ focus: {
48
+ path: focusPath,
49
+ offset: toEditorOffset(selection.focusNode, selection.focusOffset)
50
+ }
51
+ };
52
+ };
53
+ //#endregion
54
+ //#region src/browser/zero-width.ts
55
+ /** Inspect the rendered shape of a editor zero-width placeholder element. */
56
+ const inspectZeroWidthPlaceholder = (element) => {
57
+ if (!element) return {
58
+ hasBr: false,
59
+ hasFEFF: false,
60
+ kind: null
61
+ };
62
+ return {
63
+ hasBr: !!element.querySelector("br"),
64
+ hasFEFF: element.textContent?.includes("") ?? false,
65
+ kind: element.getAttribute("data-editor-zero-width")
66
+ };
67
+ };
68
+ //#endregion
69
+ export { inspectZeroWidthPlaceholder, takeDOMSelectionSnapshot, takeEditorSelectionSnapshot };
@@ -0,0 +1,32 @@
1
+ //#region src/proof/feature-contracts.ts
2
+ /** Preserve a feature contract definition with exact literal family names. */
3
+ const defineBrowserFeatureContract = (contract) => contract;
4
+ /** Build and validate a browser contract registry from feature definitions. */
5
+ const createBrowserFeatureContractRegistry = (definitions) => {
6
+ const rows = [];
7
+ const rowByFamily = /* @__PURE__ */ new Map();
8
+ for (const definition of definitions) {
9
+ if (!definition.feature) throw new Error("Feature browser contract is missing a feature name.");
10
+ if (definition.rows.length === 0) throw new Error(`Feature browser contract "${definition.feature}" has no rows.`);
11
+ for (const row of definition.rows) {
12
+ if (!row.family) throw new Error(`Feature browser contract "${definition.feature}" has a row without a family.`);
13
+ if (row.routes.length === 0) throw new Error(`Feature browser contract "${definition.feature}" row "${row.family}" has no routes.`);
14
+ if (row.assertions.length === 0) throw new Error(`Feature browser contract "${definition.feature}" row "${row.family}" has no assertions.`);
15
+ if (rowByFamily.has(row.family)) throw new Error(`Feature browser contract family "${row.family}" is registered more than once.`);
16
+ const registeredRow = Object.freeze({
17
+ ...row,
18
+ assertions: Object.freeze([...row.assertions]),
19
+ feature: definition.feature,
20
+ routes: Object.freeze([...row.routes])
21
+ });
22
+ rows.push(registeredRow);
23
+ rowByFamily.set(registeredRow.family, registeredRow);
24
+ }
25
+ }
26
+ return Object.freeze({
27
+ rowByFamily,
28
+ rows: Object.freeze(rows)
29
+ });
30
+ };
31
+ //#endregion
32
+ export { defineBrowserFeatureContract as n, createBrowserFeatureContractRegistry as t };
@@ -0,0 +1,24 @@
1
+ //#region src/proof/feature-contracts.d.ts
2
+ /** One browser behavior family owned by a feature area. */
3
+ type BrowserFeatureContractRow = {
4
+ assertions: readonly string[];
5
+ family: string;
6
+ feature: string;
7
+ routes: readonly string[];
8
+ };
9
+ /** Declarative browser contract bundle for one feature area. */
10
+ type BrowserFeatureContractDefinition = {
11
+ feature: string;
12
+ rows: ReadonlyArray<Omit<BrowserFeatureContractRow, 'feature'>>;
13
+ };
14
+ /** Indexed browser contract registry built from feature definitions. */
15
+ type BrowserFeatureContractRegistry = {
16
+ rowByFamily: ReadonlyMap<string, BrowserFeatureContractRow>;
17
+ rows: readonly BrowserFeatureContractRow[];
18
+ };
19
+ /** Preserve a feature contract definition with exact literal family names. */
20
+ declare const defineBrowserFeatureContract: <T extends BrowserFeatureContractDefinition>(contract: T) => T;
21
+ /** Build and validate a browser contract registry from feature definitions. */
22
+ declare const createBrowserFeatureContractRegistry: (definitions: readonly BrowserFeatureContractDefinition[]) => BrowserFeatureContractRegistry;
23
+ //#endregion
24
+ export { defineBrowserFeatureContract as a, createBrowserFeatureContractRegistry as i, BrowserFeatureContractRegistry as n, BrowserFeatureContractRow as r, BrowserFeatureContractDefinition as t };
@@ -0,0 +1,6 @@
1
+ import { Editor } from "platejs";
2
+ import { TestEditor, TestEditorFixture, TestEditorFixture as TestEditorFixture$1, createDataTransfer, createHyperscript, elements, hjsx, jsx, jsxt, projectTestSelectionRange, voidChildren } from "platejs/testing";
3
+ //#region src/index.d.ts
4
+ declare const createEditorFromFixture: (fixture: TestEditorFixture$1) => Editor;
5
+ //#endregion
6
+ export { type TestEditor, type TestEditorFixture, createDataTransfer, createEditorFromFixture, createHyperscript, elements, hjsx, jsx, jsxt, projectTestSelectionRange, voidChildren };
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ import { createEditor } from "platejs";
2
+ import { createDataTransfer, createHyperscript, elements, hjsx, jsx, jsxt, projectTestSelectionRange, voidChildren } from "platejs/testing";
3
+ //#region src/index.ts
4
+ const createEditorFromFixture = (fixture) => createEditor({
5
+ initialSelection: fixture.selection,
6
+ ...fixture.children.length > 0 ? { initialValue: fixture.children } : {}
7
+ });
8
+ //#endregion
9
+ export { createDataTransfer, createEditorFromFixture, createHyperscript, elements, hjsx, jsx, jsxt, projectTestSelectionRange, voidChildren };