@pie-element/simple-cloze 0.1.4-next.7 → 0.1.4-next.8

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.
@@ -2,15 +2,17 @@ declare const SvelteElementClass: any;
2
2
  declare class SimpleClozeAuthor extends SvelteElementClass {
3
3
  private _model;
4
4
  private _onChange;
5
+ onModelChange: (update: any) => void;
6
+ /**
7
+ * The component reports each edit through its `onModelChange` prop, assigned
8
+ * here through the accessor Svelte generates for it. The host keeps the
9
+ * edited model, renders from it, and announces it as `model.updated`, which
10
+ * bubbles to the listener an authoring player registers at its root.
11
+ */
12
+ constructor();
5
13
  set model(m: any);
6
14
  get model(): any;
7
15
  set onChange(fn: (model: any) => void);
8
16
  get onChange(): (model: any) => void;
9
- /**
10
- * The component reports each edit here. The host keeps the edited model,
11
- * renders from it, and announces it as `model.updated`, which bubbles to
12
- * the listener an authoring player registers at its root.
13
- */
14
- onModelChange: (update: any) => void;
15
17
  }
16
18
  export default SimpleClozeAuthor;
@@ -1,10 +1,10 @@
1
1
  //#region ../../shared/configure-events/dist/index.js
2
- var _e$1;
3
- var _e2$1;
2
+ var _e;
3
+ var _e2;
4
4
  var _e3;
5
5
  var _e4;
6
6
  var _e5;
