@ember-formwright/tiptap 1.3.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,39 @@
1
1
  # @ember-formwright/tiptap
2
2
 
3
+ ## 2.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - 199233b: Fields type their control against their path. `@control` must be a control that stores what the
8
+ path holds, and a field takes only its control's args, typed for that path. `ControlSignature`
9
+ is split into the wiring every control gets and its own args, and registered names are declared
10
+ in `FormwrightControls` (or `FormwrightChoiceControls<T>`, for controls whose value follows the
11
+ path). The add-ons declare their default names. See MIGRATION.md.
12
+
13
+ ### Minor Changes
14
+
15
+ - 332f045: Built-in strings are translatable. Register a translator as `translator:main` (an object with
16
+ `locale` and `t(message, values)`) and Submit, Reset, the ✔ and ✘ buttons' names, the file
17
+ upload's prompts, the rich-text toolbar and the date picker's trigger name all go through it;
18
+ without one they stay English. Each package exports its messages at `./messages`, with ids
19
+ `formwright.<component>.<name>`, and `@ember-formwright/ember` exports `translate`, `format` and
20
+ the `Message` and `Translator` types.
21
+
22
+ Strings that couldn't be changed before take arguments, which win over the translator:
23
+ `@applyLabel` and `@cancelLabel` on fields; `@dropLabel`, `@dropHint`, `@retryLabel`,
24
+ `@removeLabel`, `@uploadingLabel` and `@rejectedLabel` on the file upload control;
25
+ `@toolbarLabel` and `@toolLabels` on the rich-text control.
26
+
27
+ `@ember-formwright/test-support` adds `registerTranslator` and `pseudoTranslator`, to check in a
28
+ test that every string goes through the translator.
29
+
30
+ ### Patch Changes
31
+
32
+ - Updated dependencies [332f045]
33
+ - Updated dependencies [199233b]
34
+ - @ember-formwright/ember@2.0.0
35
+ - @ember-formwright/test-support@2.0.0
36
+
3
37
  ## 1.3.0
4
38
 
5
39
  ### Minor Changes
package/README.md CHANGED
@@ -15,6 +15,9 @@ import '@ember-formwright/tiptap/theme.css' // optional; after the Formwright th
15
15
  registerTiptapControl() // @control="rich-text"
16
16
  ```
17
17
 
18
+ The package types these names for Glint: which paths each fits, and which args it takes. If
19
+ you register under other names, [declare them](https://joegaudet.com/ember-formwright/guide/controls/custom-controls.md).
20
+
18
21
  ```gts
19
22
  <f.Field @for="body" @control="rich-text" @label="Body" @placeholder="Write something" />
20
23
 
@@ -30,7 +33,9 @@ registerTiptapControl() // @control="rich-text"
30
33
  The field stores HTML, or Tiptap's JSON document with `@output="json"`. An empty editor
31
34
  stores `''` (`null` for JSON), so required checks work. `field.Control` also takes `@toolbar`
32
35
  (the buttons to show, or `false`), `@extensions` (more Tiptap extensions) and `@starterKit`
