@webwriter/quiz 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/LICENSE +6 -6
  2. package/custom.d.ts +175 -175
  3. package/dist/widgets/webwriter-choice-item.js +58 -13
  4. package/dist/widgets/webwriter-choice.js +64 -19
  5. package/dist/widgets/webwriter-cloze-gap.js +59 -14
  6. package/dist/widgets/webwriter-cloze.js +56 -11
  7. package/dist/widgets/webwriter-mark.js +56 -11
  8. package/dist/widgets/webwriter-order-item.js +56 -11
  9. package/dist/widgets/webwriter-order.js +226 -1685
  10. package/dist/widgets/webwriter-pairing.js +59 -14
  11. package/dist/widgets/webwriter-quiz.js +67 -22
  12. package/dist/widgets/webwriter-speech.js +66 -20
  13. package/dist/widgets/webwriter-task.js +534 -308
  14. package/dist/widgets/webwriter-text.js +60 -14
  15. package/package.json +200 -200
  16. package/src/lib/combobox.ts +455 -455
  17. package/src/snippets/choice.html +7 -7
  18. package/src/snippets/cloze.html +3 -3
  19. package/src/snippets/mark.html +3 -3
  20. package/src/snippets/order.html +7 -7
  21. package/src/snippets/pairing.html +9 -9
  22. package/src/snippets/speech.html +3 -3
  23. package/src/snippets/text.html +3 -3
  24. package/src/snippets/wordsearch.html +3 -3
  25. package/src/widgets/webwriter-choice-item.ts +250 -250
  26. package/src/widgets/webwriter-choice.ts +309 -309
  27. package/src/widgets/webwriter-cloze-gap.ts +216 -216
  28. package/src/widgets/webwriter-cloze.ts +135 -135
  29. package/src/widgets/webwriter-mark.ts +434 -434
  30. package/src/widgets/webwriter-order-item.ts +436 -444
  31. package/src/widgets/webwriter-order.ts +279 -272
  32. package/src/widgets/webwriter-pairing-item.ts +155 -155
  33. package/src/widgets/webwriter-pairing.ts +187 -187
  34. package/src/widgets/webwriter-quiz.ts +280 -280
  35. package/src/widgets/webwriter-speech.ts +267 -267
  36. package/src/widgets/webwriter-task-explainer.ts +37 -37
  37. package/src/widgets/webwriter-task-hint.ts +16 -16
  38. package/src/widgets/webwriter-task-prompt.ts +17 -17
  39. package/src/widgets/webwriter-task.ts +543 -543
  40. package/src/widgets/webwriter-text.ts +130 -130
  41. package/tsconfig.json +6 -6
@@ -1312,27 +1312,6 @@ function option(decl = { type: "string" }) {
1312
1312
  context.addInitializer(init);
1313
1313
  };
1314
1314
  }
1315
- function action(decl) {
1316
- return (target, context) => {
1317
- function init() {
1318
- this.constructor["actions"] = { ...this.constructor["actions"], [context.name]: decl };
1319
- }
1320
- context.addInitializer(init);
1321
- function func(...args) {
1322
- this._inTransaction = true;
1323
- try {
1324
- return target.apply(this, args);
1325
- } finally {
1326
- this._inTransaction = false;
1327
- }
1328
- }
1329
- if (context.kind === "method") {
1330
- return func;
1331
- } else {
1332
- context.access.set(this, func);
1333
- }
1334
- };
1335
- }
1336
1315
  var _lang_dec;
1337
1316
  var _contentEditable_dec;
1338
1317
  var _a;
@@ -1555,17 +1534,17 @@ var LocalizeController = class {
1555
1534
  return `${this.host.lang || documentLanguage}`.toLowerCase();
1556
1535
  }
1557
1536
  getTranslationData(lang) {
1558
- var _a4, _b;
1537
+ var _a3, _b;
1559
1538
  const locale = new Intl.Locale(lang.replace(/_/g, "-"));
1560
1539
  const language = locale === null || locale === void 0 ? void 0 : locale.language.toLowerCase();
1561
- const region = (_b = (_a4 = locale === null || locale === void 0 ? void 0 : locale.region) === null || _a4 === void 0 ? void 0 : _a4.toLowerCase()) !== null && _b !== void 0 ? _b : "";
1540
+ const region = (_b = (_a3 = locale === null || locale === void 0 ? void 0 : locale.region) === null || _a3 === void 0 ? void 0 : _a3.toLowerCase()) !== null && _b !== void 0 ? _b : "";
1562
1541
  const primary = translations.get(`${language}-${region}`);
1563
1542
  const secondary = translations.get(language);
1564
1543
  return { locale, language, region, primary, secondary };
1565
1544
  }