7
- var e = (_e$1 = class e extends CustomEvent {
7
+ var e = (_e = class e extends CustomEvent {
8
8
  constructor(t, n = !1) {
9
9
  super(e.TYPE, {
10
10
  bubbles: !0,
@@ -14,8 +14,8 @@ var e = (_e$1 = class e extends CustomEvent {
14
14
  }
15
15
  }), this.update = t, this.reset = n;
16
16
  }
17
- }, _e$1.TYPE = "model.updated", _e$1);
18
- _e2$1 = class e extends CustomEvent {
17
+ }, _e.TYPE = "model.updated", _e);
18
+ _e2 = class e extends CustomEvent {
19
19
  constructor(t, n) {
20
20
  super(e.TYPE, {
21
21
  bubbles: !0,
@@ -25,7 +25,7 @@ _e2$1 = class e extends CustomEvent {
25
25
  }
26
26
  }), this.src = t, this.done = n;
27
27
  }
28
- }, _e2$1.TYPE = "delete.image";
28
+ }, _e2.TYPE = "delete.image";
29
29
  _e3 = class e extends CustomEvent {
30
30
  constructor(t) {
31
31
  super(e.TYPE, {
@@ -4795,54 +4795,6 @@ function create_custom_element(Component, props_definition, slots, exports, shad
4795
4795
  return Class;
4796
4796
  }
4797
4797
  //#endregion
4798
- //#region ../../shared/player-events/dist/index.js
4799
- var _e;
4800
- var _e2;
4801
- _e = class e extends CustomEvent {
4802
- constructor(t, n, r) {
4803
- super(e.TYPE, {
4804
- bubbles: !0,
4805
- composed: !0,
4806
- detail: {
4807
- complete: n,
4808
- component: t,
4809
- hasModel: r
4810
- }
4811
- }), this.component = t, this.complete = n;
4812
- }
4813
- }, _e.TYPE = "model-set";
4814
- _e2 = class e extends CustomEvent {
4815
- constructor(t, n) {
4816
- super(e.TYPE, {
4817
- bubbles: !0,
4818
- composed: !0,
4819
- detail: {
4820
- complete: n,
4821
- component: t
4822
- }
4823
- }), this.component = t, this.complete = n;
4824
- }
4825
- }, _e2.TYPE = "session-changed";
4826
- //#endregion
4827
- //#region ../../lib-svelte/delivery-events/dist/index2.js
4828
- var t = (e) => {
4829
- let t = e;
4830
- return t ? typeof t.onSessionChange == "function" || typeof t.onAudioStarted == "function" || typeof t.onAudioEnded == "function" : !1;
4831
- };
4832
- function n(e) {
4833
- if (e.parentElement) return e.parentElement;
4834
- let t = e.getRootNode();
4835
- return t instanceof ShadowRoot ? t.host : null;
4836
- }
4837
- function r(e, r = {}) {
4838
- let i = r.hostPredicate ?? t, a = e;
4839
- for (; a;) {
4840
- if (i(a)) return a;
4841
- a = n(a);
4842
- }
4843
- return null;
4844
- }
4845
- //#endregion
4846
4798
  //#region ../../../node_modules/.bun/@tiptap+core@3.31.3+ef29727eaaf819d3/node_modules/@tiptap/core/dist/rolldown-runtime-D7D4PA-g.js
4847
4799
  var __defProp = Object.defineProperty;
4848
4800
  var __exportAll = (all, no_symbols) => {
@@ -31299,8 +31251,15 @@ function EditableHtml$1($$anchor, $$props) {
31299
31251
  let markup = prop($$props, "markup", 3, ""), placeholder = prop($$props, "placeholder", 3, "Enter text here..."), showToolbar = prop($$props, "showToolbar", 3, true), disabled = prop($$props, "disabled", 3, false);
31300
31252
  let editorElement;
31301
31253
  let editor = /* @__PURE__ */ state(null);
31302
- let isFocused = /* @__PURE__ */ state(false);
31254
+ let hasFocus = /* @__PURE__ */ state(false);
31303
31255
  let showAlignMenu = /* @__PURE__ */ state(false);
31256
+ function editorAttributes() {
31257
+ return {
31258
+ role: "textbox",
31259
+ "aria-multiline": "true",
31260
+ ...$$props.ariaLabel ? { "aria-label": $$props.ariaLabel } : {}
31261
+ };
31262
+ }
31304
31263
  let editorState = /* @__PURE__ */ state(proxy({
31305
31264
  isBold: false,
31306
31265
  canBold: false,
@@ -31392,6 +31351,7 @@ function EditableHtml$1($$anchor, $$props) {
31392
31351
  content: markup() || "",
31393
31352
  editable: !disabled(),
31394
31353
  autofocus: false,
31354
+ editorProps: { attributes: editorAttributes() },
31395
31355
  onUpdate: ({ editor }) => {
31396
31356
  const html = editor.getHTML();
31397
31357
  if ($$props.onChange) $$props.onChange(html);
@@ -31401,12 +31361,7 @@ function EditableHtml$1($$anchor, $$props) {
31401
31361
  updateEditorState();
31402
31362
  },
31403
31363
  onFocus: () => {
31404
- set(isFocused, true);
31405
31364
  updateEditorState();
31406
- },
31407
- onBlur: () => {
31408
- set(isFocused, false);
31409
- set(showAlignMenu, false);
31410
31365
  }
31411
31366
  }), true);
31412
31367
  updateEditorState();
@@ -31421,6 +31376,19 @@ function EditableHtml$1($$anchor, $$props) {
31421
31376
  const editable = !disabled();
31422
31377
  if (get(editor) && get(editor).isEditable !== editable) get(editor).setEditable(editable, false);
31423
31378
  });
31379
+ user_effect(() => {
31380
+ const attributes = editorAttributes();
31381
+ if (get(editor) && get(editor).view.dom.getAttribute("aria-label") !== (attributes["aria-label"] ?? null)) get(editor).setOptions({ editorProps: { attributes } });
31382
+ });
31383
+ function handleFocusIn() {
31384
+ set(hasFocus, true);
31385
+ }
31386
+ function handleFocusOut(e) {
31387
+ if (!e.currentTarget.contains(e.relatedTarget)) {
31388
+ set(hasFocus, false);
31389
+ set(showAlignMenu, false);
31390
+ }
31391
+ }
31424
31392
  function toggleBold() {
31425
31393
  get(editor)?.chain().focus().toggleBold().run();
31426
31394
  }
@@ -31725,7 +31693,10 @@ function EditableHtml$1($$anchor, $$props) {
31725
31693
  reset$1(button_24);
31726
31694
  reset$1(div_5);
31727
31695
  reset$1(div_4);
31728
- template_effect(() => classes_1 = set_class(div_4, 1, "toolbar", null, classes_1, { focused: get(isFocused) }));
31696
+ template_effect(() => {
31697
+ classes_1 = set_class(div_4, 1, "toolbar", null, classes_1, { focused: get(hasFocus) });
31698
+ div_4.inert = !get(hasFocus);
31699
+ });
31729
31700
  delegated("mousedown", div_4, handleMouseDown);
31730
31701
  delegated("click", button_24, handleDoneClick);
31731
31702
  append($$anchor, div_4);
@@ -31735,10 +31706,17 @@ function EditableHtml$1($$anchor, $$props) {
31735
31706
  });
31736
31707
  reset$1(div);
31737
31708
  template_effect(() => classes = set_class(div_1, 1, "editor-holder", null, classes, { disabled: disabled() }));
31709
+ delegated("focusin", div, handleFocusIn);
31710
+ delegated("focusout", div, handleFocusOut);
31738
31711
  append($$anchor, div);
31739
31712
  pop();
31740
31713
  }
31741
- delegate(["mousedown", "click"]);
31714
+ delegate([
31715
+ "focusin",
31716
+ "focusout",
31717
+ "mousedown",
31718
+ "click"
31719
+ ]);
31742
31720
  //#endregion
31743
31721
  //#region ../../lib-svelte/editable-html-tiptap-svelte/dist/index.js
31744
31722
  var EditableHtml = EditableHtml$1;
@@ -31752,10 +31730,8 @@ var $$css = {
31752
31730
  function Author($$anchor, $$props) {
31753
31731
  push($$props, true);
31754
31732
  append_styles($$anchor, $$css);
31755
- let model = prop($$props, "model", 15), onChange = prop($$props, "onChange", 7);
31756
- let rootEl = /* @__PURE__ */ state(null);
31733
+ let model = prop($$props, "model", 15), onChange = prop($$props, "onChange", 7), onModelChange = prop($$props, "onModelChange", 7);
31757
31734
  const answerInputId = `simple-cloze-correct-answer-${Math.random().toString(36).slice(2, 10)}`;
31758
- const isAuthorHost = (node) => typeof node?.onModelChange === "function";
31759
31735
  /**
31760
31736
  * The wrapper owns the model and announces the edit; `onChange` serves a
31761
31737
  * component mounted without one. The update spreads the whole model, so fields
@@ -31766,8 +31742,7 @@ function Author($$anchor, $$props) {
31766
31742
  ...model() || {},
31767
31743
  ...patch
31768
31744
  };
31769
- const host = r(get(rootEl), { hostPredicate: isAuthorHost });
31770
- if (host) host.onModelChange(nextModel);
31745
+ if (onModelChange()) onModelChange()(nextModel);
31771
31746
  else {
31772
31747
  model(nextModel);
31773
31748
  onChange()?.(nextModel);
@@ -31793,19 +31768,27 @@ function Author($$anchor, $$props) {
31793
31768
  set onChange($$value) {
31794
31769
  onChange($$value);
31795
31770
  flushSync();
31771
+ },
31772
+ get onModelChange() {
31773
+ return onModelChange();
31774
+ },
31775
+ set onModelChange($$value) {
31776
+ onModelChange($$value);
31777
+ flushSync();
31796
31778
  }
31797
31779
  };
31798
31780
  var div = root();
31799
31781
  var div_1 = child(div);
31800
- var node_1 = sibling(child(div_1), 2);
31782
+ var node = sibling(child(div_1), 2);
31801
31783
  {
31802
31784
  let $0 = /* @__PURE__ */ user_derived(() => model()?.prompt || "");
31803
- EditableHtml(node_1, {
31785
+ EditableHtml(node, {
31804
31786
  get markup() {
31805
31787
  return get($0);
31806
31788
  },
31807
31789
  onChange: handlePromptChange,
31808
- placeholder: "Enter your question here..."
31790
+ placeholder: "Enter your question here...",
31791
+ ariaLabel: "Prompt"
31809
31792
  });
31810
31793
  }
31811
31794
  reset$1(div_1);
@@ -31815,7 +31798,6 @@ function Author($$anchor, $$props) {
31815
31798
  remove_input_defaults(input);
31816
31799
  reset$1(div_2);
31817
31800
  reset$1(div);
31818
- bind_this(div, ($$value) => set(rootEl, $$value), () => get(rootEl));
31819
31801
  template_effect(() => {
31820
31802
  set_attribute(label, "for", answerInputId);
31821
31803
  set_attribute(input, "id", answerInputId);
@@ -31828,31 +31810,29 @@ function Author($$anchor, $$props) {
31828
31810
  delegate(["input"]);
31829
31811
  create_custom_element(Author, {
31830
31812
  model: { type: "Object" },
31813
+ onModelChange: {},
31831
31814
  onChange: {}
31832
31815
  }, [], []);
31833
31816
  //#endregion
31834
31817
  //#region src/author/index.ts
31835
31818
  var SvelteElementClass = Author.element;
31836
31819
  var SimpleClozeAuthor = class extends SvelteElementClass {
31837
- constructor(..._args) {
31838
- super(..._args);
31820
+ /**
31821
+ * The component reports each edit through its `onModelChange` prop, assigned
31822
+ * here through the accessor Svelte generates for it. The host keeps the
31823
+ * edited model, renders from it, and announces it as `model.updated`, which
31824
+ * bubbles to the listener an authoring player registers at its root.
31825
+ */
31826
+ constructor() {
31827
+ super();
31839
31828
  _defineProperty(this, "_model", null);
31840
31829
  _defineProperty(this, "_onChange", null);
31841
- _defineProperty(
31842
- this,
31843
- /**
31844
- * The component reports each edit here. The host keeps the edited model,
31845
- * renders from it, and announces it as `model.updated`, which bubbles to
31846
- * the listener an authoring player registers at its root.
31847
- */
31848
- "onModelChange",
31849
- (update) => {
31850
- this._model = update;
31851
- super.model = update;
31852
- this._onChange?.(update);
31853
- this.dispatchEvent(new e(update, false));
31854
- }
31855
- );
31830
+ this.onModelChange = (update) => {
31831
+ this._model = update;
31832
+ super.model = update;
31833
+ this._onChange?.(update);
31834
+ this.dispatchEvent(new e(update, false));
31835
+ };
31856
31836
  }
31857
31837
  set model(m) {
31858
31838
  this._model = m;