33
- (StarterKit's options); the last two are read once, when the editor is created.
36
+ (StarterKit's options); the last two are read once, when the editor is created. Button names
37
+ go through the app's translator (`./messages` lists them), or take `@toolLabels`
38
+ (`{ bold: 'Strong' }`) and `@toolbarLabel`.
34
39
 
35
40
  Toolbar buttons: `bold`, `italic`, `strike`, `heading-2`, `heading-3`, `bullet-list`,
36
41
  `ordered-list`, `blockquote`, `undo`, `redo`. Each has an accessible name, and the toggles
@@ -2,14 +2,16 @@ import Component from '@glimmer/component';
2
2
  import type Owner from '@ember/owner';
3
3
  import { Editor, type Extensions, type JSONContent } from '@tiptap/core';
4
4
  import StarterKit from '@tiptap/starter-kit';
5
- import { type ControlSignature } from '@ember-formwright/ember';
5
+ import { type ControlSignature, type Message, type OwnArgs } from '@ember-formwright/ember';
6
6
  /** A toolbar button, by name. */
7
7
  export type RichTextTool = 'bold' | 'italic' | 'strike' | 'heading-2' | 'heading-3' | 'bullet-list' | 'ordered-list' | 'blockquote' | 'undo' | 'redo';
8
8
  /** What the control stores: HTML (a string), or Tiptap's JSON document. */
9
9
  export type RichTextValue = string | JSONContent | null;
10
10
  interface Tool {
11
11
  name: RichTextTool;
12
- label: string;
12
+ /** Its accessible name, translated when shown so a locale change re-renders it. */
13
+ label: Message;
14
+ labelValues?: Record<string, unknown>;
13
15
  /** Toggles a mark or node, so it has a pressed state. */
14
16
  toggle: boolean;
15
17
  run: (editor: Editor) => void;
@@ -30,6 +32,10 @@ export interface RichTextControlSignature {
30
32
  extensions?: Extensions;
31
33
  /** StarterKit's options, e.g. `{ heading: { levels: [2, 3] } }`. Read once. */
32
34
  starterKit?: Parameters<typeof StarterKit.configure>[0];
35
+ /** The toolbar's accessible name. Default "Formatting". */
36
+ toolbarLabel?: string;
37
+ /** Button names (their title and accessible name), by tool: `{ bold: 'Strong' }`. */
38
+ toolLabels?: Partial<Record<RichTextTool, string>>;
33
39
  };
34
40
  }
35
41
  /**
@@ -58,6 +64,8 @@ export declare class RichTextControl extends Component<RichTextControlSignature>
58
64
  isPressed: (tool: Tool, _revision: number) => boolean;
59
65
  isDisabled: (tool: Tool, _revision: number) => boolean;
60
66
  run: (tool: Tool) => void;
67
+ get toolbarLabel(): string;
68
+ labelFor: (tool: Tool) => string;
61
69
  /** Keeps the editor's selection when a toolbar button is clicked. */
62
70
  keepFocus: (event: MouseEvent) => void;
63
71
  /** Mounts the editor on this element; a click on the field's label focuses it. */
@@ -93,5 +101,16 @@ export declare class RichTextControl extends Component<RichTextControlSignature>
93
101
  export declare function toPlainText(value: RichTextValue | undefined): string;
94
102
  /** Makes `@control="rich-text"` available to every form. Call once, e.g. in app.ts. */
95
103
  export declare function registerTiptapControl(name?: string): void;
104
+ /** An empty document stores `''` in HTML, and `null` as JSON. */
105
+ type RichTextStored<T> = Extract<NonNullable<T>, string> | ([Extract<NonNullable<T>, JSONContent>] extends [never] ? never : Extract<NonNullable<T>, JSONContent> | null);
106
+ declare module '@ember-formwright/ember' {
107
+ interface FormwrightChoiceControls<T> {
108
+ /**
109
+ * `registerTiptapControl()`'s default name; declare yours if you pass another. It stores
110
+ * an HTML string, or Tiptap's JSON with `@output="json"`.
111
+ */
112
+ 'rich-text': ControlSignature<RichTextStored<T>, OwnArgs<RichTextControlSignature>, HTMLDivElement>;
113
+ }
114
+ }
96
115
  export {};
97
116
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
-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,KAAG,MAAM,CACqD;IAEpF,qEAAqE;IACrE,SAAS,GAAI,OAAO,UAAU,KAAG,IAAI,CAA0B;IAE/D,kFAAkF;IAClF,KAAK;;;;;;OAWH;IAEF,8FAA8F;IAC9F,IAAI;;;;;;OAQF;IAEF,WAAW;;;;;;OAET;IAEF,4FAA4F;IAC5F,SAAS,GAAI,OAAO,aAAa,KAAG,IAAI,CAEvC;CAoIF;AA4ND;;;GAGG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,aAAa,GAAG,SAAS,GAAG,MAAM,CAgBpE;AAED,uFAAuF;AACvF,wBAAgB,qBAAqB,CAAC,IAAI,SAAc,GAAG,IAAI,CAE9D;AAED,iEAAiE;AAGjE,KAAK,cAAc,CAAC,CAAC,IACjB,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,GAC/B,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GACnD,KAAK,GACL,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,GAAG,IAAI,CAAC,CAAA;AAEpD,OAAO,QAAQ,yBAAyB,CAAC;IACvC,UAAU,wBAAwB,CAAC,CAAC;QAClC;;;WAGG;QACH,WAAW,EAAE,gBAAgB,CAC3B,cAAc,CAAC,CAAC,CAAC,EACjB,OAAO,CAAC,wBAAwB,CAAC,EACjC,cAAc,CACf,CAAA;KACF;CACF"}
@@ -0,0 +1,54 @@
1
+ /** Every built-in string of @ember-formwright/tiptap, for translation catalogs. */
2
+ export declare const messages: {
3
+ toolbar: {
4
+ id: string;
5
+ message: string;
6
+ description: string;
7
+ };
8
+ bold: {
9
+ id: string;
10
+ message: string;
11
+ description: string;
12
+ };
13
+ italic: {
14
+ id: string;
15
+ message: string;
16
+ description: string;
17
+ };
18
+ strike: {
19
+ id: string;
20
+ message: string;
21
+ description: string;
22
+ };
23
+ heading: {
24
+ id: string;
25
+ message: string;
26
+ description: string;
27
+ };
28
+ bulletList: {
29
+ id: string;
30
+ message: string;
31
+ description: string;
32
+ };
33
+ orderedList: {
34
+ id: string;
35
+ message: string;
36
+ description: string;
37
+ };
38
+ blockquote: {
39
+ id: string;
40
+ message: string;
41
+ description: string;
42
+ };
43
+ undo: {
44
+ id: string;
45
+ message: string;
46
+ description: string;
47
+ };
48
+ redo: {
49
+ id: string;
50
+ message: string;
51
+ description: string;
52
+ };
53
+ };
54
+ //# sourceMappingURL=messages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../src/messages.ts"],"names":[],"mappings":"AAEA,mFAAmF;AACnF,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmCc,CAAA"}
package/dist/index.js CHANGED
@@ -5,7 +5,8 @@ import { on } from '@ember/modifier';
5
5
  import { modifier } from 'ember-modifier';
6
6
  import { Editor } from '@tiptap/core';
7
7
  import StarterKit from '@tiptap/starter-kit';
8
- import { registerControl } from '@ember-formwright/ember';
8
+ import { translate, registerControl } from '@ember-formwright/ember';
9
+ import { messages } from './messages.js';
9
10
  import { precompileTemplate } from '@ember/template-compilation';
10
11
  import { setComponentTemplate } from '@ember/component';
11
12
  import templateOnly from '@ember/component/template-only';
@@ -21,7 +22,10 @@ const mark = (name, label, type, run) => ({
21
22
  });
22
23
  const heading = level => ({
23
24
  name: `heading-${level}`,
24
- label: `Heading ${level}`,
25
+ label: messages.heading,
26
+ labelValues: {
27
+ level
28
+ },
25
29
  toggle: true,
26
30
  run: editor => editor.chain().focus().toggleHeading({
27
31
  level
@@ -31,16 +35,16 @@ const heading = level => ({
31
35
  }),
32
36
  can: () => true
33
37
  });
34
- const TOOLS = [mark('bold', 'Bold', 'bold', e => e.chain().focus().toggleBold().run()), mark('italic', 'Italic', 'italic', e => e.chain().focus().toggleItalic().run()), mark('strike', 'Strikethrough', 'strike', e => e.chain().focus().toggleStrike().run()), heading(2), heading(3), mark('bullet-list', 'Bulleted list', 'bulletList', e => e.chain().focus().toggleBulletList().run()), mark('ordered-list', 'Numbered list', 'orderedList', e => e.chain().focus().toggleOrderedList().run()), mark('blockquote', 'Quote', 'blockquote', e => e.chain().focus().toggleBlockquote().run()), {
38
+ const TOOLS = [mark('bold', messages.bold, 'bold', e => e.chain().focus().toggleBold().run()), mark('italic', messages.italic, 'italic', e => e.chain().focus().toggleItalic().run()), mark('strike', messages.strike, 'strike', e => e.chain().focus().toggleStrike().run()), heading(2), heading(3), mark('bullet-list', messages.bulletList, 'bulletList', e => e.chain().focus().toggleBulletList().run()), mark('ordered-list', messages.orderedList, 'orderedList', e => e.chain().focus().toggleOrderedList().run()), mark('blockquote', messages.blockquote, 'blockquote', e => e.chain().focus().toggleBlockquote().run()), {
35
39
  name: 'undo',
36
- label: 'Undo',
40
+ label: messages.undo,
37
41
  toggle: false,
38
42
  run: e => e.chain().focus().undo().run(),
39
43
  isActive: () => false,
40
44
  can: e => e.can().undo()
41
45
  }, {
42
46
  name: 'redo',
43
- label: 'Redo',
47
+ label: messages.redo,
44
48
  toggle: false,
45
49
  run: e => e.chain().focus().redo().run(),
46
50
  isActive: () => false,
@@ -134,6 +138,10 @@ class RichTextControl extends Component {
134
138
  isPressed = (tool, _revision) => tool.isActive(this.editor);
135
139
  isDisabled = (tool, _revision) => !this.editable || !tool.can(this.editor);
136
140
  run = tool => tool.run(this.editor);
141
+ get toolbarLabel() {
142
+ return this.args.toolbarLabel ?? translate(this, messages.toolbar);
143
+ }
144
+ labelFor = tool => this.args.toolLabels?.[tool.name] ?? translate(this, tool.label, tool.labelValues);
137
145
  /** Keeps the editor's selection when a toolbar button is clicked. */
138
146
  keepFocus = event => event.preventDefault();
139
147
  /** Mounts the editor on this element; a click on the field's label focuses it. */
@@ -167,7 +175,7 @@ class RichTextControl extends Component {
167
175
  if (event.key === 'Enter') event.stopPropagation();
168
176
  };
169
177
  static {
170
- setComponentTemplate(precompileTemplate("<div class=\"fw-rich-text{{if @disabled \" fw-rich-text--disabled\"}}\" data-test-fw-control={{@type}} data-fw-name={{@name}} ...attributes>\n {{#if this.groups.length}}\n <div class=\"fw-rich-text-toolbar\" role=\"toolbar\" aria-label=\"Formatting\" aria-controls={{@id}}>\n {{#each this.groups as |group|}}\n <span class=\"fw-rich-text-group\">\n {{#each group as |tool|}}\n <button type=\"button\" class=\"fw-rich-text-tool fw-rich-text-tool--{{tool.name}}\" title={{tool.label}} aria-label={{tool.label}} aria-pressed={{if tool.toggle (if (this.isPressed tool this.revision) \"true\" \"false\")}} disabled={{this.isDisabled tool this.revision}} data-test-fw-tool={{tool.name}} {{on \"mousedown\" this.keepFocus}} {{on \"click\" (fn this.run tool)}}>\n <ToolIcon @name={{tool.name}} />\n </button>\n {{/each}}\n </span>\n {{/each}}\n </div>\n {{/if}}\n <div id={{@id}} aria-multiline=\"true\" aria-label={{@label}} aria-describedby={{@describedBy}} aria-invalid={{if @invalid \"true\"}} aria-required={{if @required \"true\"}} aria-readonly={{if @readonly \"true\"}} aria-disabled={{if @disabled \"true\"}} aria-placeholder={{@placeholder}} data-placeholder={{@placeholder}} {{this.mount}} {{this.sync @value}} {{this.setEditable this.editable}} {{on \"keydown\" this.onKeydown}}></div>\n</div>", {
178
+ setComponentTemplate(precompileTemplate("<div class=\"fw-rich-text{{if @disabled \" fw-rich-text--disabled\"}}\" data-test-fw-control={{@type}} data-fw-name={{@name}} ...attributes>\n {{#if this.groups.length}}\n <div class=\"fw-rich-text-toolbar\" role=\"toolbar\" aria-label={{this.toolbarLabel}} aria-controls={{@id}}>\n {{#each this.groups as |group|}}\n <span class=\"fw-rich-text-group\">\n {{#each group as |tool|}}\n <button type=\"button\" class=\"fw-rich-text-tool fw-rich-text-tool--{{tool.name}}\" title={{this.labelFor tool}} aria-label={{this.labelFor tool}} aria-pressed={{if tool.toggle (if (this.isPressed tool this.revision) \"true\" \"false\")}} disabled={{this.isDisabled tool this.revision}} data-test-fw-tool={{tool.name}} {{on \"mousedown\" this.keepFocus}} {{on \"click\" (fn this.run tool)}}>\n <ToolIcon @name={{tool.name}} />\n </button>\n {{/each}}\n </span>\n {{/each}}\n </div>\n {{/if}}\n <div id={{@id}} aria-multiline=\"true\" aria-label={{@label}} aria-describedby={{@describedBy}} aria-invalid={{if @invalid \"true\"}} aria-required={{if @required \"true\"}} aria-readonly={{if @readonly \"true\"}} aria-disabled={{if @disabled \"true\"}} aria-placeholder={{@placeholder}} data-placeholder={{@placeholder}} {{this.mount}} {{this.sync @value}} {{this.setEditable this.editable}} {{on \"keydown\" this.onKeydown}}></div>\n</div>", {
171
179
  strictMode: true,
172
180
  scope: () => ({
173
181
  on,
@@ -212,6 +220,8 @@ function toPlainText(value) {
212
220
  function registerTiptapControl(name = 'rich-text') {
213
221
  registerControl(name, RichTextControl);
214
222
  }
223
+ /** An empty document stores `''` in HTML, and `null` as JSON. */ // shortcut: typed by the path, not by `@output` (which the field doesn't pass on), so a JSON path
224
+ // without `@output="json"` type-checks; type it from the arg if the field ever forwards it.
215
225
 
216
226
  export { DEFAULT_TOOLBAR, RichTextControl, registerTiptapControl, toPlainText };
217
227
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/index.gts"],"sourcesContent":["import Component from '@glimmer/component'\nimport type { TOC } from '@ember/component/template-only'\nimport type Owner from '@ember/owner'\nimport { tracked } from '@glimmer/tracking'\nimport { fn } from '@ember/helper'\nimport { on } from '@ember/modifier'\nimport { modifier } from 'ember-modifier'\nimport { Editor, type Content, type Extensions, type JSONContent } from '@tiptap/core'\nimport type { EditorState } from '@tiptap/pm/state'\nimport StarterKit from '@tiptap/starter-kit'\nimport { registerControl, type ControlSignature } from '@ember-formwright/ember'\n\n/** A toolbar button, by name. */\nexport type RichTextTool =\n | 'bold'\n | 'italic'\n | 'strike'\n | 'heading-2'\n | 'heading-3'\n | 'bullet-list'\n | 'ordered-list'\n | 'blockquote'\n | 'undo'\n | 'redo'\n\n/** What the control stores: HTML (a string), or Tiptap's JSON document. */\nexport type RichTextValue = string | JSONContent | null\n\ninterface Tool {\n name: RichTextTool\n label: string\n /** Toggles a mark or node, so it has a pressed state. */\n toggle: boolean\n run: (editor: Editor) => void\n isActive: (editor: Editor) => boolean\n can: (editor: Editor) => boolean\n}\n\nconst mark = (\n name: RichTextTool,\n label: string,\n type: string,\n run: (editor: Editor) => void,\n): Tool => ({\n name,\n label,\n toggle: true,\n run,\n isActive: editor => editor.isActive(type),\n can: () => true,\n})\n\nconst heading = (level: 2 | 3): Tool => ({\n name: `heading-${level}`,\n label: `Heading ${level}`,\n toggle: true,\n run: editor => editor.chain().focus().toggleHeading({ level }).run(),\n isActive: editor => editor.isActive('heading', { level }),\n can: () => true,\n})\n\nconst TOOLS: Tool[] = [\n mark('bold', 'Bold', 'bold', e => e.chain().focus().toggleBold().run()),\n mark('italic', 'Italic', 'italic', e => e.chain().focus().toggleItalic().run()),\n mark('strike', 'Strikethrough', 'strike', e => e.chain().focus().toggleStrike().run()),\n heading(2),\n heading(3),\n mark('bullet-list', 'Bulleted list', 'bulletList', e =>\n e.chain().focus().toggleBulletList().run(),\n ),\n mark('ordered-list', 'Numbered list', 'orderedList', e =>\n e.chain().focus().toggleOrderedList().run(),\n ),\n mark('blockquote', 'Quote', 'blockquote', e => e.chain().focus().toggleBlockquote().run()),\n {\n name: 'undo',\n label: 'Undo',\n toggle: false,\n run: e => e.chain().focus().undo().run(),\n isActive: () => false,\n can: e => e.can().undo(),\n },\n {\n name: 'redo',\n label: 'Redo',\n toggle: false,\n run: e => e.chain().focus().redo().run(),\n isActive: () => false,\n can: e => e.can().redo(),\n },\n]\n\n/** Buttons are drawn in groups, with a divider between them. */\nconst GROUPS: RichTextTool[][] = [\n ['bold', 'italic', 'strike'],\n ['heading-2', 'heading-3'],\n ['bullet-list', 'ordered-list', 'blockquote'],\n ['undo', 'redo'],\n]\n\n/** Every button, the default `@toolbar`. */\nexport const DEFAULT_TOOLBAR: readonly RichTextTool[] = GROUPS.flat()\n\nexport interface RichTextControlSignature {\n /** The wrapper around the toolbar and the editor. */\n Element: HTMLDivElement\n Args: ControlSignature<RichTextValue>['Args'] & {\n /** `html` (default) stores an HTML string; `json` stores Tiptap's JSON document. */\n output?: 'html' | 'json'\n /** The buttons to show, in groups as listed; `false` hides the toolbar. */\n toolbar?: readonly RichTextTool[] | false\n /** More Tiptap extensions, added after StarterKit. Read once, when the editor is created. */\n extensions?: Extensions\n /** StarterKit's options, e.g. `{ heading: { levels: [2, 3] } }`. Read once. */\n starterKit?: Parameters<typeof StarterKit.configure>[0]\n }\n}\n\n/** Whether a document is a single empty paragraph (or heading). */\nfunction isEmptyDoc(state: EditorState): boolean {\n const { doc } = state\n return doc.childCount === 1 && doc.firstChild!.isTextblock && doc.firstChild!.content.size === 0\n}\n\nconst isEmptyParagraph = (node: JSONContent) => node.type === 'paragraph' && !node.content?.length\n\nconst isBlank = (value: unknown) => value === null || value === undefined || value === ''\n\n/**\n * A rich-text editor built on Tiptap's StarterKit, with a toolbar. Stores HTML, or Tiptap JSON\n * with `@output=\"json\"`; an empty document stores `''` (`null` for JSON).\n */\nexport class RichTextControl extends Component<RichTextControlSignature> {\n readonly editor: Editor\n /** The value this control last sent or was given, so it isn't set back into the editor. */\n private current: unknown\n /** Bumped after each transaction, so the toolbar's pressed states re-render. */\n @tracked revision = 0\n\n constructor(owner: Owner, args: RichTextControlSignature['Args']) {\n super(owner, args)\n this.current = args.value\n this.editor = new Editor({\n element: null,\n content: (args.value ?? '') as Content,\n extensions: [StarterKit.configure(args.starterKit), ...(args.extensions ?? [])],\n editorProps: {\n attributes: (state: EditorState) => ({\n class: 'fw-rich-text-editor',\n ...(isEmptyDoc(state) ? { 'data-empty': '' } : {}),\n }),\n },\n onUpdate: () => this.onUpdate(),\n onTransaction: () => this.refresh(),\n })\n }\n\n get isJson(): boolean {\n return this.args.output === 'json'\n }\n\n get editable(): boolean {\n return !(this.args.disabled || this.args.readonly)\n }\n\n /** The toolbar's buttons, in groups; empty groups are left out. */\n get groups(): Tool[][] {\n const wanted = this.args.toolbar\n if (wanted === false) return []\n const names = new Set(wanted ?? DEFAULT_TOOLBAR)\n return GROUPS.map(group =>\n TOOLS.filter(tool => group.includes(tool.name) && names.has(tool.name)),\n ).filter(group => group.length)\n }\n\n /**\n * What the document stores as. StarterKit keeps an empty paragraph after a final list or\n * heading, so there is somewhere to type; it isn't content, so it isn't stored.\n */\n serialize(): RichTextValue {\n if (this.editor.isEmpty) return this.isJson ? null : ''\n if (!this.isJson) return this.editor.getHTML().replace(/(<p><\\/p>)+$/, '')\n const json = this.editor.getJSON()\n const content = [...(json.content ?? [])]\n while (content.length > 1 && isEmptyParagraph(content[content.length - 1]!)) content.pop()\n return { ...json, content }\n }\n\n onUpdate(): void {\n const value = this.serialize()\n this.current = value\n this.args.onChange(value)\n }\n\n /** Transactions also happen while rendering (setting content), so re-render after it. */\n refresh(): void {\n queueMicrotask(() => {\n if (!this.isDestroying) this.revision++\n })\n }\n\n isPressed = (tool: Tool, _revision: number): boolean => tool.isActive(this.editor)\n isDisabled = (tool: Tool, _revision: number): boolean => !this.editable || !tool.can(this.editor)\n\n run = (tool: Tool): void => tool.run(this.editor)\n\n /** Keeps the editor's selection when a toolbar button is clicked. */\n keepFocus = (event: MouseEvent): void => event.preventDefault()\n\n /** Mounts the editor on this element; a click on the field's label focuses it. */\n mount = modifier((element: HTMLElement) => {\n this.editor.mount({ mount: element })\n const label = element.id\n ? document.querySelector<HTMLLabelElement>(`label[for=\"${CSS.escape(element.id)}\"]`)\n : null\n const focus = () => element.focus()\n label?.addEventListener('click', focus)\n return () => {\n label?.removeEventListener('click', focus)\n this.editor.destroy()\n }\n })\n\n /** A new value from outside (a reset, a rollback) replaces the document, without a change. */\n sync = modifier((_element: HTMLElement, [value]: [unknown]) => {\n if (value === this.current) return\n this.current = value\n if (isBlank(value) && this.editor.isEmpty) return\n const same = this.isJson\n ? JSON.stringify(value) === JSON.stringify(this.serialize())\n : value === this.serialize()\n if (!same) this.editor.commands.setContent((value ?? '') as Content, { emitUpdate: false })\n })\n\n setEditable = modifier((_element: HTMLElement, [editable]: [boolean]) => {\n if (this.editor.isEditable !== editable) this.editor.setEditable(editable, false)\n })\n\n /** Enter makes a new paragraph; it doesn't reach the field, which would commit the edit. */\n onKeydown = (event: KeyboardEvent): void => {\n if (event.key === 'Enter') event.stopPropagation()\n }\n\n <template>\n <div\n class=\"fw-rich-text{{if @disabled ' fw-rich-text--disabled'}}\"\n data-test-fw-control={{@type}}\n data-fw-name={{@name}}\n ...attributes\n >\n {{#if this.groups.length}}\n <div\n class=\"fw-rich-text-toolbar\"\n role=\"toolbar\"\n aria-label=\"Formatting\"\n aria-controls={{@id}}\n >\n {{#each this.groups as |group|}}\n <span class=\"fw-rich-text-group\">\n {{#each group as |tool|}}\n <button\n type=\"button\"\n class=\"fw-rich-text-tool fw-rich-text-tool--{{tool.name}}\"\n title={{tool.label}}\n aria-label={{tool.label}}\n aria-pressed={{if\n tool.toggle\n (if (this.isPressed tool this.revision) \"true\" \"false\")\n }}\n disabled={{this.isDisabled tool this.revision}}\n data-test-fw-tool={{tool.name}}\n {{on \"mousedown\" this.keepFocus}}\n {{on \"click\" (fn this.run tool)}}\n >\n <ToolIcon @name={{tool.name}} />\n </button>\n {{/each}}\n </span>\n {{/each}}\n </div>\n {{/if}}\n <div\n id={{@id}}\n aria-multiline=\"true\"\n aria-label={{@label}}\n aria-describedby={{@describedBy}}\n aria-invalid={{if @invalid \"true\"}}\n aria-required={{if @required \"true\"}}\n aria-readonly={{if @readonly \"true\"}}\n aria-disabled={{if @disabled \"true\"}}\n aria-placeholder={{@placeholder}}\n data-placeholder={{@placeholder}}\n {{this.mount}}\n {{this.sync @value}}\n {{this.setEditable this.editable}}\n {{on \"keydown\" this.onKeydown}}\n ></div>\n </div>\n </template>\n}\n\n/** Each button's glyph: a letter for marks, a small SVG for the rest. Decorative. */\nconst ToolIcon: TOC<{ Args: { name: RichTextTool } }> = <template>\n {{#if (eq @name \"bold\")}}<b aria-hidden=\"true\">B</b>\n {{else if (eq @name \"italic\")}}<i aria-hidden=\"true\">I</i>\n {{else if (eq @name \"strike\")}}<s aria-hidden=\"true\">S</s>\n {{else}}\n <svg\n aria-hidden=\"true\"\n viewBox=\"0 0 16 16\"\n width=\"16\"\n height=\"16\"\n fill=\"none\"\n stroke=\"currentColor\"\n stroke-width=\"1.5\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n >\n {{#if (eq @name \"heading-2\")}}\n <path d=\"M2 3.5v9M8 3.5v9M2 8h6\" />\n <path d=\"M10.5 9.2c0-.7.6-1.2 1.3-1.2s1.3.5 1.3 1.2c0 1-2.6 1.8-2.6 3.3h2.8\" />\n {{else if (eq @name \"heading-3\")}}\n <path d=\"M2 3.5v9M8 3.5v9M2 8h6\" />\n <path d=\"M10.6 8h2.4l-1.4 1.6c.9 0 1.5.5 1.5 1.3s-.7 1.4-1.5 1.4c-.6 0-1.1-.3-1.3-.7\" />\n {{else if (eq @name \"bullet-list\")}}\n <circle cx=\"2.5\" cy=\"4\" r=\"1\" fill=\"currentColor\" stroke=\"none\" />\n <circle cx=\"2.5\" cy=\"8\" r=\"1\" fill=\"currentColor\" stroke=\"none\" />\n <circle cx=\"2.5\" cy=\"12\" r=\"1\" fill=\"currentColor\" stroke=\"none\" />\n <path d=\"M6 4h8M6 8h8M6 12h8\" />\n {{else if (eq @name \"ordered-list\")}}\n <path d=\"M2 2.5h1v3M2 5.5h2M2 9.5c0-.6.5-1 1-1s1 .4 1 1c0 .8-2 1.5-2 2.5h2\" />\n <path d=\"M7 4h7M7 8h7M7 12h7\" />\n {{else if (eq @name \"blockquote\")}}\n <path d=\"M3 3v10M7 5h7M7 8h7M7 11h5\" />\n {{else if (eq @name \"undo\")}}\n <path d=\"M4 6h6.5a3 3 0 0 1 0 6H7\" /><path d=\"M6.5 3.5 4 6l2.5 2.5\" />\n {{else if (eq @name \"redo\")}}\n <path d=\"M12 6H5.5a3 3 0 0 0 0 6H9\" /><path d=\"M9.5 3.5 12 6l-2.5 2.5\" />\n {{/if}}\n </svg>\n {{/if}}\n</template>\n\nfunction eq(a: unknown, b: unknown): boolean {\n return a === b\n}\n\n/**\n * Plain text from a rich-text value (HTML or Tiptap JSON), for the field's `@format` in inline\n * forms: `<f.Field @control=\"rich-text\" @format={{toPlainText}} />`.\n */\nexport function toPlainText(value: RichTextValue | undefined): string {\n if (isBlank(value)) return ''\n if (typeof value === 'string') {\n // Blocks end in a space, so \"<p>a</p><p>b</p>\" reads \"a b\", not \"ab\".\n const spaced = value.replace(/<\\/(p|h[1-6]|li|blockquote|pre)>|<br\\s*\\/?>/gi, '$& ')\n const text = new DOMParser().parseFromString(spaced, 'text/html').body.textContent ?? ''\n return text.replace(/\\s+/g, ' ').trim()\n }\n const words: string[] = []\n const walk = (node: JSONContent) => {\n if (node.text) words.push(node.text)\n node.content?.forEach(walk)\n if (node.type !== 'text') words.push(' ')\n }\n walk(value as JSONContent)\n return words.join('').replace(/\\s+/g, ' ').trim()\n}\n\n/** Makes `@control=\"rich-text\"` available to every form. Call once, e.g. in app.ts. */\nexport function registerTiptapControl(name = 'rich-text'): void {\n registerControl(name, RichTextControl)\n}\n"],"names":["mark","name","label","type","run","toggle","isActive","editor","can","heading","level","chain","focus","toggleHeading","TOOLS","e","toggleBold","toggleItalic","toggleStrike","toggleBulletList","toggleOrderedList","toggleBlockquote","undo","redo","GROUPS","DEFAULT_TOOLBAR","flat","isEmptyDoc","state","doc","childCount","firstChild","isTextblock","content","size","isEmptyParagraph","node","length","isBlank","value","undefined","RichTextControl","Component","current","g","prototype","tracked","i","constructor","owner","args","Editor","element","extensions","StarterKit","configure","starterKit","editorProps","attributes","class","onUpdate","onTransaction","refresh","isJson","output","editable","disabled","readonly","groups","wanted","toolbar","names","Set","map","group","filter","tool","includes","has","serialize","isEmpty","getHTML","replace","json","getJSON","pop","onChange","queueMicrotask","isDestroying","revision","isPressed","_revision","isDisabled","keepFocus","event","preventDefault","mount","modifier","id","document","querySelector","CSS","escape","addEventListener","removeEventListener","destroy","sync","_element","same","JSON","stringify","commands","setContent","emitUpdate","setEditable","isEditable","onKeydown","key","stopPropagation","setComponentTemplate","precompileTemplate","strictMode","scope","on","fn","ToolIcon","eq","templateOnly","a","b","toPlainText","spaced","text","DOMParser","parseFromString","body","textContent","trim","words","walk","push","forEach","join","registerTiptapControl","registerControl"],"mappings":";;;;;;;;;;;;;AAsCA,MAAMA,OAAOA,CACXC,IAAM,EACNC,KAAa,EACbC,IAAY,EACZC,GAA6B,MACnB;EACVH,IAAA;EACAC,KAAA;AACAG,EAAAA,MAAA,EAAQ,IAAA;EACRD,GAAA;EACAE,QAAA,EAAUC,MAAA,IAAUA,MAAA,CAAOD,QAAQ,CAACH,IAAA,CAAA;EACpCK,GAAA,EAAKA,MAAM;AACb,CAAC,CAAA;AAED,MAAMC,UAAWC,KAAW,KAAa;EACvCT,IAAA,EAAM,CAAA,QAAA,EAAWS,KAAA,CAAA,CAAO;EACxBR,KAAA,EAAO,CAAA,QAAA,EAAWQ,KAAA,CAAA,CAAO;AACzBL,EAAAA,MAAA,EAAQ,IAAA;AACRD,EAAAA,GAAA,EAAKG,UAAUA,MAAA,CAAOI,KAAK,GAAGC,KAAK,EAAA,CAAGC,aAAa,CAAC;AAAEH,IAAAA;AAAM,GAAA,CAAA,CAAGN,GAAG,EAAA;EAClEE,QAAA,EAAUC,MAAA,IAAUA,MAAA,CAAOD,QAAQ,CAAC,SAAA,EAAW;AAAEI,IAAAA;AAAM,GAAA,CAAA;EACvDF,GAAA,EAAKA,MAAM;AACb,CAAC,CAAA;AAED,MAAMM,KAAO,GAAS,CACpBd,IAAA,CAAK,MAAA,EAAQ,MAAA,EAAQ,MAAA,EAAQe,CAAA,IAAKA,CAAA,CAAEJ,KAAK,EAAA,CAAGC,KAAK,EAAA,CAAGI,UAAU,EAAA,CAAGZ,GAAG,EAAA,CAAA,EACp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AO,WAAW,EAAO;AAC7D+I,EAAAA,eAAA,CAAgB/I,IAAA,EAAMwC,eAAA,CAAA;AACxB;;"}
1
+ {"version":3,"file":"index.js","sources":["../src/index.gts"],"sourcesContent":["import Component from '@glimmer/component'\nimport type { TOC } from '@ember/component/template-only'\nimport type Owner from '@ember/owner'\nimport { tracked } from '@glimmer/tracking'\nimport { fn } from '@ember/helper'\nimport { on } from '@ember/modifier'\nimport { modifier } from 'ember-modifier'\nimport { Editor, type Content, type Extensions, type JSONContent } from '@tiptap/core'\nimport type { EditorState } from '@tiptap/pm/state'\nimport StarterKit from '@tiptap/starter-kit'\nimport {\n registerControl,\n translate,\n type ControlSignature,\n type Message,\n type OwnArgs,\n} from '@ember-formwright/ember'\nimport { messages } from './messages.ts'\n\n/** A toolbar button, by name. */\nexport type RichTextTool =\n | 'bold'\n | 'italic'\n | 'strike'\n | 'heading-2'\n | 'heading-3'\n | 'bullet-list'\n | 'ordered-list'\n | 'blockquote'\n | 'undo'\n | 'redo'\n\n/** What the control stores: HTML (a string), or Tiptap's JSON document. */\nexport type RichTextValue = string | JSONContent | null\n\ninterface Tool {\n name: RichTextTool\n /** Its accessible name, translated when shown so a locale change re-renders it. */\n label: Message\n labelValues?: Record<string, unknown>\n /** Toggles a mark or node, so it has a pressed state. */\n toggle: boolean\n run: (editor: Editor) => void\n isActive: (editor: Editor) => boolean\n can: (editor: Editor) => boolean\n}\n\nconst mark = (\n name: RichTextTool,\n label: Message,\n type: string,\n run: (editor: Editor) => void,\n): Tool => ({\n name,\n label,\n toggle: true,\n run,\n isActive: editor => editor.isActive(type),\n can: () => true,\n})\n\nconst heading = (level: 2 | 3): Tool => ({\n name: `heading-${level}`,\n label: messages.heading,\n labelValues: { level },\n toggle: true,\n run: editor => editor.chain().focus().toggleHeading({ level }).run(),\n isActive: editor => editor.isActive('heading', { level }),\n can: () => true,\n})\n\nconst TOOLS: Tool[] = [\n mark('bold', messages.bold, 'bold', e => e.chain().focus().toggleBold().run()),\n mark('italic', messages.italic, 'italic', e => e.chain().focus().toggleItalic().run()),\n mark('strike', messages.strike, 'strike', e => e.chain().focus().toggleStrike().run()),\n heading(2),\n heading(3),\n mark('bullet-list', messages.bulletList, 'bulletList', e =>\n e.chain().focus().toggleBulletList().run(),\n ),\n mark('ordered-list', messages.orderedList, 'orderedList', e =>\n e.chain().focus().toggleOrderedList().run(),\n ),\n mark('blockquote', messages.blockquote, 'blockquote', e =>\n e.chain().focus().toggleBlockquote().run(),\n ),\n {\n name: 'undo',\n label: messages.undo,\n toggle: false,\n run: e => e.chain().focus().undo().run(),\n isActive: () => false,\n can: e => e.can().undo(),\n },\n {\n name: 'redo',\n label: messages.redo,\n toggle: false,\n run: e => e.chain().focus().redo().run(),\n isActive: () => false,\n can: e => e.can().redo(),\n },\n]\n\n/** Buttons are drawn in groups, with a divider between them. */\nconst GROUPS: RichTextTool[][] = [\n ['bold', 'italic', 'strike'],\n ['heading-2', 'heading-3'],\n ['bullet-list', 'ordered-list', 'blockquote'],\n ['undo', 'redo'],\n]\n\n/** Every button, the default `@toolbar`. */\nexport const DEFAULT_TOOLBAR: readonly RichTextTool[] = GROUPS.flat()\n\nexport interface RichTextControlSignature {\n /** The wrapper around the toolbar and the editor. */\n Element: HTMLDivElement\n Args: ControlSignature<RichTextValue>['Args'] & {\n /** `html` (default) stores an HTML string; `json` stores Tiptap's JSON document. */\n output?: 'html' | 'json'\n /** The buttons to show, in groups as listed; `false` hides the toolbar. */\n toolbar?: readonly RichTextTool[] | false\n /** More Tiptap extensions, added after StarterKit. Read once, when the editor is created. */\n extensions?: Extensions\n /** StarterKit's options, e.g. `{ heading: { levels: [2, 3] } }`. Read once. */\n starterKit?: Parameters<typeof StarterKit.configure>[0]\n /** The toolbar's accessible name. Default \"Formatting\". */\n toolbarLabel?: string\n /** Button names (their title and accessible name), by tool: `{ bold: 'Strong' }`. */\n toolLabels?: Partial<Record<RichTextTool, string>>\n }\n}\n\n/** Whether a document is a single empty paragraph (or heading). */\nfunction isEmptyDoc(state: EditorState): boolean {\n const { doc } = state\n return doc.childCount === 1 && doc.firstChild!.isTextblock && doc.firstChild!.content.size === 0\n}\n\nconst isEmptyParagraph = (node: JSONContent) => node.type === 'paragraph' && !node.content?.length\n\nconst isBlank = (value: unknown) => value === null || value === undefined || value === ''\n\n/**\n * A rich-text editor built on Tiptap's StarterKit, with a toolbar. Stores HTML, or Tiptap JSON\n * with `@output=\"json\"`; an empty document stores `''` (`null` for JSON).\n */\nexport class RichTextControl extends Component<RichTextControlSignature> {\n readonly editor: Editor\n /** The value this control last sent or was given, so it isn't set back into the editor. */\n private current: unknown\n /** Bumped after each transaction, so the toolbar's pressed states re-render. */\n @tracked revision = 0\n\n constructor(owner: Owner, args: RichTextControlSignature['Args']) {\n super(owner, args)\n this.current = args.value\n this.editor = new Editor({\n element: null,\n content: (args.value ?? '') as Content,\n extensions: [StarterKit.configure(args.starterKit), ...(args.extensions ?? [])],\n editorProps: {\n attributes: (state: EditorState) => ({\n class: 'fw-rich-text-editor',\n ...(isEmptyDoc(state) ? { 'data-empty': '' } : {}),\n }),\n },\n onUpdate: () => this.onUpdate(),\n onTransaction: () => this.refresh(),\n })\n }\n\n get isJson(): boolean {\n return this.args.output === 'json'\n }\n\n get editable(): boolean {\n return !(this.args.disabled || this.args.readonly)\n }\n\n /** The toolbar's buttons, in groups; empty groups are left out. */\n get groups(): Tool[][] {\n const wanted = this.args.toolbar\n if (wanted === false) return []\n const names = new Set(wanted ?? DEFAULT_TOOLBAR)\n return GROUPS.map(group =>\n TOOLS.filter(tool => group.includes(tool.name) && names.has(tool.name)),\n ).filter(group => group.length)\n }\n\n /**\n * What the document stores as. StarterKit keeps an empty paragraph after a final list or\n * heading, so there is somewhere to type; it isn't content, so it isn't stored.\n */\n serialize(): RichTextValue {\n if (this.editor.isEmpty) return this.isJson ? null : ''\n if (!this.isJson) return this.editor.getHTML().replace(/(<p><\\/p>)+$/, '')\n const json = this.editor.getJSON()\n const content = [...(json.content ?? [])]\n while (content.length > 1 && isEmptyParagraph(content[content.length - 1]!)) content.pop()\n return { ...json, content }\n }\n\n onUpdate(): void {\n const value = this.serialize()\n this.current = value\n this.args.onChange(value)\n }\n\n /** Transactions also happen while rendering (setting content), so re-render after it. */\n refresh(): void {\n queueMicrotask(() => {\n if (!this.isDestroying) this.revision++\n })\n }\n\n isPressed = (tool: Tool, _revision: number): boolean => tool.isActive(this.editor)\n isDisabled = (tool: Tool, _revision: number): boolean => !this.editable || !tool.can(this.editor)\n\n run = (tool: Tool): void => tool.run(this.editor)\n\n get toolbarLabel(): string {\n return this.args.toolbarLabel ?? translate(this, messages.toolbar)\n }\n\n labelFor = (tool: Tool): string =>\n this.args.toolLabels?.[tool.name] ?? translate(this, tool.label, tool.labelValues)\n\n /** Keeps the editor's selection when a toolbar button is clicked. */\n keepFocus = (event: MouseEvent): void => event.preventDefault()\n\n /** Mounts the editor on this element; a click on the field's label focuses it. */\n mount = modifier((element: HTMLElement) => {\n this.editor.mount({ mount: element })\n const label = element.id\n ? document.querySelector<HTMLLabelElement>(`label[for=\"${CSS.escape(element.id)}\"]`)\n : null\n const focus = () => element.focus()\n label?.addEventListener('click', focus)\n return () => {\n label?.removeEventListener('click', focus)\n this.editor.destroy()\n }\n })\n\n /** A new value from outside (a reset, a rollback) replaces the document, without a change. */\n sync = modifier((_element: HTMLElement, [value]: [unknown]) => {\n if (value === this.current) return\n this.current = value\n if (isBlank(value) && this.editor.isEmpty) return\n const same = this.isJson\n ? JSON.stringify(value) === JSON.stringify(this.serialize())\n : value === this.serialize()\n if (!same) this.editor.commands.setContent((value ?? '') as Content, { emitUpdate: false })\n })\n\n setEditable = modifier((_element: HTMLElement, [editable]: [boolean]) => {\n if (this.editor.isEditable !== editable) this.editor.setEditable(editable, false)\n })\n\n /** Enter makes a new paragraph; it doesn't reach the field, which would commit the edit. */\n onKeydown = (event: KeyboardEvent): void => {\n if (event.key === 'Enter') event.stopPropagation()\n }\n\n <template>\n <div\n class=\"fw-rich-text{{if @disabled ' fw-rich-text--disabled'}}\"\n data-test-fw-control={{@type}}\n data-fw-name={{@name}}\n ...attributes\n >\n {{#if this.groups.length}}\n <div\n class=\"fw-rich-text-toolbar\"\n role=\"toolbar\"\n aria-label={{this.toolbarLabel}}\n aria-controls={{@id}}\n >\n {{#each this.groups as |group|}}\n <span class=\"fw-rich-text-group\">\n {{#each group as |tool|}}\n <button\n type=\"button\"\n class=\"fw-rich-text-tool fw-rich-text-tool--{{tool.name}}\"\n title={{this.labelFor tool}}\n aria-label={{this.labelFor tool}}\n aria-pressed={{if\n tool.toggle\n (if (this.isPressed tool this.revision) \"true\" \"false\")\n }}\n disabled={{this.isDisabled tool this.revision}}\n data-test-fw-tool={{tool.name}}\n {{on \"mousedown\" this.keepFocus}}\n {{on \"click\" (fn this.run tool)}}\n >\n <ToolIcon @name={{tool.name}} />\n </button>\n {{/each}}\n </span>\n {{/each}}\n </div>\n {{/if}}\n <div\n id={{@id}}\n aria-multiline=\"true\"\n aria-label={{@label}}\n aria-describedby={{@describedBy}}\n aria-invalid={{if @invalid \"true\"}}\n aria-required={{if @required \"true\"}}\n aria-readonly={{if @readonly \"true\"}}\n aria-disabled={{if @disabled \"true\"}}\n aria-placeholder={{@placeholder}}\n data-placeholder={{@placeholder}}\n {{this.mount}}\n {{this.sync @value}}\n {{this.setEditable this.editable}}\n {{on \"keydown\" this.onKeydown}}\n ></div>\n </div>\n </template>\n}\n\n/** Each button's glyph: a letter for marks, a small SVG for the rest. Decorative. */\nconst ToolIcon: TOC<{ Args: { name: RichTextTool } }> = <template>\n {{#if (eq @name \"bold\")}}<b aria-hidden=\"true\">B</b>\n {{else if (eq @name \"italic\")}}<i aria-hidden=\"true\">I</i>\n {{else if (eq @name \"strike\")}}<s aria-hidden=\"true\">S</s>\n {{else}}\n <svg\n aria-hidden=\"true\"\n viewBox=\"0 0 16 16\"\n width=\"16\"\n height=\"16\"\n fill=\"none\"\n stroke=\"currentColor\"\n stroke-width=\"1.5\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n >\n {{#if (eq @name \"heading-2\")}}\n <path d=\"M2 3.5v9M8 3.5v9M2 8h6\" />\n <path d=\"M10.5 9.2c0-.7.6-1.2 1.3-1.2s1.3.5 1.3 1.2c0 1-2.6 1.8-2.6 3.3h2.8\" />\n {{else if (eq @name \"heading-3\")}}\n <path d=\"M2 3.5v9M8 3.5v9M2 8h6\" />\n <path d=\"M10.6 8h2.4l-1.4 1.6c.9 0 1.5.5 1.5 1.3s-.7 1.4-1.5 1.4c-.6 0-1.1-.3-1.3-.7\" />\n {{else if (eq @name \"bullet-list\")}}\n <circle cx=\"2.5\" cy=\"4\" r=\"1\" fill=\"currentColor\" stroke=\"none\" />\n <circle cx=\"2.5\" cy=\"8\" r=\"1\" fill=\"currentColor\" stroke=\"none\" />\n <circle cx=\"2.5\" cy=\"12\" r=\"1\" fill=\"currentColor\" stroke=\"none\" />\n <path d=\"M6 4h8M6 8h8M6 12h8\" />\n {{else if (eq @name \"ordered-list\")}}\n <path d=\"M2 2.5h1v3M2 5.5h2M2 9.5c0-.6.5-1 1-1s1 .4 1 1c0 .8-2 1.5-2 2.5h2\" />\n <path d=\"M7 4h7M7 8h7M7 12h7\" />\n {{else if (eq @name \"blockquote\")}}\n <path d=\"M3 3v10M7 5h7M7 8h7M7 11h5\" />\n {{else if (eq @name \"undo\")}}\n <path d=\"M4 6h6.5a3 3 0 0 1 0 6H7\" /><path d=\"M6.5 3.5 4 6l2.5 2.5\" />\n {{else if (eq @name \"redo\")}}\n <path d=\"M12 6H5.5a3 3 0 0 0 0 6H9\" /><path d=\"M9.5 3.5 12 6l-2.5 2.5\" />\n {{/if}}\n </svg>\n {{/if}}\n</template>\n\nfunction eq(a: unknown, b: unknown): boolean {\n return a === b\n}\n\n/**\n * Plain text from a rich-text value (HTML or Tiptap JSON), for the field's `@format` in inline\n * forms: `<f.Field @control=\"rich-text\" @format={{toPlainText}} />`.\n */\nexport function toPlainText(value: RichTextValue | undefined): string {\n if (isBlank(value)) return ''\n if (typeof value === 'string') {\n // Blocks end in a space, so \"<p>a</p><p>b</p>\" reads \"a b\", not \"ab\".\n const spaced = value.replace(/<\\/(p|h[1-6]|li|blockquote|pre)>|<br\\s*\\/?>/gi, '$& ')\n const text = new DOMParser().parseFromString(spaced, 'text/html').body.textContent ?? ''\n return text.replace(/\\s+/g, ' ').trim()\n }\n const words: string[] = []\n const walk = (node: JSONContent) => {\n if (node.text) words.push(node.text)\n node.content?.forEach(walk)\n if (node.type !== 'text') words.push(' ')\n }\n walk(value as JSONContent)\n return words.join('').replace(/\\s+/g, ' ').trim()\n}\n\n/** Makes `@control=\"rich-text\"` available to every form. Call once, e.g. in app.ts. */\nexport function registerTiptapControl(name = 'rich-text'): void {\n registerControl(name, RichTextControl)\n}\n\n/** An empty document stores `''` in HTML, and `null` as JSON. */\n// shortcut: typed by the path, not by `@output` (which the field doesn't pass on), so a JSON path\n// without `@output=\"json\"` type-checks; type it from the arg if the field ever forwards it.\ntype RichTextStored<T> =\n | Extract<NonNullable<T>, string>\n | ([Extract<NonNullable<T>, JSONContent>] extends [never]\n ? never\n : Extract<NonNullable<T>, JSONContent> | null)\n\ndeclare module '@ember-formwright/ember' {\n interface FormwrightChoiceControls<T> {\n /**\n * `registerTiptapControl()`'s default name; declare yours if you pass another. It stores\n * an HTML string, or Tiptap's JSON with `@output=\"json\"`.\n */\n 'rich-text': ControlSignature<\n RichTextStored<T>,\n OwnArgs<RichTextControlSignature>,\n HTMLDivElement\n >\n }\n}\n"],"names":["mark","name","label","type","run","toggle","isActive","editor","can","heading","level","messages","labelValues","chain","focus","toggleHeading","TOOLS","bold","e","toggleBold","italic","toggleItalic","strike","toggleStrike","bulletList","toggleBulletList","orderedList","toggleOrderedList","blockquote","toggleBlockquote","undo","redo","GROUPS","DEFAULT_TOOLBAR","flat","isEmptyDoc","state","doc","childCount","firstChild","isTextblock","content","size","isEmptyParagraph","node","length","isBlank","value","undefined","RichTextControl","Component","current","g","prototype","tracked","i","constructor","owner","args","Editor","element","extensions","StarterKit","configure","starterKit","editorProps","attributes","class","onUpdate","onTransaction","refresh","isJson","output","editable","disabled","readonly","groups","wanted","toolbar","names","Set","map","group","filter","tool","includes","has","serialize","isEmpty","getHTML","replace","json","getJSON","pop","onChange","queueMicrotask","isDestroying","revision","isPressed","_revision","isDisabled","toolbarLabel","translate","labelFor","toolLabels","keepFocus","event","preventDefault","mount","modifier","id","document","querySelector","CSS","escape","addEventListener","removeEventListener","destroy","sync","_element","same","JSON","stringify","commands","setContent","emitUpdate","setEditable","isEditable","onKeydown","key","stopPropagation","setComponentTemplate","precompileTemplate","strictMode","scope","on","fn","ToolIcon","eq","templateOnly","a","b","toPlainText","spaced","text","DOMParser","parseFromString","body","textContent","trim","words","walk","push","forEach","join","registerTiptapControl","registerControl"],"mappings":";;;;;;;;;;;;;;AA+CA,MAAMA,IAAA,GAAOA,CACXC,IAAM,EACNC,KAAO,EACPC,IAAY,EACZC,GAA6B,MACnB;EACVH,IAAA;EACAC,KAAA;AACAG,EAAAA,MAAA,EAAQ,IAAA;EACRD,GAAA;EACAE,QAAA,EAAUC,MAAA,IAAUA,MAAA,CAAOD,QAAQ,CAACH,IAAA,CAAA;EACpCK,GAAA,EAAKA,MAAM;AACb,CAAC,CAAA;AAED,MAAMC,UAAWC,KAAW,KAAa;EACvCT,IAAA,EAAM,CAAA,QAAA,EAAWS,KAAA,CAAA,CAAO;EACxBR,KAAA,EAAOS,SAASF,OAAO;AACvBG,EAAAA,WAAA,EAAa;AAAEF,IAAAA;GAAM;AACrBL,EAAAA,MAAA,EAAQ,IAAA;AACRD,EAAAA,GAAA,EAAKG,UAAUA,MAAA,CAAOM,KAAK,GAAGC,KAAK,EAAA,CAAGC,aAAa,CAAC;AAAEL,IAAAA;AAAM,GAAA,CAAA,CAAGN,GAAG,EAAA;EAClEE,QAAA,EAAUC,MAAA,IAAUA,MAAA,CAAOD,QAAQ,CAAC,SAAA,EAAW;AAAEI,IAAAA;AAAM,GAAA,CAAA;EAC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OJ,IAAA,CAAKtD,OAAO,CAAC,MAAA,EAAQ,KAAK2D,IAAI,EAAA;AACvC,EAAA;EACA,MAAMC,KAAa,GAAK,EAAE;EAC1B,MAAMC,IAAA,GAAQ3G,IAAM,IAAA;IAClB,IAAIA,KAAKoG,IAAI,EAAEM,MAAME,IAAI,CAAC5G,KAAKoG,IAAI,CAAA;AACnCpG,IAAAA,IAAA,CAAKH,OAAO,EAAEgH,OAAA,CAAQF,IAAA,CAAA;IACtB,IAAI3G,KAAKzC,IAAI,KAAK,MAAA,EAAQmJ,KAAA,CAAME,IAAI,CAAC,GAAA,CAAA;EACvC,CAAA;EACAD,IAAA,CAAKxG,KAAS,CAAA;AACd,EAAA,OAAOuG,KAAA,CAAMI,IAAI,CAAC,EAAA,CAAA,CAAIhE,OAAO,CAAC,MAAA,EAAQ,KAAK2D,IAAI,EAAA;AACjD;AAEA;AACO,SAASM,sBAAsB1J,IAAA,GAAO,WAAW,EAAO;AAC7D2J,EAAAA,eAAA,CAAgB3J,IAAA,EAAMgD,eAAA,CAAA;AACxB;AAEA;AAEA;;"}
@@ -0,0 +1,56 @@
1
+ /** Every built-in string of @ember-formwright/tiptap, for translation catalogs. */
2
+ const messages = {
3
+ toolbar: {
4
+ id: 'formwright.richText.toolbar',
5
+ message: 'Formatting',
6
+ description: "Accessible name of the rich-text editor's toolbar"
7
+ },
8
+ bold: {
9
+ id: 'formwright.richText.bold',
10
+ message: 'Bold',
11
+ description: 'Toolbar button'
12
+ },
13
+ italic: {
14
+ id: 'formwright.richText.italic',
15
+ message: 'Italic',
16
+ description: 'Toolbar button'
17
+ },
18
+ strike: {
19
+ id: 'formwright.richText.strike',
20
+ message: 'Strikethrough',
21
+ description: 'Toolbar button'
22
+ },
23
+ heading: {
24
+ id: 'formwright.richText.heading',
25
+ message: 'Heading {level}',
26
+ description: 'Toolbar button; {level} is 2 or 3'
27
+ },
28
+ bulletList: {
29
+ id: 'formwright.richText.bulletList',
30
+ message: 'Bulleted list',
31
+ description: 'Toolbar button'
32
+ },
33
+ orderedList: {
34
+ id: 'formwright.richText.orderedList',
35
+ message: 'Numbered list',
36
+ description: 'Toolbar button'
37
+ },
38
+ blockquote: {
39
+ id: 'formwright.richText.blockquote',
40
+ message: 'Quote',
41
+ description: 'Toolbar button'
42
+ },
43
+ undo: {
44
+ id: 'formwright.richText.undo',
45
+ message: 'Undo',
46
+ description: 'Toolbar button'
47
+ },
48
+ redo: {
49
+ id: 'formwright.richText.redo',
50
+ message: 'Redo',
51
+ description: 'Toolbar button'
52
+ }
53
+ };
54
+
55
+ export { messages };
56
+ //# sourceMappingURL=messages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.js","sources":["../src/messages.ts"],"sourcesContent":["import type { Message } from '@ember-formwright/ember'\n\n/** Every built-in string of @ember-formwright/tiptap, for translation catalogs. */\nexport const messages = {\n toolbar: {\n id: 'formwright.richText.toolbar',\n message: 'Formatting',\n description: \"Accessible name of the rich-text editor's toolbar\",\n },\n bold: { id: 'formwright.richText.bold', message: 'Bold', description: 'Toolbar button' },\n italic: { id: 'formwright.richText.italic', message: 'Italic', description: 'Toolbar button' },\n strike: {\n id: 'formwright.richText.strike',\n message: 'Strikethrough',\n description: 'Toolbar button',\n },\n heading: {\n id: 'formwright.richText.heading',\n message: 'Heading {level}',\n description: 'Toolbar button; {level} is 2 or 3',\n },\n bulletList: {\n id: 'formwright.richText.bulletList',\n message: 'Bulleted list',\n description: 'Toolbar button',\n },\n orderedList: {\n id: 'formwright.richText.orderedList',\n message: 'Numbered list',\n description: 'Toolbar button',\n },\n blockquote: {\n id: 'formwright.richText.blockquote',\n message: 'Quote',\n description: 'Toolbar button',\n },\n undo: { id: 'formwright.richText.undo', message: 'Undo', description: 'Toolbar button' },\n redo: { id: 'formwright.richText.redo', message: 'Redo', description: 'Toolbar button' },\n} satisfies Record<string, Message>\n"],"names":["messages","toolbar","id","message","description","bold","italic","strike","heading","bulletList","orderedList","blockquote","undo","redo"],"mappings":"AAEA;AAC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EAAE,MAAM;AAAEC,IAAAA,WAAW,EAAE;AAAiB;AACzF;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ember-formwright/tiptap",
3
- "version": "1.3.0",
3
+ "version": "2.0.0",
4
4
  "description": "A rich-text control for Formwright, powered by Tiptap.",
5
5
  "keywords": [
6
6
  "ember-addon",
@@ -26,6 +26,10 @@
26
26
  "types": "./declarations/index.d.ts",
27
27
  "default": "./dist/index.js"
28
28
  },
29
+ "./messages": {
30
+ "types": "./declarations/messages.d.ts",
31
+ "default": "./dist/messages.js"
32
+ },
29
33
  "./test-support": {
30
34
  "types": "./declarations/test-support/index.d.ts",
31
35
  "default": "./dist/test-support/index.js"
@@ -58,8 +62,8 @@
58
62
  "@tiptap/pm": ">= 3.0.0",
59
63
  "@tiptap/starter-kit": ">= 3.0.0",
60
64
  "ember-source": ">= 6.12.0",
61
- "@ember-formwright/ember": "^1.3.0",
62
- "@ember-formwright/test-support": "^1.3.0"
65
+ "@ember-formwright/ember": "^2.0.0",
66
+ "@ember-formwright/test-support": "^2.0.0"
63
67
  },
64
68
  "peerDependenciesMeta": {
65
69
  "@ember-formwright/test-support": {
@@ -77,9 +81,9 @@
77
81
  "@ember/test-helpers": "^5.7.0",
78
82
  "@embroider/addon-dev": "^8.4.2",
79
83
  "@embroider/macros": "^1.21.1",
80
- "@glimmer/component": "^2.1.1",
84
+ "@glimmer/component": "^2.2.1",
81
85
  "@glimmer/tracking": "^1.1.2",
82
- "@glint/ember-tsc": "^1.11.6",
86
+ "@glint/ember-tsc": "^1.14.2",
83
87
  "@glint/template": "^1.9.0",
84
88
  "@rollup/plugin-babel": "^7.1.0",
85
89
  "@tiptap/core": "^3.32.0",
@@ -89,8 +93,8 @@
89
93
  "ember-source": "~7.3.0",
90
94
  "rollup": "^4.64.6",
91
95
  "typescript": "~6.0.3",
92
- "@ember-formwright/ember": "1.3.0",
93
- "@ember-formwright/test-support": "1.3.0"
96
+ "@ember-formwright/ember": "2.0.0",
97
+ "@ember-formwright/test-support": "2.0.0"
94
98
  },
95
99
  "publishConfig": {
96
100
  "access": "public"