1566
1545
  exists(key, options) {
1567
- var _a4;
1568
- const { primary, secondary } = this.getTranslationData((_a4 = options.lang) !== null && _a4 !== void 0 ? _a4 : this.lang());
1546
+ var _a3;
1547
+ const { primary, secondary } = this.getTranslationData((_a3 = options.lang) !== null && _a3 !== void 0 ? _a3 : this.lang());
1569
1548
  options = Object.assign({ includeFallback: false }, options);
1570
1549
  if (primary && primary[key] || secondary && secondary[key] || options.includeFallback && fallback && fallback[key]) {
1571
1550
  return true;
@@ -1662,7 +1641,7 @@ var component_styles_default = i`
1662
1641
  }
1663
1642
  `;
1664
1643
 
1665
- // ../../node_modules/@shoelace-style/shoelace/dist/chunks/chunk.IFDWM6P4.js
1644
+ // ../../node_modules/@shoelace-style/shoelace/dist/chunks/chunk.B3BW2AY6.js
1666
1645
  var __defProp3 = Object.defineProperty;
1667
1646
  var __defProps = Object.defineProperties;
1668
1647
  var __getOwnPropDesc3 = Object.getOwnPropertyDescriptor;
@@ -1692,11 +1671,32 @@ var __decorateClass = (decorators, target, key, kind) => {
1692
1671
  __defProp3(target, key, result);
1693
1672
  return result;
1694
1673
  };
1674
+ var __accessCheck3 = (obj, member, msg) => {
1675
+ if (!member.has(obj))
1676
+ throw TypeError("Cannot " + msg);
1677
+ };
1678
+ var __privateGet3 = (obj, member, getter) => {
1679
+ __accessCheck3(obj, member, "read from private field");
1680
+ return getter ? getter.call(obj) : member.get(obj);
1681
+ };
1682
+ var __privateAdd3 = (obj, member, value) => {
1683
+ if (member.has(obj))
1684
+ throw TypeError("Cannot add the same private member more than once");
1685
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1686
+ };
1687
+ var __privateSet3 = (obj, member, value, setter) => {
1688
+ __accessCheck3(obj, member, "write to private field");
1689
+ setter ? setter.call(obj, value) : member.set(obj, value);
1690
+ return value;
1691
+ };
1695
1692
 
1696
- // ../../node_modules/@shoelace-style/shoelace/dist/chunks/chunk.5THGRZAA.js
1693
+ // ../../node_modules/@shoelace-style/shoelace/dist/chunks/chunk.NLWS5DN7.js
1694
+ var _hasRecordedInitialProperties;
1697
1695
  var ShoelaceElement = class extends h3 {
1698
1696
  constructor() {
1699
1697
  super();
1698
+ __privateAdd3(this, _hasRecordedInitialProperties, false);
1699
+ this.initialReflectedProperties = /* @__PURE__ */ new Map();
1700
1700
  Object.entries(this.constructor.dependencies).forEach(([name, component]) => {
1701
1701
  this.constructor.define(name, component);
1702
1702
  });
@@ -1738,8 +1738,30 @@ var ShoelaceElement = class extends h3 {
1738
1738
  `Attempted to register <${name}>${newVersion}, but <${name}>${existingVersion} has already been registered.`
1739
1739
  );
1740
1740
  }
1741
+ attributeChangedCallback(name, oldValue, newValue) {
1742
+ if (!__privateGet3(this, _hasRecordedInitialProperties)) {
1743
+ this.constructor.elementProperties.forEach(
1744
+ (obj, prop) => {
1745
+ if (obj.reflect && this[prop] != null) {
1746
+ this.initialReflectedProperties.set(prop, this[prop]);
1747
+ }
1748
+ }
1749
+ );
1750
+ __privateSet3(this, _hasRecordedInitialProperties, true);
1751
+ }
1752
+ super.attributeChangedCallback(name, oldValue, newValue);
1753
+ }
1754
+ willUpdate(changedProperties) {
1755
+ super.willUpdate(changedProperties);
1756
+ this.initialReflectedProperties.forEach((value, prop) => {
1757
+ if (changedProperties.has(prop) && this[prop] == null) {
1758
+ this[prop] = value;
1759
+ }
1760
+ });
1761
+ }
1741
1762
  };
1742
- ShoelaceElement.version = "2.16.0";
1763
+ _hasRecordedInitialProperties = /* @__PURE__ */ new WeakMap();
1764
+ ShoelaceElement.version = "2.17.1";
1743
1765
  ShoelaceElement.dependencies = {};
1744
1766
  __decorateClass([
1745
1767
  n5()
@@ -1748,7 +1770,7 @@ __decorateClass([
1748
1770
  n5()
1749
1771
  ], ShoelaceElement.prototype, "lang", 2);
1750
1772
 
1751
- // ../../node_modules/@shoelace-style/shoelace/dist/chunks/chunk.7HOIOSC7.js
1773
+ // ../../node_modules/@shoelace-style/shoelace/dist/chunks/chunk.R2T2D3TO.js
1752
1774
  var SlSpinner = class extends ShoelaceElement {
1753
1775
  constructor() {
1754
1776
  super(...arguments);
@@ -1765,7 +1787,7 @@ var SlSpinner = class extends ShoelaceElement {
1765
1787
  };
1766
1788
  SlSpinner.styles = [component_styles_default, spinner_styles_default];
1767
1789
 
1768
- // ../../node_modules/@shoelace-style/shoelace/dist/chunks/chunk.KWPBDQ6I.js
1790
+ // ../../node_modules/@shoelace-style/shoelace/dist/chunks/chunk.2RCF7SLU.js
1769
1791
  var formCollections = /* @__PURE__ */ new WeakMap();
1770
1792
  var reportValidityOverloads = /* @__PURE__ */ new WeakMap();
1771
1793
  var checkValidityOverloads = /* @__PURE__ */ new WeakMap();
@@ -1789,11 +1811,11 @@ var FormControlController = class {
1789
1811
  }
1790
1812
  };
1791
1813
  this.handleFormSubmit = (event) => {
1792
- var _a4;
1814
+ var _a3;
1793
1815
  const disabled = this.options.disabled(this.host);
1794
1816
  const reportValidity = this.options.reportValidity;
1795
1817
  if (this.form && !this.form.noValidate) {
1796
- (_a4 = formCollections.get(this.form)) == null ? void 0 : _a4.forEach((control) => {
1818
+ (_a3 = formCollections.get(this.form)) == null ? void 0 : _a3.forEach((control) => {
1797
1819
  this.setUserInteracted(control, true);
1798
1820
  });
1799
1821
  }
@@ -1859,8 +1881,8 @@ var FormControlController = class {
1859
1881
  value: (input) => input.value,
1860
1882
  defaultValue: (input) => input.defaultValue,
1861
1883
  disabled: (input) => {
1862
- var _a4;
1863
- return (_a4 = input.disabled) != null ? _a4 : false;
1884
+ var _a3;
1885
+ return (_a3 = input.disabled) != null ? _a3 : false;
1864
1886
  },
1865
1887
  reportValidity: (input) => typeof input.reportValidity === "function" ? input.reportValidity() : true,
1866
1888
  checkValidity: (input) => typeof input.checkValidity === "function" ? input.checkValidity() : true,
@@ -1978,8 +2000,8 @@ var FormControlController = class {
1978
2000
  }
1979
2001
  /** Returns the associated `<form>` element, if one exists. */
1980
2002
  getForm() {
1981
- var _a4;
1982
- return (_a4 = this.form) != null ? _a4 : null;
2003
+ var _a3;
2004
+ return (_a3 = this.form) != null ? _a3 : null;
1983
2005
  }
1984
2006
  /** Resets the form, restoring all the control to their default value */
1985
2007
  reset(submitter) {
@@ -2882,7 +2904,7 @@ var icon_styles_default = i`
2882
2904
  }
2883
2905
  `;
2884
2906
 
2885
- // ../../node_modules/@shoelace-style/shoelace/dist/chunks/chunk.2FB5TK5H.js
2907
+ // ../../node_modules/@shoelace-style/shoelace/dist/chunks/chunk.CCJUT23E.js
2886
2908
  function watch(propertyName, options) {
2887
2909
  const resolvedOptions = __spreadValues({
2888
2910
  waitUntilFirstUpdate: false
@@ -2911,11 +2933,8 @@ function watch(propertyName, options) {
2911
2933
  // ../../node_modules/lit/node_modules/lit-html/directive-helpers.js
2912
2934
  var { I: et3 } = si;
2913
2935
  var nt = (o6, t5) => void 0 === t5 ? void 0 !== o6?._$litType$ : o6?._$litType$ === t5;
2914
- var rt = (o6) => void 0 === o6.strings;
2915
- var ht = {};
2916
- var dt = (o6, t5 = ht) => o6._$AH = t5;
2917
2936
 
2918
- // ../../node_modules/@shoelace-style/shoelace/dist/chunks/chunk.ALSPWWWG.js
2937
+ // ../../node_modules/@shoelace-style/shoelace/dist/chunks/chunk.O7VCMB7W.js
2919
2938
  var CACHEABLE_ERROR = Symbol();
2920
2939
  var RETRYABLE_ERROR = Symbol();
2921
2940
  var parser;
@@ -2930,17 +2949,12 @@ var SlIcon = class extends ShoelaceElement {
2930
2949
  }
2931
2950
  /** Given a URL, this function returns the resulting SVG element or an appropriate error symbol. */
2932
2951
  async resolveIcon(url, library2) {
2933
- var _a4;
2952
+ var _a3;
2934
2953
  let fileData;
2935
2954
  if (library2 == null ? void 0 : library2.spriteSheet) {
2936
2955
  this.svg = ke`<svg part="svg">
2937
2956
  <use part="use" href="${url}"></use>
2938
2957
  </svg>`;
2939
- await this.updateComplete;
2940
- const svg = this.shadowRoot.querySelector("[part='svg']");
2941
- if (typeof library2.mutator === "function") {
2942
- library2.mutator(svg);
2943
- }
2944
2958
  return this.svg;
2945
2959
  }
2946
2960
  try {
@@ -2954,7 +2968,7 @@ var SlIcon = class extends ShoelaceElement {
2954
2968
  const div = document.createElement("div");
2955
2969
  div.innerHTML = await fileData.text();
2956
2970
  const svg = div.firstElementChild;
2957
- if (((_a4 = svg == null ? void 0 : svg.tagName) == null ? void 0 : _a4.toLowerCase()) !== "svg")
2971
+ if (((_a3 = svg == null ? void 0 : svg.tagName) == null ? void 0 : _a3.toLowerCase()) !== "svg")
2958
2972
  return CACHEABLE_ERROR;
2959
2973
  if (!parser)
2960
2974
  parser = new DOMParser();
@@ -3006,7 +3020,7 @@ var SlIcon = class extends ShoelaceElement {
3006
3020
  }
3007
3021
  }
3008
3022
  async setIcon() {
3009
- var _a4;
3023
+ var _a3;
3010
3024
  const { url, fromLibrary } = this.getIconSource();
3011
3025
  const library2 = fromLibrary ? getIconLibrary(this.library) : void 0;
3012
3026
  if (!url) {
@@ -3030,6 +3044,13 @@ var SlIcon = class extends ShoelaceElement {
3030
3044
  }
3031
3045
  if (nt(svg)) {
3032
3046
  this.svg = svg;
3047
+ if (library2) {
3048
+ await this.updateComplete;
3049
+ const shadowSVG = this.shadowRoot.querySelector("[part='svg']");
3050
+ if (typeof library2.mutator === "function" && shadowSVG) {
3051
+ library2.mutator(shadowSVG);
3052
+ }
3053
+ }
3033
3054
  return;
3034
3055
  }
3035
3056
  switch (svg) {
@@ -3040,7 +3061,7 @@ var SlIcon = class extends ShoelaceElement {
3040
3061
  break;
3041
3062
  default:
3042
3063
  this.svg = svg.cloneNode(true);
3043
- (_a4 = library2 == null ? void 0 : library2.mutator) == null ? void 0 : _a4.call(library2, this.svg);
3064
+ (_a3 = library2 == null ? void 0 : library2.mutator) == null ? void 0 : _a3.call(library2, this.svg);
3044
3065
  this.emit("sl-load");
3045
3066
  }
3046
3067
  }
@@ -3148,7 +3169,7 @@ var Se3 = Ee(Se);
3148
3169
  // ../../node_modules/lit/node_modules/lit-html/directives/if-defined.js
3149
3170
  var to = (t5) => t5 ?? D;
3150
3171
 
3151
- // ../../node_modules/@shoelace-style/shoelace/dist/chunks/chunk.MR6SHCJO.js
3172
+ // ../../node_modules/@shoelace-style/shoelace/dist/chunks/chunk.OEHLR4TU.js
3152
3173
  var SlButton = class extends ShoelaceElement {
3153
3174
  constructor() {
3154
3175
  super(...arguments);
@@ -3297,7 +3318,7 @@ var SlButton = class extends ShoelaceElement {
3297
3318
  title=${this.title}
3298
3319
  name=${to(isLink ? void 0 : this.name)}
3299
3320
  value=${to(isLink ? void 0 : this.value)}
3300
- href=${to(isLink ? this.href : void 0)}
3321
+ href=${to(isLink && !this.disabled ? this.href : void 0)}
3301
3322
  target=${to(isLink ? this.target : void 0)}
3302
3323
  download=${to(isLink ? this.download : void 0)}
3303
3324
  rel=${to(isLink ? this.rel : void 0)}
@@ -3405,1654 +3426,180 @@ __decorateClass([
3405
3426
  // ../../node_modules/bootstrap-icons/icons/plus.svg
3406
3427
  var plus_default = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-plus" viewBox="0 0 16 16">%0A <path d="M8 4a.5.5 0 0 1 .5.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3A.5.5 0 0 1 8 4"/>%0A</svg>';
3407
3428
 
3408
- // ../../node_modules/@shoelace-style/shoelace/dist/chunks/chunk.FKMWLPHV.js
3409
- var radio_styles_default = i`
3410
- :host {
3411
- display: block;
3412
- }
3413
-
3414
- :host(:focus-visible) {
3415
- outline: 0px;
3416
- }
3417
-
3418
- .radio {
3419
- display: inline-flex;
3420
- align-items: top;
3421
- font-family: var(--sl-input-font-family);
3422
- font-size: var(--sl-input-font-size-medium);
3423
- font-weight: var(--sl-input-font-weight);
3424
- color: var(--sl-input-label-color);
3425
- vertical-align: middle;
3426
- cursor: pointer;
3427
- }
3428
-
3429
- .radio--small {
3430
- --toggle-size: var(--sl-toggle-size-small);
3431
- font-size: var(--sl-input-font-size-small);
3432
- }
3433
-
3434
- .radio--medium {
3435
- --toggle-size: var(--sl-toggle-size-medium);
3436
- font-size: var(--sl-input-font-size-medium);
3429
+ // src/widgets/webwriter-order.ts
3430
+ function shuffle(a3) {
3431
+ for (let i4 = a3.length - 1; i4 > 0; i4--) {
3432
+ const j3 = Math.floor(Math.random() * (i4 + 1));
3433
+ [a3[i4], a3[j3]] = [a3[j3], a3[i4]];
3437
3434
  }
3438
-
3439
- .radio--large {
3440
- --toggle-size: var(--sl-toggle-size-large);
3441
- font-size: var(--sl-input-font-size-large);
3435
+ return a3;
3436
+ }
3437
+ var _solution_dec, _items_dec, _itemsSlot_dec, _hideOrderButtons_dec, _layout_dec, _a2, _WebwriterOrder_decorators, _init2, _itemsSlot, _items, _solution;
3438
+ _WebwriterOrder_decorators = [t3("webwriter-order")];
3439
+ var WebwriterOrder = class extends (_a2 = LitElementWw, _layout_dec = [n5({ type: String, attribute: true, reflect: true }), option({
3440
+ type: "select",
3441
+ options: [
3442
+ { value: "list", label: { "en": "List" } },
3443
+ { value: "tiles", label: { "en": "Tiles" } }
3444
+ ]
3445
+ })], _hideOrderButtons_dec = [n5({ type: Boolean, attribute: true, reflect: true }), option({ type: Boolean, label: { _: "Hide order buttons" } })], _itemsSlot_dec = [e5("#items-slot")], _items_dec = [o5()], _solution_dec = [n5({ attribute: false })], _a2) {
3446
+ constructor() {
3447
+ super(...arguments);
3448
+ __runInitializers(_init2, 5, this);
3449
+ __publicField(this, "observer");
3450
+ __publicField(this, "orderSheet", new CSSStyleSheet());
3451
+ __publicField(this, "clearDropPreviews", () => {
3452
+ this.items.forEach((item) => item.dropPreview = void 0);
3453
+ });
3454
+ __privateAdd(this, _itemsSlot, __runInitializers(_init2, 8, this)), __runInitializers(_init2, 11, this);
3455
+ __privateAdd(this, _items, __runInitializers(_init2, 12, this)), __runInitializers(_init2, 15, this);
3456
+ __publicField(this, "handleMove", (e7) => {
3457
+ const elem = e7.target;
3458
+ const children = Array.from(this.children);
3459
+ const pos = children.indexOf(elem);
3460
+ let i4;
3461
+ if (e7.type === "ww-moveup") {
3462
+ i4 = Math.max(0, pos - 1);
3463
+ } else if (e7.type === "ww-movedown") {
3464
+ i4 = Math.min(children.length, pos + 2);
3465
+ } else if (e7.type === "ww-moveto") {
3466
+ i4 = e7.detail.i;
3467
+ }
3468
+ this.moveChild(elem, i4);
3469
+ });
3470
+ __privateAdd(this, _solution, []);
3442
3471
  }
3443
-
3444
- .radio__checked-icon {
3445
- display: inline-flex;
3446
- width: var(--toggle-size);
3447
- height: var(--toggle-size);
3472
+ get layout() {
3473
+ return this.children?.item(0)?.getAttribute("layout") ?? "list";
3448
3474
  }
3449
-
3450
- .radio__control {
3451
- flex: 0 0 auto;
3452
- position: relative;
3453
- display: inline-flex;
3454
- align-items: center;
3455
- justify-content: center;
3456
- width: var(--toggle-size);
3457
- height: var(--toggle-size);
3458
- border: solid var(--sl-input-border-width) var(--sl-input-border-color);
3459
- border-radius: 50%;
3460
- background-color: var(--sl-input-background-color);
3461
- color: transparent;
3462
- transition:
3463
- var(--sl-transition-fast) border-color,
3464
- var(--sl-transition-fast) background-color,
3465
- var(--sl-transition-fast) color,
3466
- var(--sl-transition-fast) box-shadow;
3475
+ set layout(value) {
3476
+ this.querySelectorAll("webwriter-order-item").forEach((el) => el.setAttribute("layout", value));
3477
+ this.requestUpdate("layout");
3467
3478
  }
3468
-
3469
- .radio__input {
3470
- position: absolute;
3471
- opacity: 0;
3472
- padding: 0;
3473
- margin: 0;
3474
- pointer-events: none;
3479
+ get hideOrderButtons() {
3480
+ return !!this.items[0]?.hideOrderButtons;
3475
3481
  }
3476
-
3477
- /* Hover */
3478
- .radio:not(.radio--checked):not(.radio--disabled) .radio__control:hover {
3479
- border-color: var(--sl-input-border-color-hover);
3480
- background-color: var(--sl-input-background-color-hover);
3482
+ set hideOrderButtons(value) {
3483
+ this.items.forEach((item) => item.hideOrderButtons = value);
3481
3484
  }
3482
-
3483
- /* Checked */
3484
- .radio--checked .radio__control {
3485
- color: var(--sl-color-neutral-0);
3486
- border-color: var(--sl-color-primary-600);
3487
- background-color: var(--sl-color-primary-600);
3485
+ connectedCallback() {
3486
+ super.connectedCallback();
3487
+ this.addEventListener("ww-moveup", this.handleMove);
3488
+ this.addEventListener("ww-movedown", this.handleMove);
3489
+ this.addEventListener("ww-moveto", this.handleMove);
3490
+ this.observer = new MutationObserver(() => {
3491
+ this.items.forEach((item) => item.requestUpdate());
3492
+ if (this.isContentEditable) {
3493
+ this.solution = this.items.map((item) => item.id);
3494
+ }
3495
+ this.clearDropPreviews();
3496
+ });
3497
+ this.observer.observe(this, { childList: true });
3488
3498
  }
3489
-
3490
- /* Checked + hover */
3491
- .radio.radio--checked:not(.radio--disabled) .radio__control:hover {
3492
- border-color: var(--sl-color-primary-500);
3493
- background-color: var(--sl-color-primary-500);
3499
+ serializedCallback() {
3500
+ this.shuffleItems();
3494
3501
  }
3495
-
3496
- /* Checked + focus */
3497
- :host(:focus-visible) .radio__control {
3498
- outline: var(--sl-focus-ring);
3499
- outline-offset: var(--sl-focus-ring-offset);
3502
+ disconnectedCallback() {
3503
+ super.disconnectedCallback();
3504
+ this.observer?.disconnect();
3505
+ this.observer = void 0;
3500
3506
  }
3501
-
3502
- /* Disabled */
3503
- .radio--disabled {
3504
- opacity: 0.5;
3505
- cursor: not-allowed;
3507
+ addItem() {
3508
+ const orderItem = this.ownerDocument.createElement("webwriter-order-item");
3509
+ const p3 = this.ownerDocument.createElement("p");
3510
+ orderItem.appendChild(p3);
3511
+ orderItem.setAttribute("layout", this.layout);
3512
+ this.append(orderItem);
3513
+ this.solution = [...__privateGet(this, _solution), orderItem.id];
3514
+ this.ownerDocument.getSelection().setBaseAndExtent(p3, 0, p3, 0);
3506
3515
  }
3507
-
3508
- /* When the control isn't checked, hide the circle for Windows High Contrast mode a11y */
3509
- .radio:not(.radio--checked) svg circle {
3510
- opacity: 0;
3516
+ shuffleItems() {
3517
+ const n6 = this.items.length;
3518
+ const nums = shuffle([...new Array(n6).keys()]);
3519
+ this.innerHTML = nums.map((i4) => this.children.item(i4).outerHTML).join("");
3511
3520
  }
3512
-
3513
- .radio__label {
3514
- display: inline-block;
3515
- color: var(--sl-input-label-color);
3516
- line-height: var(--toggle-size);
3517
- margin-inline-start: 0.5em;
3518
- user-select: none;
3519
- -webkit-user-select: none;
3521
+ handleKeyDown(e7) {
3522
+ if (e7.key == "ArrowDown") {
3523
+ e7.stopPropagation();
3524
+ e7.preventDefault();
3525
+ } else if (e7.key === "ArrowUp") {
3526
+ e7.stopPropagation();
3527
+ e7.preventDefault();
3528
+ }
3520
3529
  }
3521
- `;
3522
-
3523
- // ../../node_modules/@shoelace-style/shoelace/dist/chunks/chunk.QQTW5PZI.js
3524
- var SlRadio = class extends ShoelaceElement {
3525
- constructor() {
3526
- super();
3527
- this.checked = false;
3528
- this.hasFocus = false;
3529
- this.size = "medium";
3530
- this.disabled = false;
3531
- this.handleBlur = () => {
3532
- this.hasFocus = false;
3533
- this.emit("sl-blur");
3534
- };
3535
- this.handleClick = () => {
3536
- if (!this.disabled) {
3537
- this.checked = true;
3538
- }
3539
- };
3540
- this.handleFocus = () => {
3541
- this.hasFocus = true;
3542
- this.emit("sl-focus");
3543
- };
3544
- this.addEventListener("blur", this.handleBlur);
3545
- this.addEventListener("click", this.handleClick);
3546
- this.addEventListener("focus", this.handleFocus);
3530
+ /*
3531
+ If contenteditable: Reorder solution -> Triggers orderSheet change
3532
+ If not contenteditable: Reorder value -> Triggers orderSheet change
3533
+ */
3534
+ moveChild(elem, i4) {
3535
+ if (i4 === 0) {
3536
+ this.insertAdjacentElement("afterbegin", elem);
3537
+ } else if (i4 < this.items.length) {
3538
+ this.items[i4].insertAdjacentElement("beforebegin", elem);
3539
+ } else {
3540
+ this.insertAdjacentElement("beforeend", elem);
3541
+ }
3547
3542
  }
3548
- connectedCallback() {
3549
- super.connectedCallback();
3550
- this.setInitialAttributes();
3543
+ get solution() {
3544
+ return __privateGet(this, _solution)?.length ? __privateGet(this, _solution) : void 0;
3551
3545
  }
3552
- setInitialAttributes() {
3553
- this.setAttribute("role", "radio");
3554
- this.setAttribute("tabindex", "-1");
3555
- this.setAttribute("aria-disabled", this.disabled ? "true" : "false");
3546
+ set solution(value) {
3547
+ __privateSet(this, _solution, value);
3548
+ if (value) {
3549
+ this.dispatchEvent(new CustomEvent("ww-answer-change", {
3550
+ bubbles: true,
3551
+ composed: true
3552
+ }));
3553
+ }
3556
3554
  }
3557
- handleCheckedChange() {
3558
- this.setAttribute("aria-checked", this.checked ? "true" : "false");
3559
- this.setAttribute("tabindex", this.checked ? "0" : "-1");
3555
+ reportSolution() {
3556
+ this.solution.forEach((id, i4) => this.querySelector(`#${id}`).validOrder = i4);
3560
3557
  }
3561
- handleDisabledChange() {
3562
- this.setAttribute("aria-disabled", this.disabled ? "true" : "false");
3558
+ reset() {
3559
+ this.solution = void 0;
3560
+ this.shuffleItems();
3563
3561
  }
3564
3562
  render() {
3565
3563
  return ke`
3566
- <span
3567
- part="base"
3568
- class=${Rt({
3569
- radio: true,
3570
- "radio--checked": this.checked,
3571
- "radio--disabled": this.disabled,
3572
- "radio--focused": this.hasFocus,
3573
- "radio--small": this.size === "small",
3574
- "radio--medium": this.size === "medium",
3575
- "radio--large": this.size === "large"
3576
- })}
3577
- >
3578
- <span part="${`control${this.checked ? " control--checked" : ""}`}" class="radio__control">
3579
- ${this.checked ? ke` <sl-icon part="checked-icon" class="radio__checked-icon" library="system" name="radio"></sl-icon> ` : ""}
3580
- </span>
3581
-
3582
- <slot part="label" class="radio__label"></slot>
3583
- </span>
3564
+ <slot id="items-slot" @webwriter-clear-drop-preview=${this.clearDropPreviews}></slot>
3565
+ <sl-button size="small" id="add-option" class="author-only" @click=${() => this.addItem()}>
3566
+ <sl-icon src=${plus_default}></sl-icon><span>Add Option</span>
3567
+ </sl-button>
3584
3568
  `;
3585
3569
  }
3586
3570
  };
3587
- SlRadio.styles = [component_styles_default, radio_styles_default];
3588
- SlRadio.dependencies = { "sl-icon": SlIcon };
3589
- __decorateClass([
3590
- r5()
3591
- ], SlRadio.prototype, "checked", 2);
3592
- __decorateClass([
3593
- r5()
3594
- ], SlRadio.prototype, "hasFocus", 2);
3595
- __decorateClass([
3596
- n5()
3597
- ], SlRadio.prototype, "value", 2);
3598
- __decorateClass([
3599
- n5({ reflect: true })
3600
- ], SlRadio.prototype, "size", 2);
3601
- __decorateClass([
3602
- n5({ type: Boolean, reflect: true })
3603
- ], SlRadio.prototype, "disabled", 2);
3604
- __decorateClass([
3605
- watch("checked")
3606
- ], SlRadio.prototype, "handleCheckedChange", 1);
3607
- __decorateClass([
3608
- watch("disabled", { waitUntilFirstUpdate: true })
3609
- ], SlRadio.prototype, "handleDisabledChange", 1);
3571
+ _init2 = __decoratorStart(_a2);
3572
+ _itemsSlot = new WeakMap();
3573
+ _items = new WeakMap();
3574
+ _solution = new WeakMap();
3575
+ __decorateElement(_init2, 3, "layout", _layout_dec, WebwriterOrder);
3576
+ __decorateElement(_init2, 3, "hideOrderButtons", _hideOrderButtons_dec, WebwriterOrder);
3577
+ __decorateElement(_init2, 4, "itemsSlot", _itemsSlot_dec, WebwriterOrder, _itemsSlot);
3578
+ __decorateElement(_init2, 4, "items", _items_dec, WebwriterOrder, _items);
3579
+ __decorateElement(_init2, 3, "solution", _solution_dec, WebwriterOrder);
3580
+ WebwriterOrder = __decorateElement(_init2, 0, "WebwriterOrder", _WebwriterOrder_decorators, WebwriterOrder);
3581
+ __publicField(WebwriterOrder, "scopedElements", {
3582
+ "sl-button": SlButton,
3583
+ "sl-icon": SlIcon
3584
+ });
3585
+ __publicField(WebwriterOrder, "styles", i`
3586
+ :host {
3587
+ display: flex !important;
3588
+ flex-direction: column;
3589
+ align-items: flex-start;
3590
+ counter-reset: orderItem;
3591
+ gap: 2px;
3592
+ }
3610
3593
 
3611
- // ../../node_modules/@shoelace-style/shoelace/dist/chunks/chunk.R3NF57O3.js
3612
- var checkbox_styles_default = i`
3613
- :host {
3614
- display: inline-block;
3615
- }
3594
+ :host([layout=tiles]) {
3595
+ flex-direction: row;
3596
+ flex-wrap: wrap;
3597
+ gap: 15px;
3598
+ }
3616
3599
 
3617
- .checkbox {
3618
- position: relative;
3619
- display: inline-flex;
3620
- align-items: flex-start;
3621
- font-family: var(--sl-input-font-family);
3622
- font-weight: var(--sl-input-font-weight);
3623
- color: var(--sl-input-label-color);
3624
- vertical-align: middle;
3625
- cursor: pointer;
3626
- }
3627
-
3628
- .checkbox--small {
3629
- --toggle-size: var(--sl-toggle-size-small);
3630
- font-size: var(--sl-input-font-size-small);
3631
- }
3632
-
3633
- .checkbox--medium {
3634
- --toggle-size: var(--sl-toggle-size-medium);
3635
- font-size: var(--sl-input-font-size-medium);
3636
- }
3637
-
3638
- .checkbox--large {
3639
- --toggle-size: var(--sl-toggle-size-large);
3640
- font-size: var(--sl-input-font-size-large);
3641
- }
3642
-
3643
- .checkbox__control {
3644
- flex: 0 0 auto;
3645
- position: relative;
3646
- display: inline-flex;
3647
- align-items: center;
3648
- justify-content: center;
3649
- width: var(--toggle-size);
3650
- height: var(--toggle-size);
3651
- border: solid var(--sl-input-border-width) var(--sl-input-border-color);
3652
- border-radius: 2px;
3653
- background-color: var(--sl-input-background-color);
3654
- color: var(--sl-color-neutral-0);
3655
- transition:
3656
- var(--sl-transition-fast) border-color,
3657
- var(--sl-transition-fast) background-color,
3658
- var(--sl-transition-fast) color,
3659
- var(--sl-transition-fast) box-shadow;
3660
- }
3661
-
3662
- .checkbox__input {
3663
- position: absolute;
3664
- opacity: 0;
3665
- padding: 0;
3666
- margin: 0;
3667
- pointer-events: none;
3668
- }
3669
-
3670
- .checkbox__checked-icon,
3671
- .checkbox__indeterminate-icon {
3672
- display: inline-flex;
3673
- width: var(--toggle-size);
3674
- height: var(--toggle-size);
3675
- }
3676
-
3677
- /* Hover */
3678
- .checkbox:not(.checkbox--checked):not(.checkbox--disabled) .checkbox__control:hover {
3679
- border-color: var(--sl-input-border-color-hover);
3680
- background-color: var(--sl-input-background-color-hover);
3681
- }
3682
-
3683
- /* Focus */
3684
- .checkbox:not(.checkbox--checked):not(.checkbox--disabled) .checkbox__input:focus-visible ~ .checkbox__control {
3685
- outline: var(--sl-focus-ring);
3686
- outline-offset: var(--sl-focus-ring-offset);
3687
- }
3688
-
3689
- /* Checked/indeterminate */
3690
- .checkbox--checked .checkbox__control,
3691
- .checkbox--indeterminate .checkbox__control {
3692
- border-color: var(--sl-color-primary-600);
3693
- background-color: var(--sl-color-primary-600);
3694
- }
3695
-
3696
- /* Checked/indeterminate + hover */
3697
- .checkbox.checkbox--checked:not(.checkbox--disabled) .checkbox__control:hover,
3698
- .checkbox.checkbox--indeterminate:not(.checkbox--disabled) .checkbox__control:hover {
3699
- border-color: var(--sl-color-primary-500);
3700
- background-color: var(--sl-color-primary-500);
3701
- }
3702
-
3703
- /* Checked/indeterminate + focus */
3704
- .checkbox.checkbox--checked:not(.checkbox--disabled) .checkbox__input:focus-visible ~ .checkbox__control,
3705
- .checkbox.checkbox--indeterminate:not(.checkbox--disabled) .checkbox__input:focus-visible ~ .checkbox__control {
3706
- outline: var(--sl-focus-ring);
3707
- outline-offset: var(--sl-focus-ring-offset);
3708
- }
3709
-
3710
- /* Disabled */
3711
- .checkbox--disabled {
3712
- opacity: 0.5;
3713
- cursor: not-allowed;
3714
- }
3715
-
3716
- .checkbox__label {
3717
- display: inline-block;
3718
- color: var(--sl-input-label-color);
3719
- line-height: var(--toggle-size);
3720
- margin-inline-start: 0.5em;
3721
- user-select: none;
3722
- -webkit-user-select: none;
3723
- }
3724
-
3725
- :host([required]) .checkbox__label::after {
3726
- content: var(--sl-input-required-content);
3727
- color: var(--sl-input-required-content-color);
3728
- margin-inline-start: var(--sl-input-required-content-offset);
3729
- }
3730
- `;
3731
-
3732
- // ../../node_modules/@shoelace-style/shoelace/dist/chunks/chunk.GI7VDIWX.js
3733
- var defaultValue = (propertyName = "value") => (proto, key) => {
3734
- const ctor = proto.constructor;
3735
- const attributeChangedCallback = ctor.prototype.attributeChangedCallback;
3736
- ctor.prototype.attributeChangedCallback = function(name, old, value) {
3737
- var _a4;
3738
- const options = ctor.getPropertyOptions(propertyName);
3739
- const attributeName = typeof options.attribute === "string" ? options.attribute : propertyName;
3740
- if (name === attributeName) {
3741
- const converter = options.converter || u;
3742
- const fromAttribute = typeof converter === "function" ? converter : (_a4 = converter == null ? void 0 : converter.fromAttribute) != null ? _a4 : u.fromAttribute;
3743
- const newValue = fromAttribute(value, options.type);
3744
- if (this[propertyName] !== newValue) {
3745
- this[key] = newValue;
3746
- }
3747
- }
3748
- attributeChangedCallback.call(this, name, old, value);
3749
- };
3750
- };
3751
-
3752
- // ../../node_modules/@shoelace-style/shoelace/dist/chunks/chunk.SI4ACBFK.js
3753
- var form_control_styles_default = i`
3754
- .form-control .form-control__label {
3755
- display: none;
3756
- }
3757
-
3758
- .form-control .form-control__help-text {
3759
- display: none;
3760
- }
3761
-
3762
- /* Label */
3763
- .form-control--has-label .form-control__label {
3764
- display: inline-block;
3765
- color: var(--sl-input-label-color);
3766
- margin-bottom: var(--sl-spacing-3x-small);
3767
- }
3768
-
3769
- .form-control--has-label.form-control--small .form-control__label {
3770
- font-size: var(--sl-input-label-font-size-small);
3771
- }
3772
-
3773
- .form-control--has-label.form-control--medium .form-control__label {
3774
- font-size: var(--sl-input-label-font-size-medium);
3775
- }
3776
-
3777
- .form-control--has-label.form-control--large .form-control__label {
3778
- font-size: var(--sl-input-label-font-size-large);
3779
- }
3780
-
3781
- :host([required]) .form-control--has-label .form-control__label::after {
3782
- content: var(--sl-input-required-content);
3783
- margin-inline-start: var(--sl-input-required-content-offset);
3784
- color: var(--sl-input-required-content-color);
3785
- }
3786
-
3787
- /* Help text */
3788
- .form-control--has-help-text .form-control__help-text {
3789
- display: block;
3790
- color: var(--sl-input-help-text-color);
3791
- margin-top: var(--sl-spacing-3x-small);
3792
- }
3793
-
3794
- .form-control--has-help-text.form-control--small .form-control__help-text {
3795
- font-size: var(--sl-input-help-text-font-size-small);
3796
- }
3797
-
3798
- .form-control--has-help-text.form-control--medium .form-control__help-text {
3799
- font-size: var(--sl-input-help-text-font-size-medium);
3800
- }
3801
-
3802
- .form-control--has-help-text.form-control--large .form-control__help-text {
3803
- font-size: var(--sl-input-help-text-font-size-large);
3804
- }
3805
-
3806
- .form-control--has-help-text.form-control--radio-group .form-control__help-text {
3807
- margin-top: var(--sl-spacing-2x-small);
3808
- }
3809
- `;
3810
-
3811
- // ../../node_modules/lit/node_modules/lit-html/directives/live.js
3812
- var Ft = e6(class extends i3 {
3813
- constructor(r6) {
3814
- if (super(r6), r6.type !== t4.PROPERTY && r6.type !== t4.ATTRIBUTE && r6.type !== t4.BOOLEAN_ATTRIBUTE) throw Error("The `live` directive is not allowed on child or event bindings");
3815
- if (!rt(r6)) throw Error("`live` bindings can only contain a single expression");
3816
- }
3817
- render(r6) {
3818
- return r6;
3819
- }
3820
- update(r6, [e7]) {
3821
- if (e7 === R || e7 === D) return e7;
3822
- const i4 = r6.element, n6 = r6.name;
3823
- if (r6.type === t4.PROPERTY) {
3824
- if (e7 === i4[n6]) return R;
3825
- } else if (r6.type === t4.BOOLEAN_ATTRIBUTE) {
3826
- if (!!e7 === i4.hasAttribute(n6)) return R;
3827
- } else if (r6.type === t4.ATTRIBUTE && i4.getAttribute(n6) === e7 + "") return R;
3828
- return dt(r6), e7;
3829
- }
3830
- });
3831
-
3832
- // ../../node_modules/@shoelace-style/shoelace/dist/chunks/chunk.6GAVHIFH.js
3833
- var SlCheckbox = class extends ShoelaceElement {
3834
- constructor() {
3835
- super(...arguments);
3836
- this.formControlController = new FormControlController(this, {
3837
- value: (control) => control.checked ? control.value || "on" : void 0,
3838
- defaultValue: (control) => control.defaultChecked,
3839
- setValue: (control, checked) => control.checked = checked
3840
- });
3841
- this.hasSlotController = new HasSlotController(this, "help-text");
3842
- this.hasFocus = false;
3843
- this.title = "";
3844
- this.name = "";
3845
- this.size = "medium";
3846
- this.disabled = false;
3847
- this.checked = false;
3848
- this.indeterminate = false;
3849
- this.defaultChecked = false;
3850
- this.form = "";
3851
- this.required = false;
3852
- this.helpText = "";
3853
- }
3854
- /** Gets the validity state object */
3855
- get validity() {
3856
- return this.input.validity;
3857
- }
3858
- /** Gets the validation message */
3859
- get validationMessage() {
3860
- return this.input.validationMessage;
3861
- }
3862
- firstUpdated() {
3863
- this.formControlController.updateValidity();
3864
- }
3865
- handleClick() {
3866
- this.checked = !this.checked;
3867
- this.indeterminate = false;
3868
- this.emit("sl-change");
3869
- }
3870
- handleBlur() {
3871
- this.hasFocus = false;
3872
- this.emit("sl-blur");
3873
- }
3874
- handleInput() {
3875
- this.emit("sl-input");
3876
- }
3877
- handleInvalid(event) {
3878
- this.formControlController.setValidity(false);
3879
- this.formControlController.emitInvalidEvent(event);
3880
- }
3881
- handleFocus() {
3882
- this.hasFocus = true;
3883
- this.emit("sl-focus");
3884
- }
3885
- handleDisabledChange() {
3886
- this.formControlController.setValidity(this.disabled);
3887
- }
3888
- handleStateChange() {
3889
- this.input.checked = this.checked;
3890
- this.input.indeterminate = this.indeterminate;
3891
- this.formControlController.updateValidity();
3892
- }
3893
- /** Simulates a click on the checkbox. */
3894
- click() {
3895
- this.input.click();
3896
- }
3897
- /** Sets focus on the checkbox. */
3898
- focus(options) {
3899
- this.input.focus(options);
3900
- }
3901
- /** Removes focus from the checkbox. */
3902
- blur() {
3903
- this.input.blur();
3904
- }
3905
- /** Checks for validity but does not show a validation message. Returns `true` when valid and `false` when invalid. */
3906
- checkValidity() {
3907
- return this.input.checkValidity();
3908
- }
3909
- /** Gets the associated form, if one exists. */
3910
- getForm() {
3911
- return this.formControlController.getForm();
3912
- }
3913
- /** Checks for validity and shows the browser's validation message if the control is invalid. */
3914
- reportValidity() {
3915
- return this.input.reportValidity();
3916
- }
3917
- /**
3918
- * Sets a custom validation message. The value provided will be shown to the user when the form is submitted. To clear
3919
- * the custom validation message, call this method with an empty string.
3920
- */
3921
- setCustomValidity(message) {
3922
- this.input.setCustomValidity(message);
3923
- this.formControlController.updateValidity();
3924
- }
3925
- render() {
3926
- const hasHelpTextSlot = this.hasSlotController.test("help-text");
3927
- const hasHelpText = this.helpText ? true : !!hasHelpTextSlot;
3928
- return ke`
3929
- <div
3930
- class=${Rt({
3931
- "form-control": true,
3932
- "form-control--small": this.size === "small",
3933
- "form-control--medium": this.size === "medium",
3934
- "form-control--large": this.size === "large",
3935
- "form-control--has-help-text": hasHelpText
3936
- })}
3937
- >
3938
- <label
3939
- part="base"
3940
- class=${Rt({
3941
- checkbox: true,
3942
- "checkbox--checked": this.checked,
3943
- "checkbox--disabled": this.disabled,
3944
- "checkbox--focused": this.hasFocus,
3945
- "checkbox--indeterminate": this.indeterminate,
3946
- "checkbox--small": this.size === "small",
3947
- "checkbox--medium": this.size === "medium",
3948
- "checkbox--large": this.size === "large"
3949
- })}
3950
- >
3951
- <input
3952
- class="checkbox__input"
3953
- type="checkbox"
3954
- title=${this.title}
3955
- name=${this.name}
3956
- value=${to(this.value)}
3957
- .indeterminate=${Ft(this.indeterminate)}
3958
- .checked=${Ft(this.checked)}
3959
- .disabled=${this.disabled}
3960
- .required=${this.required}
3961
- aria-checked=${this.checked ? "true" : "false"}
3962
- aria-describedby="help-text"
3963
- @click=${this.handleClick}
3964
- @input=${this.handleInput}
3965
- @invalid=${this.handleInvalid}
3966
- @blur=${this.handleBlur}
3967
- @focus=${this.handleFocus}
3968
- />
3969
-
3970
- <span
3971
- part="control${this.checked ? " control--checked" : ""}${this.indeterminate ? " control--indeterminate" : ""}"
3972
- class="checkbox__control"
3973
- >
3974
- ${this.checked ? ke`
3975
- <sl-icon part="checked-icon" class="checkbox__checked-icon" library="system" name="check"></sl-icon>
3976
- ` : ""}
3977
- ${!this.checked && this.indeterminate ? ke`
3978
- <sl-icon
3979
- part="indeterminate-icon"
3980
- class="checkbox__indeterminate-icon"
3981
- library="system"
3982
- name="indeterminate"
3983
- ></sl-icon>
3984
- ` : ""}
3985
- </span>
3986
-
3987
- <div part="label" class="checkbox__label">
3988
- <slot></slot>
3989
- </div>
3990
- </label>
3991
-
3992
- <div
3993
- aria-hidden=${hasHelpText ? "false" : "true"}
3994
- class="form-control__help-text"
3995
- id="help-text"
3996
- part="form-control-help-text"
3997
- >
3998
- <slot name="help-text">${this.helpText}</slot>
3999
- </div>
4000
- </div>
4001
- `;
4002
- }
4003
- };
4004
- SlCheckbox.styles = [component_styles_default, form_control_styles_default, checkbox_styles_default];
4005
- SlCheckbox.dependencies = { "sl-icon": SlIcon };
4006
- __decorateClass([
4007
- e5('input[type="checkbox"]')
4008
- ], SlCheckbox.prototype, "input", 2);
4009
- __decorateClass([
4010
- r5()
4011
- ], SlCheckbox.prototype, "hasFocus", 2);
4012
- __decorateClass([
4013
- n5()
4014
- ], SlCheckbox.prototype, "title", 2);
4015
- __decorateClass([
4016
- n5()
4017
- ], SlCheckbox.prototype, "name", 2);
4018
- __decorateClass([
4019
- n5()
4020
- ], SlCheckbox.prototype, "value", 2);
4021
- __decorateClass([
4022
- n5({ reflect: true })
4023
- ], SlCheckbox.prototype, "size", 2);
4024
- __decorateClass([
4025
- n5({ type: Boolean, reflect: true })
4026
- ], SlCheckbox.prototype, "disabled", 2);
4027
- __decorateClass([
4028
- n5({ type: Boolean, reflect: true })
4029
- ], SlCheckbox.prototype, "checked", 2);
4030
- __decorateClass([
4031
- n5({ type: Boolean, reflect: true })
4032
- ], SlCheckbox.prototype, "indeterminate", 2);
4033
- __decorateClass([
4034
- defaultValue("checked")
4035
- ], SlCheckbox.prototype, "defaultChecked", 2);
4036
- __decorateClass([
4037
- n5({ reflect: true })
4038
- ], SlCheckbox.prototype, "form", 2);
4039
- __decorateClass([
4040
- n5({ type: Boolean, reflect: true })
4041
- ], SlCheckbox.prototype, "required", 2);
4042
- __decorateClass([
4043
- n5({ attribute: "help-text" })
4044
- ], SlCheckbox.prototype, "helpText", 2);
4045
- __decorateClass([
4046
- watch("disabled", { waitUntilFirstUpdate: true })
4047
- ], SlCheckbox.prototype, "handleDisabledChange", 1);
4048
- __decorateClass([
4049
- watch(["checked", "indeterminate"], { waitUntilFirstUpdate: true })
4050
- ], SlCheckbox.prototype, "handleStateChange", 1);
4051
-
4052
- // ../../node_modules/@shoelace-style/shoelace/dist/chunks/chunk.2P5EQCYK.js
4053
- var radio_button_styles_default = i`
4054
- ${button_styles_default}
4055
-
4056
- .button__prefix,
4057
- .button__suffix,
4058
- .button__label {
4059
- display: inline-flex;
4060
- position: relative;
4061
- align-items: center;
4062
- }
4063
-
4064
- /* We use a hidden input so constraint validation errors work, since they don't appear to show when used with buttons.
4065
- We can't actually hide it, though, otherwise the messages will be suppressed by the browser. */
4066
- .hidden-input {
4067
- all: unset;
4068
- position: absolute;
4069
- top: 0;
4070
- left: 0;
4071
- bottom: 0;
4072
- right: 0;
4073
- outline: dotted 1px red;
4074
- opacity: 0;
4075
- z-index: -1;
4076
- }
4077
- `;
4078
-
4079
- // ../../node_modules/@shoelace-style/shoelace/dist/chunks/chunk.2VQCGLC7.js
4080
- var SlRadioButton = class extends ShoelaceElement {
4081
- constructor() {
4082
- super(...arguments);
4083
- this.hasSlotController = new HasSlotController(this, "[default]", "prefix", "suffix");
4084
- this.hasFocus = false;
4085
- this.checked = false;
4086
- this.disabled = false;
4087
- this.size = "medium";
4088
- this.pill = false;
4089
- }
4090
- connectedCallback() {
4091
- super.connectedCallback();
4092
- this.setAttribute("role", "presentation");
4093
- }
4094
- handleBlur() {
4095
- this.hasFocus = false;
4096
- this.emit("sl-blur");
4097
- }
4098
- handleClick(e7) {
4099
- if (this.disabled) {
4100
- e7.preventDefault();
4101
- e7.stopPropagation();
4102
- return;
4103
- }
4104
- this.checked = true;
4105
- }
4106
- handleFocus() {
4107
- this.hasFocus = true;
4108
- this.emit("sl-focus");
4109
- }
4110
- handleDisabledChange() {
4111
- this.setAttribute("aria-disabled", this.disabled ? "true" : "false");
4112
- }
4113
- /** Sets focus on the radio button. */
4114
- focus(options) {
4115
- this.input.focus(options);
4116
- }
4117
- /** Removes focus from the radio button. */
4118
- blur() {
4119
- this.input.blur();
4120
- }
4121
- render() {
4122
- return ke3`
4123
- <div part="base" role="presentation">
4124
- <button
4125
- part="${`button${this.checked ? " button--checked" : ""}`}"
4126
- role="radio"
4127
- aria-checked="${this.checked}"
4128
- class=${Rt({
4129
- button: true,
4130
- "button--default": true,
4131
- "button--small": this.size === "small",
4132
- "button--medium": this.size === "medium",
4133
- "button--large": this.size === "large",
4134
- "button--checked": this.checked,
4135
- "button--disabled": this.disabled,
4136
- "button--focused": this.hasFocus,
4137
- "button--outline": true,
4138
- "button--pill": this.pill,
4139
- "button--has-label": this.hasSlotController.test("[default]"),
4140
- "button--has-prefix": this.hasSlotController.test("prefix"),
4141
- "button--has-suffix": this.hasSlotController.test("suffix")
4142
- })}
4143
- aria-disabled=${this.disabled}
4144
- type="button"
4145
- value=${to(this.value)}
4146
- @blur=${this.handleBlur}
4147
- @focus=${this.handleFocus}
4148
- @click=${this.handleClick}
4149
- >
4150
- <slot name="prefix" part="prefix" class="button__prefix"></slot>
4151
- <slot part="label" class="button__label"></slot>
4152
- <slot name="suffix" part="suffix" class="button__suffix"></slot>
4153
- </button>
4154
- </div>
4155
- `;
4156
- }
4157
- };
4158
- SlRadioButton.styles = [component_styles_default, radio_button_styles_default];
4159
- __decorateClass([
4160
- e5(".button")
4161
- ], SlRadioButton.prototype, "input", 2);
4162
- __decorateClass([
4163
- e5(".hidden-input")
4164
- ], SlRadioButton.prototype, "hiddenInput", 2);
4165
- __decorateClass([
4166
- r5()
4167
- ], SlRadioButton.prototype, "hasFocus", 2);
4168
- __decorateClass([
4169
- n5({ type: Boolean, reflect: true })
4170
- ], SlRadioButton.prototype, "checked", 2);
4171
- __decorateClass([
4172
- n5()
4173
- ], SlRadioButton.prototype, "value", 2);
4174
- __decorateClass([
4175
- n5({ type: Boolean, reflect: true })
4176
- ], SlRadioButton.prototype, "disabled", 2);
4177
- __decorateClass([
4178
- n5({ reflect: true })
4179
- ], SlRadioButton.prototype, "size", 2);
4180
- __decorateClass([
4181
- n5({ type: Boolean, reflect: true })
4182
- ], SlRadioButton.prototype, "pill", 2);
4183
- __decorateClass([
4184
- watch("disabled", { waitUntilFirstUpdate: true })
4185
- ], SlRadioButton.prototype, "handleDisabledChange", 1);
4186
-
4187
- // ../../node_modules/@shoelace-style/shoelace/dist/chunks/chunk.B63YXDJO.js
4188
- var radio_group_styles_default = i`
4189
- :host {
4190
- display: block;
4191
- }
4192
-
4193
- .form-control {
4194
- position: relative;
4195
- border: none;
4196
- padding: 0;
4197
- margin: 0;
4198
- }
4199
-
4200
- .form-control__label {
4201
- padding: 0;
4202
- }
4203
-
4204
- .radio-group--required .radio-group__label::after {
4205
- content: var(--sl-input-required-content);
4206
- margin-inline-start: var(--sl-input-required-content-offset);
4207
- }
4208
-
4209
- .visually-hidden {
4210
- position: absolute;
4211
- width: 1px;
4212
- height: 1px;
4213
- padding: 0;
4214
- margin: -1px;
4215
- overflow: hidden;
4216
- clip: rect(0, 0, 0, 0);
4217
- white-space: nowrap;
4218
- border: 0;
4219
- }
4220
- `;
4221
-
4222
- // ../../node_modules/@shoelace-style/shoelace/dist/chunks/chunk.2OUC42YY.js
4223
- var button_group_styles_default = i`
4224
- :host {
4225
- display: inline-block;
4226
- }
4227
-
4228
- .button-group {
4229
- display: flex;
4230
- flex-wrap: nowrap;
4231
- }
4232
- `;
4233
-
4234
- // ../../node_modules/@shoelace-style/shoelace/dist/chunks/chunk.AKN2SAUH.js
4235
- var SlButtonGroup = class extends ShoelaceElement {
4236
- constructor() {
4237
- super(...arguments);
4238
- this.disableRole = false;
4239
- this.label = "";
4240
- }
4241
- handleFocus(event) {
4242
- const button = findButton(event.target);
4243
- button == null ? void 0 : button.toggleAttribute("data-sl-button-group__button--focus", true);
4244
- }
4245
- handleBlur(event) {
4246
- const button = findButton(event.target);
4247
- button == null ? void 0 : button.toggleAttribute("data-sl-button-group__button--focus", false);
4248
- }
4249
- handleMouseOver(event) {
4250
- const button = findButton(event.target);
4251
- button == null ? void 0 : button.toggleAttribute("data-sl-button-group__button--hover", true);
4252
- }
4253
- handleMouseOut(event) {
4254
- const button = findButton(event.target);
4255
- button == null ? void 0 : button.toggleAttribute("data-sl-button-group__button--hover", false);
4256
- }
4257
- handleSlotChange() {
4258
- const slottedElements = [...this.defaultSlot.assignedElements({ flatten: true })];
4259
- slottedElements.forEach((el) => {
4260
- const index = slottedElements.indexOf(el);
4261
- const button = findButton(el);
4262
- if (button) {
4263
- button.toggleAttribute("data-sl-button-group__button", true);
4264
- button.toggleAttribute("data-sl-button-group__button--first", index === 0);
4265
- button.toggleAttribute("data-sl-button-group__button--inner", index > 0 && index < slottedElements.length - 1);
4266
- button.toggleAttribute("data-sl-button-group__button--last", index === slottedElements.length - 1);
4267
- button.toggleAttribute(
4268
- "data-sl-button-group__button--radio",
4269
- button.tagName.toLowerCase() === "sl-radio-button"
4270
- );
4271
- }
4272
- });
4273
- }
4274
- render() {
4275
- return ke`
4276
- <div
4277
- part="base"
4278
- class="button-group"
4279
- role="${this.disableRole ? "presentation" : "group"}"
4280
- aria-label=${this.label}
4281
- @focusout=${this.handleBlur}
4282
- @focusin=${this.handleFocus}
4283
- @mouseover=${this.handleMouseOver}
4284
- @mouseout=${this.handleMouseOut}
4285
- >
4286
- <slot @slotchange=${this.handleSlotChange}></slot>
4287
- </div>
4288
- `;
4289
- }
4290
- };
4291
- SlButtonGroup.styles = [component_styles_default, button_group_styles_default];
4292
- __decorateClass([
4293
- e5("slot")
4294
- ], SlButtonGroup.prototype, "defaultSlot", 2);
4295
- __decorateClass([
4296
- r5()
4297
- ], SlButtonGroup.prototype, "disableRole", 2);
4298
- __decorateClass([
4299
- n5()
4300
- ], SlButtonGroup.prototype, "label", 2);
4301
- function findButton(el) {
4302
- var _a4;
4303
- const selector = "sl-button, sl-radio-button";
4304
- return (_a4 = el.closest(selector)) != null ? _a4 : el.querySelector(selector);
4305
- }
4306
-
4307
- // ../../node_modules/@shoelace-style/shoelace/dist/chunks/chunk.TSKLKQOV.js
4308
- var SlRadioGroup = class extends ShoelaceElement {
4309
- constructor() {
4310
- super(...arguments);
4311
- this.formControlController = new FormControlController(this);
4312
- this.hasSlotController = new HasSlotController(this, "help-text", "label");
4313
- this.customValidityMessage = "";
4314
- this.hasButtonGroup = false;
4315
- this.errorMessage = "";
4316
- this.defaultValue = "";
4317
- this.label = "";
4318
- this.helpText = "";
4319
- this.name = "option";
4320
- this.value = "";
4321
- this.size = "medium";
4322
- this.form = "";
4323
- this.required = false;
4324
- }
4325
- /** Gets the validity state object */
4326
- get validity() {
4327
- const isRequiredAndEmpty = this.required && !this.value;
4328
- const hasCustomValidityMessage = this.customValidityMessage !== "";
4329
- if (hasCustomValidityMessage) {
4330
- return customErrorValidityState;
4331
- } else if (isRequiredAndEmpty) {
4332
- return valueMissingValidityState;
4333
- }
4334
- return validValidityState;
4335
- }
4336
- /** Gets the validation message */
4337
- get validationMessage() {
4338
- const isRequiredAndEmpty = this.required && !this.value;
4339
- const hasCustomValidityMessage = this.customValidityMessage !== "";
4340
- if (hasCustomValidityMessage) {
4341
- return this.customValidityMessage;
4342
- } else if (isRequiredAndEmpty) {
4343
- return this.validationInput.validationMessage;
4344
- }
4345
- return "";
4346
- }
4347
- connectedCallback() {
4348
- super.connectedCallback();
4349
- this.defaultValue = this.value;
4350
- }
4351
- firstUpdated() {
4352
- this.formControlController.updateValidity();
4353
- }
4354
- getAllRadios() {
4355
- return [...this.querySelectorAll("sl-radio, sl-radio-button")];
4356
- }
4357
- handleRadioClick(event) {
4358
- const target = event.target.closest("sl-radio, sl-radio-button");
4359
- const radios = this.getAllRadios();
4360
- const oldValue = this.value;
4361
- if (!target || target.disabled) {
4362
- return;
4363
- }
4364
- this.value = target.value;
4365
- radios.forEach((radio) => radio.checked = radio === target);
4366
- if (this.value !== oldValue) {
4367
- this.emit("sl-change");
4368
- this.emit("sl-input");
4369
- }
4370
- }
4371
- handleKeyDown(event) {
4372
- var _a4;
4373
- if (!["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight", " "].includes(event.key)) {
4374
- return;
4375
- }
4376
- const radios = this.getAllRadios().filter((radio) => !radio.disabled);
4377
- const checkedRadio = (_a4 = radios.find((radio) => radio.checked)) != null ? _a4 : radios[0];
4378
- const incr = event.key === " " ? 0 : ["ArrowUp", "ArrowLeft"].includes(event.key) ? -1 : 1;
4379
- const oldValue = this.value;
4380
- let index = radios.indexOf(checkedRadio) + incr;
4381
- if (index < 0) {
4382
- index = radios.length - 1;
4383
- }
4384
- if (index > radios.length - 1) {
4385
- index = 0;
4386
- }
4387
- this.getAllRadios().forEach((radio) => {
4388
- radio.checked = false;
4389
- if (!this.hasButtonGroup) {
4390
- radio.setAttribute("tabindex", "-1");
4391
- }
4392
- });
4393
- this.value = radios[index].value;
4394
- radios[index].checked = true;
4395
- if (!this.hasButtonGroup) {
4396
- radios[index].setAttribute("tabindex", "0");
4397
- radios[index].focus();
4398
- } else {
4399
- radios[index].shadowRoot.querySelector("button").focus();
4400
- }
4401
- if (this.value !== oldValue) {
4402
- this.emit("sl-change");
4403
- this.emit("sl-input");
4404
- }
4405
- event.preventDefault();
4406
- }
4407
- handleLabelClick() {
4408
- const radios = this.getAllRadios();
4409
- const checked = radios.find((radio) => radio.checked);
4410
- const radioToFocus = checked || radios[0];
4411
- if (radioToFocus) {
4412
- radioToFocus.focus();
4413
- }
4414
- }
4415
- handleInvalid(event) {
4416
- this.formControlController.setValidity(false);
4417
- this.formControlController.emitInvalidEvent(event);
4418
- }
4419
- async syncRadioElements() {
4420
- var _a4, _b;
4421
- const radios = this.getAllRadios();
4422
- await Promise.all(
4423
- // Sync the checked state and size
4424
- radios.map(async (radio) => {
4425
- await radio.updateComplete;
4426
- radio.checked = radio.value === this.value;
4427
- radio.size = this.size;
4428
- })
4429
- );
4430
- this.hasButtonGroup = radios.some((radio) => radio.tagName.toLowerCase() === "sl-radio-button");
4431
- if (radios.length > 0 && !radios.some((radio) => radio.checked)) {
4432
- if (this.hasButtonGroup) {
4433
- const buttonRadio = (_a4 = radios[0].shadowRoot) == null ? void 0 : _a4.querySelector("button");
4434
- if (buttonRadio) {
4435
- buttonRadio.setAttribute("tabindex", "0");
4436
- }
4437
- } else {
4438
- radios[0].setAttribute("tabindex", "0");
4439
- }
4440
- }
4441
- if (this.hasButtonGroup) {
4442
- const buttonGroup = (_b = this.shadowRoot) == null ? void 0 : _b.querySelector("sl-button-group");
4443
- if (buttonGroup) {
4444
- buttonGroup.disableRole = true;
4445
- }
4446
- }
4447
- }
4448
- syncRadios() {
4449
- if (customElements.get("sl-radio") && customElements.get("sl-radio-button")) {
4450
- this.syncRadioElements();
4451
- return;
4452
- }
4453
- if (customElements.get("sl-radio")) {
4454
- this.syncRadioElements();
4455
- } else {
4456
- customElements.whenDefined("sl-radio").then(() => this.syncRadios());
4457
- }
4458
- if (customElements.get("sl-radio-button")) {
4459
- this.syncRadioElements();
4460
- } else {
4461
- customElements.whenDefined("sl-radio-button").then(() => this.syncRadios());
4462
- }
4463
- }
4464
- updateCheckedRadio() {
4465
- const radios = this.getAllRadios();
4466
- radios.forEach((radio) => radio.checked = radio.value === this.value);
4467
- this.formControlController.setValidity(this.validity.valid);
4468
- }
4469
- handleSizeChange() {
4470
- this.syncRadios();
4471
- }
4472
- handleValueChange() {
4473
- if (this.hasUpdated) {
4474
- this.updateCheckedRadio();
4475
- }
4476
- }
4477
- /** Checks for validity but does not show a validation message. Returns `true` when valid and `false` when invalid. */
4478
- checkValidity() {
4479
- const isRequiredAndEmpty = this.required && !this.value;
4480
- const hasCustomValidityMessage = this.customValidityMessage !== "";
4481
- if (isRequiredAndEmpty || hasCustomValidityMessage) {
4482
- this.formControlController.emitInvalidEvent();
4483
- return false;
4484
- }
4485
- return true;
4486
- }
4487
- /** Gets the associated form, if one exists. */
4488
- getForm() {
4489
- return this.formControlController.getForm();
4490
- }
4491
- /** Checks for validity and shows the browser's validation message if the control is invalid. */
4492
- reportValidity() {
4493
- const isValid = this.validity.valid;
4494
- this.errorMessage = this.customValidityMessage || isValid ? "" : this.validationInput.validationMessage;
4495
- this.formControlController.setValidity(isValid);
4496
- this.validationInput.hidden = true;
4497
- clearTimeout(this.validationTimeout);
4498
- if (!isValid) {
4499
- this.validationInput.hidden = false;
4500
- this.validationInput.reportValidity();
4501
- this.validationTimeout = setTimeout(() => this.validationInput.hidden = true, 1e4);
4502
- }
4503
- return isValid;
4504
- }
4505
- /** Sets a custom validation message. Pass an empty string to restore validity. */
4506
- setCustomValidity(message = "") {
4507
- this.customValidityMessage = message;
4508
- this.errorMessage = message;
4509
- this.validationInput.setCustomValidity(message);
4510
- this.formControlController.updateValidity();
4511
- }
4512
- render() {
4513
- const hasLabelSlot = this.hasSlotController.test("label");
4514
- const hasHelpTextSlot = this.hasSlotController.test("help-text");
4515
- const hasLabel = this.label ? true : !!hasLabelSlot;
4516
- const hasHelpText = this.helpText ? true : !!hasHelpTextSlot;
4517
- const defaultSlot = ke`
4518
- <slot @slotchange=${this.syncRadios} @click=${this.handleRadioClick} @keydown=${this.handleKeyDown}></slot>
4519
- `;
4520
- return ke`
4521
- <fieldset
4522
- part="form-control"
4523
- class=${Rt({
4524
- "form-control": true,
4525
- "form-control--small": this.size === "small",
4526
- "form-control--medium": this.size === "medium",
4527
- "form-control--large": this.size === "large",
4528
- "form-control--radio-group": true,
4529
- "form-control--has-label": hasLabel,
4530
- "form-control--has-help-text": hasHelpText
4531
- })}
4532
- role="radiogroup"
4533
- aria-labelledby="label"
4534
- aria-describedby="help-text"
4535
- aria-errormessage="error-message"
4536
- >
4537
- <label
4538
- part="form-control-label"
4539
- id="label"
4540
- class="form-control__label"
4541
- aria-hidden=${hasLabel ? "false" : "true"}
4542
- @click=${this.handleLabelClick}
4543
- >
4544
- <slot name="label">${this.label}</slot>
4545
- </label>
4546
-
4547
- <div part="form-control-input" class="form-control-input">
4548
- <div class="visually-hidden">
4549
- <div id="error-message" aria-live="assertive">${this.errorMessage}</div>
4550
- <label class="radio-group__validation">
4551
- <input
4552
- type="text"
4553
- class="radio-group__validation-input"
4554
- ?required=${this.required}
4555
- tabindex="-1"
4556
- hidden
4557
- @invalid=${this.handleInvalid}
4558
- />
4559
- </label>
4560
- </div>
4561
-
4562
- ${this.hasButtonGroup ? ke`
4563
- <sl-button-group part="button-group" exportparts="base:button-group__base" role="presentation">
4564
- ${defaultSlot}
4565
- </sl-button-group>
4566
- ` : defaultSlot}
4567
- </div>
4568
-
4569
- <div
4570
- part="form-control-help-text"
4571
- id="help-text"
4572
- class="form-control__help-text"
4573
- aria-hidden=${hasHelpText ? "false" : "true"}
4574
- >
4575
- <slot name="help-text">${this.helpText}</slot>
4576
- </div>
4577
- </fieldset>
4578
- `;
4579
- }
4580
- };
4581
- SlRadioGroup.styles = [component_styles_default, form_control_styles_default, radio_group_styles_default];
4582
- SlRadioGroup.dependencies = { "sl-button-group": SlButtonGroup };
4583
- __decorateClass([
4584
- e5("slot:not([name])")
4585
- ], SlRadioGroup.prototype, "defaultSlot", 2);
4586
- __decorateClass([
4587
- e5(".radio-group__validation-input")
4588
- ], SlRadioGroup.prototype, "validationInput", 2);
4589
- __decorateClass([
4590
- r5()
4591
- ], SlRadioGroup.prototype, "hasButtonGroup", 2);
4592
- __decorateClass([
4593
- r5()
4594
- ], SlRadioGroup.prototype, "errorMessage", 2);
4595
- __decorateClass([
4596
- r5()
4597
- ], SlRadioGroup.prototype, "defaultValue", 2);
4598
- __decorateClass([
4599
- n5()
4600
- ], SlRadioGroup.prototype, "label", 2);
4601
- __decorateClass([
4602
- n5({ attribute: "help-text" })
4603
- ], SlRadioGroup.prototype, "helpText", 2);
4604
- __decorateClass([
4605
- n5()
4606
- ], SlRadioGroup.prototype, "name", 2);
4607
- __decorateClass([
4608
- n5({ reflect: true })
4609
- ], SlRadioGroup.prototype, "value", 2);
4610
- __decorateClass([
4611
- n5({ reflect: true })
4612
- ], SlRadioGroup.prototype, "size", 2);
4613
- __decorateClass([
4614
- n5({ reflect: true })
4615
- ], SlRadioGroup.prototype, "form", 2);
4616
- __decorateClass([
4617
- n5({ type: Boolean, reflect: true })
4618
- ], SlRadioGroup.prototype, "required", 2);
4619
- __decorateClass([
4620
- watch("size", { waitUntilFirstUpdate: true })
4621
- ], SlRadioGroup.prototype, "handleSizeChange", 1);
4622
- __decorateClass([
4623
- watch("value")
4624
- ], SlRadioGroup.prototype, "handleValueChange", 1);
4625
-
4626
- // ../../node_modules/bootstrap-icons/icons/plus-square.svg
4627
- var plus_square_default = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-plus-square" viewBox="0 0 16 16">%0A <path d="M14 1a1 1 0 0 1 1 1v12a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1zM2 0a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2z"/>%0A <path d="M8 4a.5.5 0 0 1 .5.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3A.5.5 0 0 1 8 4"/>%0A</svg>';
4628
-
4629
- // ../../node_modules/bootstrap-icons/icons/plus-circle.svg
4630
- var plus_circle_default = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-plus-circle" viewBox="0 0 16 16">%0A <path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14m0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16"/>%0A <path d="M8 4a.5.5 0 0 1 .5.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3A.5.5 0 0 1 8 4"/>%0A</svg>';
4631
-
4632
- // src/widgets/webwriter-choice.ts
4633
- function shuffle(a3) {
4634
- for (let i4 = a3.length - 1; i4 > 0; i4--) {
4635
- const j3 = Math.floor(Math.random() * (i4 + 1));
4636
- [a3[i4], a3[j3]] = [a3[j3], a3[i4]];
4637
- }
4638
- return a3;
4639
- }
4640
- var _itemsSlotEl_dec, _value_dec, _items_dec, _addItem_dec, _slotEl_dec, _randomOrder_dec, _layout_dec, _mode_dec, _a2, _WebwriterChoice_decorators, _init2, _mode, _randomOrder, _slotEl, _items, _value, _itemsSlotEl;
4641
- _WebwriterChoice_decorators = [t3("webwriter-choice")];
4642
- var WebwriterChoice = class extends (_a2 = LitElementWw, _mode_dec = [n5({ type: String, attribute: true, reflect: true }), option({
4643
- type: "select",
4644
- options: [
4645
- { value: "truefalse", label: { "en": "True/False" } },
4646
- { value: "single", label: { "en": "Single Choice" } },
4647
- { value: "multiple", label: { "en": "Multiple Choice" } }
4648
- ]
4649
- })], _layout_dec = [n5({ type: String, attribute: true, reflect: true }), option({
4650
- type: "select",
4651
- options: [
4652
- { value: "list", label: { "en": "List" } },
4653
- { value: "tiles", label: { "en": "Tiles" } }
4654
- ]
4655
- })], _randomOrder_dec = [n5({ type: Boolean, attribute: true, reflect: true }), option({
4656
- type: Boolean,
4657
- label: { "en": "Random Choice Order" }
4658
- })], _slotEl_dec = [e5("slot")], _addItem_dec = [action()], _items_dec = [o5()], _value_dec = [n5({ type: Array, attribute: false })], _itemsSlotEl_dec = [e5("#items-slot")], _a2) {
4659
- constructor() {
4660
- super(...arguments);
4661
- __runInitializers(_init2, 5, this);
4662
- __privateAdd(this, _mode, __runInitializers(_init2, 8, this, "single")), __runInitializers(_init2, 11, this);
4663
- __privateAdd(this, _randomOrder, __runInitializers(_init2, 12, this, false)), __runInitializers(_init2, 15, this);
4664
- __privateAdd(this, _slotEl, __runInitializers(_init2, 16, this)), __runInitializers(_init2, 19, this);
4665
- __privateAdd(this, _items, __runInitializers(_init2, 20, this)), __runInitializers(_init2, 23, this);
4666
- __privateAdd(this, _value, []);
4667
- __publicField(this, "handleControlChange", (e7) => {
4668
- if (this.mode === "single") {
4669
- const item = e7.target;
4670
- const otherItems = this.items.filter((el) => el !== item);
4671
- otherItems.forEach((el) => this.isContentEditable ? el.valid = false : el.active = false);
4672
- }
4673
- this.applyValue();
4674
- this.dispatchEvent(new CustomEvent("ww-answer-change", {
4675
- detail: { value: this.value },
4676
- bubbles: true,
4677
- composed: true
4678
- }));
4679
- });
4680
- __privateAdd(this, _itemsSlotEl, __runInitializers(_init2, 24, this)), __runInitializers(_init2, 27, this);
4681
- }
4682
- get layout() {
4683
- return this.children?.item(0)?.getAttribute("layout") ?? "list";
4684
- }
4685
- set layout(value) {
4686
- this.querySelectorAll("webwriter-choice-item").forEach((el) => el.setAttribute("layout", value));
4687
- this.requestUpdate("layout");
4688
- }
4689
- get solution() {
4690
- const validIDs = this.items.filter((item) => item.valid).map((item) => item.id);
4691
- return validIDs.length ? validIDs : void 0;
4692
- }
4693
- set solution(value) {
4694
- this.items.forEach((item) => value.includes(item.id) ? item.valid = true : null);
4695
- }
4696
- reportSolution() {
4697
- if (!this.solution) {
4698
- this.items.forEach((item) => item.valid = true);
4699
- return;
4700
- }
4701
- this.items.forEach((item) => item.valid = (this.solution ?? []).includes(item.id));
4702
- }
4703
- reset() {
4704
- this.items.forEach((item) => {
4705
- item.valid = void 0;
4706
- item.active = false;
4707
- });
4708
- this.shuffleItems();
4709
- }
4710
- addItem() {
4711
- const choiceItem = this.ownerDocument.createElement("webwriter-choice-item");
4712
- const p3 = this.ownerDocument.createElement("p");
4713
- choiceItem.appendChild(p3);
4714
- choiceItem.setAttribute("layout", this.layout);
4715
- this.appendChild(choiceItem);
4716
- this.ownerDocument.getSelection().setBaseAndExtent(p3, 0, p3, 0);
4717
- }
4718
- shuffleItems() {
4719
- const items = this.slotEl.assignedElements();
4720
- const n6 = items.length;
4721
- const nums = shuffle([...new Array(n6).keys()]);
4722
- items.forEach((el, i4) => el.style.order = String(nums[i4]));
4723
- }
4724
- connectedCallback() {
4725
- super.connectedCallback();
4726
- const observer = new MutationObserver(() => {
4727
- if (!this.contentEditable && this.randomOrder) {
4728
- this.shuffleItems();
4729
- }
4730
- });
4731
- observer.observe(this, { childList: true });
4732
- }
4733
- firstUpdated(_changedProperties) {
4734
- if (!this.contentEditable && this.randomOrder) {
4735
- this.shuffleItems();
4736
- }
4737
- }
4738
- get value() {
4739
- return __privateGet(this, _value);
4740
- }
4741
- set value(value) {
4742
- __privateSet(this, _value, value);
4743
- this.items.forEach((item, i4) => {
4744
- this.isContentEditable ? item.valid = __privateGet(this, _value).includes(i4) : item.active = __privateGet(this, _value).includes(i4);
4745
- });
4746
- }
4747
- applyValue() {
4748
- __privateSet(this, _value, this.items.map((item, i4) => [item.valid, i4]).filter(([valid]) => valid).map(([_3, i4]) => i4));
4749
- }
4750
- handleSlotChange(e7) {
4751
- this.requestUpdate();
4752
- }
4753
- willUpdate(changed) {
4754
- if (changed.has("mode") && this.mode === "single") {
4755
- this.items.filter((el) => this.isContentEditable ? el.valid : el.active).slice(1).forEach((el) => this.isContentEditable ? el.valid = false : el.active = false);
4756
- }
4757
- if (changed.has("mode") && this.mode === "truefalse") {
4758
- this.items.forEach((el) => el.remove());
4759
- }
4760
- }
4761
- render() {
4762
- return ke`
4763
- ${this.mode === "truefalse" ? ke`
4764
- <sl-radio-group>
4765
- <sl-radio-button value="true">True</sl-radio-button>
4766
- <sl-radio-button value="false">False</sl-radio-button>
4767
- </sl-radio-group>
4768
- ` : ke`
4769
- <slot id="items-slot" @sl-change=${this.handleControlChange} @slotchange=${this.handleSlotChange}></slot>
4770
- `}
4771
- <sl-button size="small" id="add-option" class="author-only" @click=${() => this.addItem()}>
4772
- <sl-icon src=${this.mode === "multiple" ? plus_square_default : plus_circle_default}></sl-icon><span>Add Option</span>
4773
- </sl-button>
4774
- `;
4775
- }
4776
- };
4777
- _init2 = __decoratorStart(_a2);
4778
- _mode = new WeakMap();
4779
- _randomOrder = new WeakMap();
4780
- _slotEl = new WeakMap();
4781
- _items = new WeakMap();
4782
- _value = new WeakMap();
4783
- _itemsSlotEl = new WeakMap();
4784
- __decorateElement(_init2, 4, "mode", _mode_dec, WebwriterChoice, _mode);
4785
- __decorateElement(_init2, 3, "layout", _layout_dec, WebwriterChoice);
4786
- __decorateElement(_init2, 4, "randomOrder", _randomOrder_dec, WebwriterChoice, _randomOrder);
4787
- __decorateElement(_init2, 4, "slotEl", _slotEl_dec, WebwriterChoice, _slotEl);
4788
- __decorateElement(_init2, 1, "addItem", _addItem_dec, WebwriterChoice);
4789
- __decorateElement(_init2, 4, "items", _items_dec, WebwriterChoice, _items);
4790
- __decorateElement(_init2, 3, "value", _value_dec, WebwriterChoice);
4791
- __decorateElement(_init2, 4, "itemsSlotEl", _itemsSlotEl_dec, WebwriterChoice, _itemsSlotEl);
4792
- WebwriterChoice = __decorateElement(_init2, 0, "WebwriterChoice", _WebwriterChoice_decorators, WebwriterChoice);
4793
- __publicField(WebwriterChoice, "scopedElements", {
4794
- "sl-button": SlButton,
4795
- "sl-icon": SlIcon,
4796
- "sl-radio": SlRadio,
4797
- "sl-checkbox": SlCheckbox,
4798
- "sl-radio-button": SlRadioButton,
4799
- "sl-radio-group": SlRadioGroup
4800
- });
4801
- __publicField(WebwriterChoice, "styles", i`
4802
- :host {
4803
- display: flex !important;
4804
- flex-direction: column;
4805
- align-items: flex-start;
4806
- gap: 0.5rem;
4807
- }
4808
-
4809
- :host([layout=tiles]) {
4810
-
4811
- flex-direction: row;
4812
- flex-wrap: wrap;
4813
- gap: 15px;
4814
-
4815
- & ::slotted(*) {
4816
- aspect-ratio: 1;
4817
- min-width: 125px;
4818
- width: 125px;
4819
- max-width: 350px;
4820
- min-height: 125px;
4821
- height: 125px;
4822
- max-height: 350px;
4823
- overflow: hidden;
4824
- resize: both;
4825
- border: 2px solid var(--sl-color-gray-500);
4826
- border-radius: 5px;
4827
- }
4828
- }
4829
-
4830
- sl-button::part(label) {
4831
- padding: 0;
4832
- display: flex;
4833
- flex-direction: row;
4834
- align-items: center;
4835
- }
4836
-
4837
- sl-button::part(base) {
4838
- border: none;
4839
- background: transparent;
4840
- }
4841
-
4842
- sl-icon {
4843
- width: 19px;
4844
- height: 19px;
4845
- }
4846
-
4847
- sl-icon::part(svg) {
4848
- overflow: visible;
4849
- }
4850
-
4851
- :host(:not([contenteditable=true]):not([contenteditable=""])) .author-only {
4852
- display: none !important;
4853
- }
4854
-
4855
- #add-option span {
4856
- margin-inline-start: 0.5em;
4857
- }
4858
-
4859
- :host(:is([contenteditable=true], [contenteditable=""])) ::slotted(*) {
4860
- order: unset !important;
4861
- }
4862
-
4863
- :host(:not([mode=multiple])) {
4864
- --webwriter-choice-radius: 100%;
4865
- }
4866
-
4867
- #add-option:not(:hover)::part(base) {
4868
- color: darkgray;
4869
- }
4870
-
4871
- :host([layout=tiles]) #add-option {
4872
- width: 125px;
4873
- height: 125px;
4874
- overflow: hidden;
4875
- border: 2px solid var(--sl-color-gray-300);
4876
- border-radius: 5px;
4877
- padding: 5px;
4878
- display: flex;
4879
- align-items: center;
4880
- justify-content: center;
4881
- }
4882
-
4883
- :host([mode=truefalse]) #add-option {
4884
- display: none;
4885
- }
4886
- `);
4887
- __runInitializers(_init2, 1, WebwriterChoice);
4888
-
4889
- // src/widgets/webwriter-order.ts
4890
- var _solution_dec, _items_dec2, _itemsSlot_dec, _hideOrderButtons_dec, _layout_dec2, _a3, _WebwriterOrder_decorators, _init3, _itemsSlot, _items2, _solution;
4891
- _WebwriterOrder_decorators = [t3("webwriter-order")];
4892
- var WebwriterOrder = class extends (_a3 = LitElementWw, _layout_dec2 = [n5({ type: String, attribute: true, reflect: true }), option({
4893
- type: "select",
4894
- options: [
4895
- { value: "list", label: { "en": "List" } },
4896
- { value: "tiles", label: { "en": "Tiles" } }
4897
- ]
4898
- })], _hideOrderButtons_dec = [n5({ type: Boolean, attribute: true, reflect: true }), option({ type: Boolean, label: { _: "Hide order buttons" } })], _itemsSlot_dec = [e5("#items-slot")], _items_dec2 = [o5()], _solution_dec = [n5({ attribute: false })], _a3) {
4899
- constructor() {
4900
- super(...arguments);
4901
- __runInitializers(_init3, 5, this);
4902
- __publicField(this, "observer");
4903
- __publicField(this, "orderSheet", new CSSStyleSheet());
4904
- __publicField(this, "clearDropPreviews", () => {
4905
- this.items.forEach((item) => item.dropPreview = void 0);
4906
- });
4907
- __privateAdd(this, _itemsSlot, __runInitializers(_init3, 8, this)), __runInitializers(_init3, 11, this);
4908
- __privateAdd(this, _items2, __runInitializers(_init3, 12, this)), __runInitializers(_init3, 15, this);
4909
- __publicField(this, "handleMove", (e7) => {
4910
- const elem = e7.target;
4911
- const children = Array.from(this.children);
4912
- const pos = children.indexOf(elem);
4913
- let i4;
4914
- if (e7.type === "ww-moveup") {
4915
- i4 = Math.max(0, pos - 1);
4916
- } else if (e7.type === "ww-movedown") {
4917
- i4 = Math.min(children.length, pos + 2);
4918
- } else if (e7.type === "ww-moveto") {
4919
- i4 = e7.detail.i;
4920
- }
4921
- this.moveChild(elem, i4);
4922
- });
4923
- __privateAdd(this, _solution, []);
4924
- }
4925
- get layout() {
4926
- return this.children?.item(0)?.getAttribute("layout") ?? "list";
4927
- }
4928
- set layout(value) {
4929
- this.querySelectorAll("webwriter-order-item").forEach((el) => el.setAttribute("layout", value));
4930
- this.requestUpdate("layout");
4931
- }
4932
- get hideOrderButtons() {
4933
- return !!this.items[0]?.hideOrderButtons;
4934
- }
4935
- set hideOrderButtons(value) {
4936
- this.items.forEach((item) => item.hideOrderButtons = value);
4937
- }
4938
- connectedCallback() {
4939
- super.connectedCallback();
4940
- this.addEventListener("ww-moveup", this.handleMove);
4941
- this.addEventListener("ww-movedown", this.handleMove);
4942
- this.addEventListener("ww-moveto", this.handleMove);
4943
- this.observer = new MutationObserver(() => {
4944
- this.items.forEach((item) => item.requestUpdate());
4945
- if (this.isContentEditable) {
4946
- this.solution = this.items.map((item) => item.id);
4947
- }
4948
- this.clearDropPreviews();
4949
- });
4950
- this.observer.observe(this, { childList: true });
4951
- }
4952
- serializedCallback() {
4953
- this.shuffleItems();
4954
- }
4955
- disconnectedCallback() {
4956
- super.disconnectedCallback();
4957
- this.observer?.disconnect();
4958
- this.observer = void 0;
4959
- }
4960
- addItem() {
4961
- const orderItem = this.ownerDocument.createElement("webwriter-order-item");
4962
- const p3 = this.ownerDocument.createElement("p");
4963
- orderItem.appendChild(p3);
4964
- orderItem.setAttribute("layout", this.layout);
4965
- this.append(orderItem);
4966
- this.solution = [...__privateGet(this, _solution), orderItem.id];
4967
- this.ownerDocument.getSelection().setBaseAndExtent(p3, 0, p3, 0);
4968
- }
4969
- shuffleItems() {
4970
- const n6 = this.items.length;
4971
- const nums = shuffle([...new Array(n6).keys()]);
4972
- this.innerHTML = nums.map((i4) => this.children.item(i4).outerHTML).join("");
4973
- }
4974
- handleKeyDown(e7) {
4975
- if (e7.key == "ArrowDown") {
4976
- e7.stopPropagation();
4977
- e7.preventDefault();
4978
- } else if (e7.key === "ArrowUp") {
4979
- e7.stopPropagation();
4980
- e7.preventDefault();
4981
- }
4982
- }
4983
- /*
4984
- If contenteditable: Reorder solution -> Triggers orderSheet change
4985
- If not contenteditable: Reorder value -> Triggers orderSheet change
4986
- */
4987
- moveChild(elem, i4) {
4988
- if (i4 === 0) {
4989
- this.insertAdjacentElement("afterbegin", elem);
4990
- } else if (i4 < this.items.length) {
4991
- this.items[i4].insertAdjacentElement("beforebegin", elem);
4992
- } else {
4993
- this.insertAdjacentElement("beforeend", elem);
4994
- }
4995
- }
4996
- get solution() {
4997
- return __privateGet(this, _solution)?.length ? __privateGet(this, _solution) : void 0;
4998
- }
4999
- set solution(value) {
5000
- __privateSet(this, _solution, value);
5001
- if (value) {
5002
- this.dispatchEvent(new CustomEvent("ww-answer-change", {
5003
- bubbles: true,
5004
- composed: true
5005
- }));
5006
- }
5007
- }
5008
- reportSolution() {
5009
- this.solution.forEach((id, i4) => this.querySelector(`#${id}`).validOrder = i4);
5010
- }
5011
- reset() {
5012
- this.solution = void 0;
5013
- this.shuffleItems();
5014
- }
5015
- render() {
5016
- return ke`
5017
- <slot id="items-slot" @webwriter-clear-drop-preview=${this.clearDropPreviews}></slot>
5018
- <sl-button size="small" id="add-option" class="author-only" @click=${() => this.addItem()}>
5019
- <sl-icon src=${plus_default}></sl-icon><span>Add Option</span>
5020
- </sl-button>
5021
- `;
5022
- }
5023
- };
5024
- _init3 = __decoratorStart(_a3);
5025
- _itemsSlot = new WeakMap();
5026
- _items2 = new WeakMap();
5027
- _solution = new WeakMap();
5028
- __decorateElement(_init3, 3, "layout", _layout_dec2, WebwriterOrder);
5029
- __decorateElement(_init3, 3, "hideOrderButtons", _hideOrderButtons_dec, WebwriterOrder);
5030
- __decorateElement(_init3, 4, "itemsSlot", _itemsSlot_dec, WebwriterOrder, _itemsSlot);
5031
- __decorateElement(_init3, 4, "items", _items_dec2, WebwriterOrder, _items2);
5032
- __decorateElement(_init3, 3, "solution", _solution_dec, WebwriterOrder);
5033
- WebwriterOrder = __decorateElement(_init3, 0, "WebwriterOrder", _WebwriterOrder_decorators, WebwriterOrder);
5034
- __publicField(WebwriterOrder, "scopedElements", {
5035
- "sl-button": SlButton,
5036
- "sl-icon": SlIcon
5037
- });
5038
- __publicField(WebwriterOrder, "styles", i`
5039
- :host {
5040
- display: flex !important;
5041
- flex-direction: column;
5042
- align-items: flex-start;
5043
- counter-reset: orderItem;
5044
- gap: 2px;
5045
- }
5046
-
5047
- :host([layout=tiles]) {
5048
- flex-direction: row;
5049
- flex-wrap: wrap;
5050
- gap: 15px;
5051
- }
5052
-
5053
- :host(:is([contenteditable=true], [contenteditable=""])) {
5054
- --text-color: var(--sl-color-success-700);
5055
- }
3600
+ :host(:is([contenteditable=true], [contenteditable=""])) {
3601
+ --text-color: var(--sl-color-success-700);
3602
+ }
5056
3603
 
5057
3604
  :host ::slotted(*::part(counter)) {
5058
3605
  counter-increment: orderItem;
@@ -5108,9 +3655,10 @@ __publicField(WebwriterOrder, "styles", i`
5108
3655
  display: none;
5109
3656
  }
5110
3657
  `);
5111
- __runInitializers(_init3, 1, WebwriterOrder);
3658
+ __runInitializers(_init2, 1, WebwriterOrder);
5112
3659
  export {
5113
- WebwriterOrder
3660
+ WebwriterOrder,
3661
+ shuffle
5114
3662
  };
5115
3663
  /*! Bundled license information:
5116
3664
 
@@ -5360,11 +3908,4 @@ lit-html/directives/if-defined.js:
5360
3908
  * Copyright 2018 Google LLC
5361
3909
  * SPDX-License-Identifier: BSD-3-Clause
5362
3910
  *)
5363
-
5364
- lit-html/directives/live.js:
5365
- (**
5366
- * @license
5367
- * Copyright 2020 Google LLC
5368
- * SPDX-License-Identifier: BSD-3-Clause
5369
- *)
5370
3911
  */