@pie-element/boilerplate-item-type 5.0.1-next.0 → 5.0.1

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.
@@ -0,0 +1,113 @@
1
+ import isEmpty from 'lodash/isEmpty';
2
+
3
+ function _defineProperty(obj, key, value) {
4
+ if (key in obj) {
5
+ Object.defineProperty(obj, key, {
6
+ value: value,
7
+ enumerable: true,
8
+ configurable: true,
9
+ writable: true
10
+ });
11
+ } else {
12
+ obj[key] = value;
13
+ }
14
+
15
+ return obj;
16
+ }
17
+
18
+ // Should be exactly the same as configure/defaults.js
19
+ var defaults = {
20
+ model: {
21
+ prompt: '',
22
+ promptEnabled: true
23
+ },
24
+ configuration: {
25
+ prompt: {
26
+ label: 'Prompt',
27
+ settings: true
28
+ }
29
+ }
30
+ };
31
+
32
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
33
+
34
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
35
+ var getCorrectness = model => {
36
+ var correctnessCondition = 'c';
37
+
38
+ switch (correctnessCondition) {
39
+ case 'c':
40
+ return 'correct';
41
+
42
+ case 'pc':
43
+ return 'partially-correct';
44
+
45
+ case 'i':
46
+ return 'incorrect';
47
+
48
+ default:
49
+ return 'unknown';
50
+ }
51
+ };
52
+ var getPartialScore = (question, session) => {
53
+ if (!session || isEmpty(session)) {
54
+ return 0;
55
+ }
56
+
57
+ return 1;
58
+ };
59
+ var outcome = (question, session, env) => new Promise(resolve => {
60
+ if (!session || isEmpty(session)) {
61
+ resolve({
62
+ score: 0,
63
+ empty: true
64
+ });
65
+ }
66
+
67
+ session = normalizeSession(session);
68
+
69
+ if (env.mode !== 'evaluate') {
70
+ resolve({
71
+ score: undefined,
72
+ completed: undefined
73
+ });
74
+ } else {
75
+ resolve({
76
+ score: 1
77
+ });
78
+ }
79
+ });
80
+ var createDefaultModel = function createDefaultModel() {
81
+ var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
82
+ return _objectSpread(_objectSpread({}, defaults.model), model);
83
+ };
84
+ var normalizeSession = s => _objectSpread({}, s);
85
+ var model = (question, session, env) => {
86
+ return new Promise(resolve => {
87
+ var normalizedQuestion = createDefaultModel(question);
88
+ var out = {
89
+ prompt: normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null,
90
+ extraCSSRules: normalizedQuestion.extraCSSRules,
91
+ env
92
+ };
93
+ resolve(out);
94
+ });
95
+ };
96
+ var createCorrectResponseSession = (question, env) => {
97
+ return new Promise(resolve => {
98
+ if (env.mode !== 'evaluate' && env.role === 'instructor') {
99
+ resolve({
100
+ id: '1'
101
+ });
102
+ } else {
103
+ resolve(null);
104
+ }
105
+ });
106
+ };
107
+ var validate = function validate() {
108
+ var errors = {};
109
+ return errors;
110
+ };
111
+
112
+ export { createCorrectResponseSession, createDefaultModel, getCorrectness, getPartialScore, model, normalizeSession, outcome, validate };
113
+ //# sourceMappingURL=controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"controller.js","sources":["../../../node_modules/@babel/runtime/helpers/esm/defineProperty.js","../controller/src/defaults.js","../controller/src/index.js"],"sourcesContent":["export default function _defineProperty(obj, key, value) {\n if (key in obj) {\n Object.defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n } else {\n obj[key] = value;\n }\n\n return obj;\n}","// Should be exactly the same as configure/defaults.js\nexport default {\n model: {\n prompt: '',\n promptEnabled: true,\n },\n configuration: {\n prompt: {\n label: 'Prompt',\n settings: true,\n },\n },\n};\n","import isEmpty from 'lodash/isEmpty';\nimport defaults from './defaults';\n\nexport const getCorrectness = (model) => {\n const correctnessCondition = 'c';\n\n switch (correctnessCondition) {\n case 'c':\n return 'correct';\n case 'pc':\n return 'partially-correct';\n case 'i':\n return 'incorrect';\n default:\n return 'unknown';\n }\n};\n\nexport const getPartialScore = (question, session) => {\n if (!session || isEmpty(session)) {\n return 0;\n }\n\n return 1;\n};\n\nexport const outcome = (question, session, env) =>\n new Promise((resolve) => {\n if (!session || isEmpty(session)) {\n resolve({ score: 0, empty: true });\n }\n\n session = normalizeSession(session);\n\n if (env.mode !== 'evaluate') {\n resolve({ score: undefined, completed: undefined });\n } else {\n resolve({ score: 1 });\n }\n });\n\nexport const createDefaultModel = (model = {}) => ({ ...defaults.model, ...model });\n\nexport const normalizeSession = (s) => ({ ...s });\n\nexport const model = (question, session, env) => {\n return new Promise((resolve) => {\n session = session || {};\n const normalizedQuestion = createDefaultModel(question);\n\n const out = {\n prompt: normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null,\n extraCSSRules: normalizedQuestion.extraCSSRules,\n env,\n };\n\n resolve(out);\n });\n};\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise((resolve) => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n resolve({ id: '1' });\n } else {\n resolve(null);\n }\n });\n};\n\nexport const validate = (model = {}, config = {}) => {\n const errors = {};\n\n return errors;\n};\n"],"names":["model","prompt","promptEnabled","configuration","label","settings","getCorrectness","correctnessCondition","getPartialScore","question","session","isEmpty","outcome","env","Promise","resolve","score","empty","normalizeSession","mode","undefined","completed","createDefaultModel","defaults","s","normalizedQuestion","out","extraCSSRules","createCorrectResponseSession","role","id","validate","errors"],"mappings":";;AAAe,SAAS,eAAe,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE;AACzD,EAAE,IAAI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V0B,MAAAA,aAAa,EAAEF,kBAAkB,CAACE,aAFxB;AAGVd,MAAAA,GAAAA;AAHU,KAAZ,CAAA;AAMAE,IAAAA,OAAO,CAACW,GAAD,CAAP,CAAA;AACD,GAXM,CAAP,CAAA;AAYD,EAbM;IAeME,4BAA4B,GAAG,CAACnB,QAAD,EAAWI,GAAX,KAAmB;AAC7D,EAAA,OAAO,IAAIC,OAAJ,CAAaC,OAAD,IAAa;AAC9B,IAAIF,IAAAA,GAAG,CAACM,IAAJ,KAAa,UAAb,IAA2BN,GAAG,CAACgB,IAAJ,KAAa,YAA5C,EAA0D;AACxDd,MAAAA,OAAO,CAAC;AAAEe,QAAAA,EAAE,EAAE,GAAA;AAAN,OAAD,CAAP,CAAA;AACD,KAFD,MAEO;AACLf,MAAAA,OAAO,CAAC,IAAD,CAAP,CAAA;AACD,KAAA;AACF,GANM,CAAP,CAAA;AAOD,EARM;AAUMgB,IAAAA,QAAQ,GAAG,SAAXA,QAAW,GAA6B;AACnD,EAAMC,IAAAA,MAAM,GAAG,EAAf,CAAA;AAEA,EAAA,OAAOA,MAAP,CAAA;AACD;;;;"}
package/esm/element.js ADDED
@@ -0,0 +1,99 @@
1
+ import React from 'react';
2
+ import ReactDOM from 'react-dom';
3
+ import { ModelSetEvent, SessionChangedEvent } from '@pie-framework/pie-player-events';
4
+ import PropTypes from 'prop-types';
5
+ import { UiLayout, PreviewPrompt } from '@pie-lib/render-ui';
6
+ import { renderMath } from '@pie-lib/math-rendering';
7
+
8
+ function _defineProperty(obj, key, value) {
9
+ if (key in obj) {
10
+ Object.defineProperty(obj, key, {
11
+ value: value,
12
+ enumerable: true,
13
+ configurable: true,
14
+ writable: true
15
+ });
16
+ } else {
17
+ obj[key] = value;
18
+ }
19
+
20
+ return obj;
21
+ }
22
+
23
+ class Main extends React.Component {
24
+ render() {
25
+ var {
26
+ model
27
+ } = this.props;
28
+ var {
29
+ extraCSSRules
30
+ } = model;
31
+ return /*#__PURE__*/React.createElement(UiLayout, {
32
+ extraCSSRules: extraCSSRules
33
+ }, model.prompt && /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("p", null, "Boilerplate Item"), /*#__PURE__*/React.createElement(PreviewPrompt, {
34
+ prompt: model.prompt
35
+ })));
36
+ }
37
+
38
+ }
39
+
40
+ _defineProperty(Main, "propTypes", {
41
+ model: PropTypes.object,
42
+ session: PropTypes.object,
43
+ onSessionChange: PropTypes.func.isRequired
44
+ });
45
+
46
+ _defineProperty(Main, "defaultProps", {});
47
+
48
+ class BoilerplateItemType extends HTMLElement {
49
+ set model(m) {
50
+ this._model = m;
51
+ this.render();
52
+ this.dispatchEvent(new ModelSetEvent(this.tagName.toLowerCase(), this.isSessionComplete(), this._model !== undefined));
53
+ }
54
+
55
+ get model() {
56
+ return this._model;
57
+ }
58
+
59
+ set session(s) {
60
+ this._session = s;
61
+ this.render();
62
+ }
63
+
64
+ get session() {
65
+ return this._session;
66
+ }
67
+
68
+ isSessionComplete() {
69
+ // a method to check if student answered the question
70
+ return true;
71
+ }
72
+
73
+ onSessionChange(session) {
74
+ // you can add an extra step here to validate session
75
+ this._session = session;
76
+ this.dispatchEvent(new SessionChangedEvent(this.tagName.toLowerCase(), this.isSessionComplete()));
77
+ }
78
+
79
+ connectedCallback() {
80
+ this.render();
81
+ }
82
+
83
+ render() {
84
+ if (this._model && this._session) {
85
+ var el = /*#__PURE__*/React.createElement(Main, {
86
+ model: this._model,
87
+ session: this._session,
88
+ onSessionChange: this.onSessionChange.bind(this)
89
+ });
90
+ ReactDOM.render(el, this, () => {
91
+ renderMath(this);
92
+ });
93
+ }
94
+ }
95
+
96
+ }
97
+
98
+ export { BoilerplateItemType as default };
99
+ //# sourceMappingURL=element.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"element.js","sources":["../../../node_modules/@babel/runtime/helpers/esm/defineProperty.js","../src/main.jsx","../src/index.js"],"sourcesContent":["export default function _defineProperty(obj, key, value) {\n if (key in obj) {\n Object.defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n } else {\n obj[key] = value;\n }\n\n return obj;\n}","import React from 'react';\nimport PropTypes from 'prop-types';\nimport { PreviewPrompt, UiLayout } from '@pie-lib/render-ui';\n\nexport default class Main extends React.Component {\n static propTypes = {\n model: PropTypes.object,\n session: PropTypes.object,\n onSessionChange: PropTypes.func.isRequired,\n };\n\n static defaultProps = {};\n\n render() {\n const { model } = this.props;\n const { extraCSSRules } = model;\n\n return (\n <UiLayout extraCSSRules={extraCSSRules}>\n {model.prompt && (\n <div>\n <p>Boilerplate Item</p>\n <PreviewPrompt prompt={model.prompt} />\n </div>\n )}\n </UiLayout>\n );\n }\n}\n","import React from 'react';\nimport ReactDOM from 'react-dom';\nimport { SessionChangedEvent, ModelSetEvent } from '@pie-framework/pie-player-events';\nimport Main from './main';\nimport { renderMath } from '@pie-lib/math-rendering';\n\nexport default class BoilerplateItemType extends HTMLElement {\n set model(m) {\n this._model = m;\n\n this.render();\n this.dispatchEvent(\n new ModelSetEvent(this.tagName.toLowerCase(), this.isSessionComplete(), this._model !== undefined),\n );\n }\n\n get model() {\n return this._model;\n }\n\n set session(s) {\n this._session = s;\n\n this.render();\n }\n\n get session() {\n return this._session;\n }\n\n isSessionComplete() {\n // a method to check if student answered the question\n return true;\n }\n\n onSessionChange(session) {\n // you can add an extra step here to validate session\n this._session = session;\n\n this.dispatchEvent(new SessionChangedEvent(this.tagName.toLowerCase(), this.isSessionComplete()));\n }\n\n connectedCallback() {\n this.render();\n }\n\n render() {\n if (this._model && this._session) {\n const el = React.createElement(Main, {\n model: this._model,\n session: this._session,\n onSessionChange: this.onSessionChange.bind(this),\n });\n\n ReactDOM.render(el, this, () => {\n renderMath(this);\n });\n }\n }\n}\n"],"names":["Main","React","Component","render","model","props","extraCSSRules","prompt","PropTypes","object","session","onSessionChange","func","isRequired","BoilerplateItemType","HTMLElement","m","_model","dispatchEvent","ModelSetEvent","tagName","toLowerCase","isSessionComplete","undefined","s","_session","Sess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AA,CAAKQ,QAAxB,EAAkC;AAChC,MAAA,IAAMG,EAAE,gBAAG3B,KAAK,CAAC4B,aAAN,CAAoB7B,IAApB,EAA0B;AACnCI,QAAAA,KAAK,EAAE,IAAA,CAAKa,MADuB;AAEnCP,QAAAA,OAAO,EAAE,IAAA,CAAKe,QAFqB;AAGnCd,QAAAA,eAAe,EAAE,IAAA,CAAKA,eAAL,CAAqBmB,IAArB,CAA0B,IAA1B,CAAA;AAHkB,OAA1B,CAAX,CAAA;AAMAC,MAAAA,QAAQ,CAAC5B,MAAT,CAAgByB,EAAhB,EAAoB,IAApB,EAA0B,MAAM;AAC9BI,QAAAA,UAAU,CAAC,IAAD,CAAV,CAAA;AACD,OAFD,CAAA,CAAA;AAGD,KAAA;AACF,GAAA;;AApD0D;;;;"}
package/esm/print.js ADDED
@@ -0,0 +1,103 @@
1
+ import React from 'react';
2
+ import ReactDOM from 'react-dom';
3
+ import debounce from 'lodash/debounce';
4
+ import PropTypes from 'prop-types';
5
+ import { UiLayout, PreviewPrompt } from '@pie-lib/render-ui';
6
+ import { renderMath } from '@pie-lib/math-rendering';
7
+ import debug from 'debug';
8
+
9
+ function _defineProperty(obj, key, value) {
10
+ if (key in obj) {
11
+ Object.defineProperty(obj, key, {
12
+ value: value,
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true
16
+ });
17
+ } else {
18
+ obj[key] = value;
19
+ }
20
+
21
+ return obj;
22
+ }
23
+
24
+ class Main extends React.Component {
25
+ render() {
26
+ var {
27
+ model
28
+ } = this.props;
29
+ var {
30
+ extraCSSRules
31
+ } = model;
32
+ return /*#__PURE__*/React.createElement(UiLayout, {
33
+ extraCSSRules: extraCSSRules
34
+ }, model.prompt && /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("p", null, "Boilerplate Item"), /*#__PURE__*/React.createElement(PreviewPrompt, {
35
+ prompt: model.prompt
36
+ })));
37
+ }
38
+
39
+ }
40
+
41
+ _defineProperty(Main, "propTypes", {
42
+ model: PropTypes.object,
43
+ session: PropTypes.object,
44
+ onSessionChange: PropTypes.func.isRequired
45
+ });
46
+
47
+ _defineProperty(Main, "defaultProps", {});
48
+
49
+ var log = debug('pie-element:multiple-choice:print');
50
+ /**
51
+ * Live in same package as main element - so we can access some of the shared comps!
52
+ *
53
+ * - update pslb to build print if src/print.js is there
54
+ * - update demo el
55
+ * - get configure/controller building
56
+ */
57
+
58
+ var preparePrintModel = (model, opts) => {
59
+ return model;
60
+ };
61
+
62
+ class BoilerPlateItemTypePrint extends HTMLElement {
63
+ constructor() {
64
+ super();
65
+ this._options = null;
66
+ this._model = null;
67
+ this._session = [];
68
+ this._rerender = debounce(() => {
69
+ if (this._model && this._session) {
70
+ var printModel = preparePrintModel(this._model, this._options);
71
+ var element = this._options && /*#__PURE__*/React.createElement(Main, {
72
+ model: printModel,
73
+ session: {}
74
+ });
75
+ ReactDOM.render(element, this, () => {
76
+ log('render complete - render math');
77
+ renderMath(this);
78
+ });
79
+ } else {
80
+ log('skip');
81
+ }
82
+ }, 50, {
83
+ leading: false,
84
+ trailing: true
85
+ });
86
+ }
87
+
88
+ set options(o) {
89
+ this._options = o;
90
+ }
91
+
92
+ set model(s) {
93
+ this._model = s;
94
+
95
+ this._rerender();
96
+ }
97
+
98
+ connectedCallback() {}
99
+
100
+ }
101
+
102
+ export { BoilerPlateItemTypePrint as default };
103
+ //# sourceMappingURL=print.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"print.js","sources":["../../../node_modules/@babel/runtime/helpers/esm/defineProperty.js","../src/main.jsx","../src/print.js"],"sourcesContent":["export default function _defineProperty(obj, key, value) {\n if (key in obj) {\n Object.defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n } else {\n obj[key] = value;\n }\n\n return obj;\n}","import React from 'react';\nimport PropTypes from 'prop-types';\nimport { PreviewPrompt, UiLayout } from '@pie-lib/render-ui';\n\nexport default class Main extends React.Component {\n static propTypes = {\n model: PropTypes.object,\n session: PropTypes.object,\n onSessionChange: PropTypes.func.isRequired,\n };\n\n static defaultProps = {};\n\n render() {\n const { model } = this.props;\n const { extraCSSRules } = model;\n\n return (\n <UiLayout extraCSSRules={extraCSSRules}>\n {model.prompt && (\n <div>\n <p>Boilerplate Item</p>\n <PreviewPrompt prompt={model.prompt} />\n </div>\n )}\n </UiLayout>\n );\n }\n}\n","import React from 'react';\nimport ReactDOM from 'react-dom';\nimport debounce from 'lodash/debounce';\nimport Main from './main';\nimport { renderMath } from '@pie-lib/math-rendering';\nimport debug from 'debug';\n\nconst log = debug('pie-element:multiple-choice:print');\n\n/**\n * Live in same package as main element - so we can access some of the shared comps!\n *\n * - update pslb to build print if src/print.js is there\n * - update demo el\n * - get configure/controller building\n */\n\nconst preparePrintModel = (model, opts) => {\n return model;\n};\n\nexport default class BoilerPlateItemTypePrint extends HTMLElement {\n constructor() {\n super();\n this._options = null;\n this._model = null;\n this._session = [];\n this._rerender = debounce(\n () => {\n if (this._model && this._session) {\n const printModel = preparePrintModel(this._model, this._options);\n\n const element =\n this._options &&\n React.createElement(Main, {\n model: printModel,\n session: {},\n });\n\n ReactDOM.render(element, this, () => {\n log('render complete - render math');\n renderMath(this);\n });\n } else {\n log('skip');\n }\n },\n 50,\n { leading: false, trailing: true },\n );\n }\n set options(o) {\n this._options = o;\n }\n\n set model(s) {\n this._model = s;\n this._rerender();\n }\n\n connectedCallback() {}\n}\n"],"names":["Main","React","Component","render","model","props","extraCSSRules","prompt","PropTypes","object","session","onSessionChange","func","isRequired","log","debug","preparePrintModel","opts","BoilerPlateItemTypePrint","HTMLElement","constructor","_options","_model","_session","_rerender","debounce","printModel","element","createElement","ReactDOM","renderMath","leading","trailing","options","o","s","connectedCallback"],"mappings":";;;;;;;;AAAe,SAAS,eAAe,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE;AACzD,EAAE,IAAI,GAAG,IAAI,GAAG,EAAE;AAClB,IAAI,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,GAA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AAEQ,EAAL9B,IAAAA,KAAK,CAAC+B,CAAD,EAAI;AACX,IAAKb,IAAAA,CAAAA,MAAL,GAAca,CAAd,CAAA;;AACA,IAAA,IAAA,CAAKX,SAAL,EAAA,CAAA;AACD,GAAA;;AAEDY,EAAAA,iBAAiB,GAAG,EAAE;;AAvC0C;;;;"}
@@ -0,0 +1 @@
1
+ import{_dll_react as e,_dll_prop_types as t,_dll_material_ui__core_styles as n,_dll_lodash as i,_dll_react_dom as s}from"../../../@pie-lib/shared-module@^1.14.0/module/index.js";import{_dll_pie_lib__config_ui as o}from"../../../@pie-lib/config-module@^2.19.0/module/index.js";import{_dll_pie_lib__editable_html as a}from"../../../@pie-lib/editable-html-module@^5.6.0/module/index.js";const d=e,r=t,{withStyles:l}=n,{cloneDeep:u}=i,{InputContainer:p}=o,{settings:c}=o,{layout:h}=o,m=a,{Panel:g,toggle:_}=c;class b extends d.Component{constructor(...e){super(...e),b.prototype.__init.call(this)}static __initStatic(){this.propTypes={model:r.object.isRequired,configuration:r.object.isRequired,classes:r.object.isRequired,onModelChanged:r.func.isRequired,onConfigurationChanged:r.func.isRequired,imageSupport:r.shape({add:r.func.isRequired,delete:r.func.isRequired}),uploadSoundSupport:r.object}}static __initStatic2(){this.defaultProps={}}__init(){this.onPromptChanged=e=>{const{onModelChanged:t,model:n}=this.props,i=u(n);i.prompt=e,t(i)}}render(){const{classes:e,configuration:t,imageSupport:n,model:i,onConfigurationChanged:s,onModelChanged:o,uploadSoundSupport:a}=this.props,{contentDimensions:r={},prompt:l={},settingsPanelDisabled:u}=t||{},{extraCSSRules:c,promptEnabled:b}=i||{},C={promptEnabled:l.settings&&_(l.label)};return d.createElement(h.ConfigLayout,{extraCSSRules:c,dimensions:r,hideSettings:u,settings:d.createElement(g,{model:i,configuration:t,onChangeModel:e=>o(e),onChangeConfiguration:s,groups:{Settings:{},Properties:C}})},b&&d.createElement(p,{label:l.label||"",className:e.promptHolder},d.createElement(m,{className:e.prompt,markup:i.prompt,onChange:this.onPromptChanged,imageSupport:n,uploadSoundSupport:a,languageCharactersProps:[{language:"spanish"},{language:"special"}]})))}}b.__initStatic(),b.__initStatic2();var C=l((e=>({promptHolder:{width:"100%",paddingTop:2*e.spacing.unit,marginBottom:2*e.spacing.unit}})))(b),E={};Object.defineProperty(E,"__esModule",{value:!0});class f extends CustomEvent{constructor(e,t=!1){super(f.TYPE,{bubbles:!0,detail:{update:e,reset:t}}),this.update=e,this.reset=t}}f.TYPE="model.updated";var S=E.ModelUpdatedEvent=f;class v extends CustomEvent{constructor(e,t){super(v.TYPE,{bubbles:!0,detail:{src:e,done:t}}),this.src=e,this.done=t}}v.TYPE="delete.image";var P=E.DeleteImageEvent=v;class x extends CustomEvent{constructor(e){super(x.TYPE,{bubbles:!0,detail:e}),this.handler=e}}x.TYPE="insert.image";var T=E.InsertImageEvent=x;class D extends CustomEvent{constructor(e,t){super(D.TYPE,{bubbles:!0,detail:{src:e,done:t}}),this.src=e,this.done=t}}D.TYPE="delete.sound";var M=E.DeleteSoundEvent=D;class Y extends CustomEvent{constructor(e){super(Y.TYPE,{bubbles:!0,detail:e}),this.handler=e}}Y.TYPE="insert.sound";var I=E.InsertSoundEvent=Y,R={prompt:"",promptEnabled:!0},j={prompt:{label:"Prompt",settings:!0}};const y=e,q=s;class w extends HTMLElement{static __initStatic(){this.createDefaultModel=(e={})=>({...R,...e})}constructor(){super(),this._model=w.createDefaultModel(),this._configuration=j}set model(e){this._model=w.createDefaultModel(e),this.render()}set configuration(e){this._configuration=e,this.render()}connectedCallback(){this.render()}modelChanged(e){this._model=e,this.dispatchEvent(new S(this._model),!0),this.render()}onConfigurationChanged(e){this._configuration=e,this.render()}insertImage(e){this.dispatchEvent(new T(e))}onDeleteImage(e,t){this.dispatchEvent(new P(e,t))}insertSound(e){this.dispatchEvent(new I(e))}onDeleteSound(e,t){this.dispatchEvent(new M(e,t))}render(){if(this._model){const e=y.createElement(C,{model:this._model,configuration:this._configuration,onModelChanged:this.modelChanged.bind(this),onConfigurationChanged:this.onConfigurationChanged.bind(this),imageSupport:{add:this.insertImage.bind(this),delete:this.onDeleteImage.bind(this)},uploadSoundSupport:{add:this.insertSound.bind(this),delete:this.onDeleteSound.bind(this)}});q.render(e,this)}}}w.__initStatic();export{w as default};