foldkit-mixins-richtext 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.
- package/LICENSE +21 -0
- package/README.md +71 -0
- package/dist/index.d.mts +29 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +33 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Patrick Glenn
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# foldkit-mixins-richtext
|
|
2
|
+
|
|
3
|
+
The rich-text editor's chrome, drawn through [Mixins](../mixins) slots.
|
|
4
|
+
|
|
5
|
+
The editor is a Bundle that renders one host element and nothing else (§29 of the
|
|
6
|
+
Rich Text design): the toolbar beside it is the application's chrome. This package
|
|
7
|
+
draws that chrome as a `SlotView`, so every element it makes is a slot an
|
|
8
|
+
application styles or extends the way it does any other view.
|
|
9
|
+
|
|
10
|
+
It does not wrap `foldkit-richtext-dom/toolbar`'s `marksToolbar`, and cannot: a
|
|
11
|
+
slot's contributions resolve at the element the view creates, so a slot view owns
|
|
12
|
+
its elements. The two share `markActive`, the rule that decides whether a mark is
|
|
13
|
+
lit.
|
|
14
|
+
|
|
15
|
+
## Status
|
|
16
|
+
|
|
17
|
+
Early: the `foldkit-richtext` family is 0.x, and its API may change between minor
|
|
18
|
+
versions. The first slice is the mark toolbar; the rest of the design's editor chrome (floating toolbar,
|
|
19
|
+
link popover, block handle, placeholder, status) arrives when a view needs it.
|
|
20
|
+
|
|
21
|
+
## The mark toolbar
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { Style } from 'foldkit-mixins'
|
|
25
|
+
import { MarkToolbarSlots, markToolbar } from 'foldkit-mixins-richtext'
|
|
26
|
+
|
|
27
|
+
const Toolbar = markToolbar<Message>().pipe(
|
|
28
|
+
Style.attach(Style.forSlots(MarkToolbarSlots)({ button: Style.class('mark-button') })),
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
// In a view: `toggled` builds the caller's own Message from a mark.
|
|
32
|
+
Toolbar(
|
|
33
|
+
{
|
|
34
|
+
state: { document, selection, storedMarks },
|
|
35
|
+
toggled: mark => edited(Message.ToggledMark({ mark })),
|
|
36
|
+
},
|
|
37
|
+
h,
|
|
38
|
+
)
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`state` is what the editor projects (`document`, `selection`, `storedMarks`); `marks`
|
|
42
|
+
defaults to the three `foldkit-richtext` ships; `toggled` turns a mark into the
|
|
43
|
+
caller's Message, which is a function because a caller usually dispatches its own
|
|
44
|
+
wrapper. Each button renders with its mark as the slot item's `id`, so a Behavior
|
|
45
|
+
can single one out.
|
|
46
|
+
|
|
47
|
+
| Slot | Capability | Renders |
|
|
48
|
+
| --- | --- | --- |
|
|
49
|
+
| `root` | Container | the toolbar's wrapper |
|
|
50
|
+
| `toolbar` | Collection | the row of buttons |
|
|
51
|
+
| `button` | Interactive | one mark's button, per mark |
|
|
52
|
+
|
|
53
|
+
The view owns each button's click and its pressed state, so neither is in a slot's
|
|
54
|
+
contract: a mixin cannot take them over.
|
|
55
|
+
|
|
56
|
+
## Checks
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
pnpm --filter foldkit-mixins-richtext typecheck
|
|
60
|
+
pnpm vitest run packages/mixins-richtext/test
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
`smoke/` checks the *built* richtext packages the way a consumer meets them —
|
|
64
|
+
through each package's `exports` map, from `dist`. Everything inside this workspace
|
|
65
|
+
resolves them from source, so nothing else catches a wrong `exports` path, a
|
|
66
|
+
missing file, or a wrong `types` condition. Build first, then:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
pnpm build
|
|
70
|
+
pnpm --filter foldkit-mixins-richtext smoke
|
|
71
|
+
```
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Capability, Slot, SlotView, Slots } from "foldkit-mixins";
|
|
2
|
+
import { ToolbarState } from "foldkit-richtext-dom/toolbar";
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
/** The elements the toolbar publishes: its wrapper, its row, and one button per mark. */
|
|
5
|
+
export declare const MarkToolbarSlots: Slots.Contract<{
|
|
6
|
+
readonly root: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>;
|
|
7
|
+
readonly toolbar: Slot.UnnamedSlot<Capability.Capability<"Collection", readonly [Capability.Capability<"Base", readonly []>]>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>;
|
|
8
|
+
readonly button: Slot.UnnamedSlot<Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>;
|
|
9
|
+
}>;
|
|
10
|
+
export interface MarkToolbarInput<Message> {
|
|
11
|
+
/** What the editor projects: `document`, `selection`, and the caret's format. */
|
|
12
|
+
readonly state: ToolbarState;
|
|
13
|
+
/** The marks to offer, by name. Defaults to the three `foldkit-richtext` ships. */
|
|
14
|
+
readonly marks?: ReadonlyArray<string> | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* A mark to the Message that toggles it for this caller. The editor's
|
|
17
|
+
* `Message.ToggledMark` is data, but a caller usually dispatches its wrapper
|
|
18
|
+
* (`edited(...)`), which is a function — and a plain SlotView holds one.
|
|
19
|
+
*/
|
|
20
|
+
readonly toggled: (mark: string) => Message;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The mark toolbar as a slot view. A Style or Behavior attaches to
|
|
24
|
+
* `MarkToolbarSlots`; each button renders with its mark as the slot item's `id`, so
|
|
25
|
+
* a Behavior can single one out.
|
|
26
|
+
*/
|
|
27
|
+
export declare const markToolbar: <Message>() => SlotView.SlotView<typeof MarkToolbarSlots, MarkToolbarInput<Message>, Message>;
|
|
28
|
+
//#endregion
|
|
29
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;qBAgBa,kBAAgB,MAAA;;;;;iBAMZ,iBAAiB;;WAEvB,OAAO;;WAEP,QAAQ;;;;;;WAMR,UAAU,iBAAiB;;;;;;;qBAQzB,cAAe,cAAY,SAAS,gBACxC,kBACP,iBAAiB,UACjB"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Capability, Slot, SlotView, Slots } from "foldkit-mixins";
|
|
2
|
+
import * as RichText from "foldkit-richtext";
|
|
3
|
+
import { markActive } from "foldkit-richtext-dom/toolbar";
|
|
4
|
+
//#region src/index.ts
|
|
5
|
+
/** The elements the toolbar publishes: its wrapper, its row, and one button per mark. */
|
|
6
|
+
const MarkToolbarSlots = Slots.define({
|
|
7
|
+
root: Slot.make({ capability: Capability.Container }),
|
|
8
|
+
toolbar: Slot.make({ capability: Capability.Collection }),
|
|
9
|
+
button: Slot.make({ capability: Capability.Interactive })
|
|
10
|
+
});
|
|
11
|
+
/**
|
|
12
|
+
* The mark toolbar as a slot view. A Style or Behavior attaches to
|
|
13
|
+
* `MarkToolbarSlots`; each button renders with its mark as the slot item's `id`, so
|
|
14
|
+
* a Behavior can single one out.
|
|
15
|
+
*/
|
|
16
|
+
const markToolbar = () => SlotView.forMessages().define(MarkToolbarSlots, (input, slots, h) => {
|
|
17
|
+
const marks = input.marks ?? RichText.shippedMarks.map((definition) => definition.name);
|
|
18
|
+
return h.div(slots.root.attrs(), [h.div(slots.toolbar.attrs([h.Role("toolbar")]), marks.map((mark, index) => h.button(slots.button.attrs([
|
|
19
|
+
h.Type("button"),
|
|
20
|
+
h.DataAttribute("mark", mark),
|
|
21
|
+
h.AriaLabel(mark),
|
|
22
|
+
h.AriaPressed(markActive(input.state, mark) ? "true" : "false"),
|
|
23
|
+
h.OnClick(input.toggled(mark))
|
|
24
|
+
], {
|
|
25
|
+
index,
|
|
26
|
+
id: mark,
|
|
27
|
+
count: marks.length
|
|
28
|
+
}), [mark])))]);
|
|
29
|
+
});
|
|
30
|
+
//#endregion
|
|
31
|
+
export { MarkToolbarSlots, markToolbar };
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["/**\n * `foldkit-mixins-richtext` — the editor's chrome, drawn through slots (§35, §120).\n *\n * The editor's Bundle renders one host element and nothing else (§29); the marks\n * toolbar beside it is the application's chrome. This package draws that chrome as\n * a SlotView, so every element it makes is a slot an application styles or extends\n * the way it does any other view. It cannot wrap `marksToolbar`: a slot's\n * contributions resolve at the element the view creates (§120). The two share\n * `markActive` instead.\n */\nimport type { Html } from 'foldkit/html'\nimport { Capability, Slot, Slots, SlotView } from 'foldkit-mixins'\nimport * as RichText from 'foldkit-richtext'\nimport { markActive, type ToolbarState } from 'foldkit-richtext-dom/toolbar'\n\n/** The elements the toolbar publishes: its wrapper, its row, and one button per mark. */\nexport const MarkToolbarSlots = Slots.define({\n root: Slot.make({ capability: Capability.Container }),\n toolbar: Slot.make({ capability: Capability.Collection }),\n button: Slot.make({ capability: Capability.Interactive }),\n})\n\nexport interface MarkToolbarInput<Message> {\n /** What the editor projects: `document`, `selection`, and the caret's format. */\n readonly state: ToolbarState\n /** The marks to offer, by name. Defaults to the three `foldkit-richtext` ships. */\n readonly marks?: ReadonlyArray<string> | undefined\n /**\n * A mark to the Message that toggles it for this caller. The editor's\n * `Message.ToggledMark` is data, but a caller usually dispatches its wrapper\n * (`edited(...)`), which is a function — and a plain SlotView holds one.\n */\n readonly toggled: (mark: string) => Message\n}\n\n/**\n * The mark toolbar as a slot view. A Style or Behavior attaches to\n * `MarkToolbarSlots`; each button renders with its mark as the slot item's `id`, so\n * a Behavior can single one out.\n */\nexport const markToolbar = <Message>(): SlotView.SlotView<\n typeof MarkToolbarSlots,\n MarkToolbarInput<Message>,\n Message\n> =>\n SlotView.forMessages<Message>().define(MarkToolbarSlots, (input, slots, h) => {\n const marks = input.marks ?? RichText.shippedMarks.map(definition => definition.name)\n return h.div(slots.root.attrs(), [\n h.div(\n slots.toolbar.attrs([h.Role('toolbar')]),\n marks.map((mark, index) =>\n h.button(\n slots.button.attrs(\n [\n h.Type('button'),\n h.DataAttribute('mark', mark),\n h.AriaLabel(mark),\n h.AriaPressed(markActive(input.state, mark) ? 'true' : 'false'),\n h.OnClick(input.toggled(mark)),\n ],\n { index, id: mark, count: marks.length },\n ),\n [mark],\n ),\n ),\n ),\n ])\n })\n"],"mappings":";;;;;AAgBA,MAAa,mBAAmB,MAAM,OAAO;CAC3C,MAAM,KAAK,KAAK,EAAE,YAAY,WAAW,UAAU,CAAC;CACpD,SAAS,KAAK,KAAK,EAAE,YAAY,WAAW,WAAW,CAAC;CACxD,QAAQ,KAAK,KAAK,EAAE,YAAY,WAAW,YAAY,CAAC;AAC1D,CAAC;;;;;;AAoBD,MAAa,oBAKX,SAAS,YAAqB,CAAC,CAAC,OAAO,mBAAmB,OAAO,OAAO,MAAM;CAC5E,MAAM,QAAQ,MAAM,SAAS,SAAS,aAAa,KAAI,eAAc,WAAW,IAAI;CACpF,OAAO,EAAE,IAAI,MAAM,KAAK,MAAM,GAAG,CAC/B,EAAE,IACA,MAAM,QAAQ,MAAM,CAAC,EAAE,KAAK,SAAS,CAAC,CAAC,GACvC,MAAM,KAAK,MAAM,UACf,EAAE,OACA,MAAM,OAAO,MACX;EACE,EAAE,KAAK,QAAQ;EACf,EAAE,cAAc,QAAQ,IAAI;EAC5B,EAAE,UAAU,IAAI;EAChB,EAAE,YAAY,WAAW,MAAM,OAAO,IAAI,IAAI,SAAS,OAAO;EAC9D,EAAE,QAAQ,MAAM,QAAQ,IAAI,CAAC;CAC/B,GACA;EAAE;EAAO,IAAI;EAAM,OAAO,MAAM;CAAO,CACzC,GACA,CAAC,IAAI,CACP,CACF,CACF,CACF,CAAC;AACH,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "foldkit-mixins-richtext",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "The rich-text editor's chrome, drawn through Mixins slots.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"foldkit",
|
|
7
|
+
"rich-text",
|
|
8
|
+
"editor",
|
|
9
|
+
"toolbar",
|
|
10
|
+
"mixins",
|
|
11
|
+
"typescript"
|
|
12
|
+
],
|
|
13
|
+
"type": "module",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"author": "Patrick Glenn <doeixd@gmail.com>",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/doeixd/foldkit-plus.git",
|
|
22
|
+
"directory": "packages/mixins-richtext"
|
|
23
|
+
},
|
|
24
|
+
"homepage": "https://github.com/doeixd/foldkit-plus/tree/main/packages/mixins-richtext#readme",
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/doeixd/foldkit-plus/issues"
|
|
27
|
+
},
|
|
28
|
+
"sideEffects": false,
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./dist/index.d.mts",
|
|
32
|
+
"import": "./dist/index.mjs"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist",
|
|
37
|
+
"README.md",
|
|
38
|
+
"LICENSE"
|
|
39
|
+
],
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"foldkit-richtext": "0.1.0",
|
|
42
|
+
"foldkit-richtext-dom": "0.1.0",
|
|
43
|
+
"foldkit-mixins": "0.4.0"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"foldkit": "^0.163.0"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"effect": "4.0.0-rc.116",
|
|
50
|
+
"foldkit": "0.163.0",
|
|
51
|
+
"jsdom": "26.1.0",
|
|
52
|
+
"tsdown": "^0.23.0",
|
|
53
|
+
"typescript": "5.9.3"
|
|
54
|
+
},
|
|
55
|
+
"scripts": {
|
|
56
|
+
"build": "tsdown",
|
|
57
|
+
"typecheck": "tsc -b",
|
|
58
|
+
"smoke": "node smoke/build.mjs"
|
|
59
|
+
}
|
|
60
|
+
}
|