diff --git a/assets/javascripts/wizard-custom.js b/assets/javascripts/wizard-custom.js index 667d23fd..1e487273 100644 --- a/assets/javascripts/wizard-custom.js +++ b/assets/javascripts/wizard-custom.js @@ -1,8 +1,6 @@ //= require_tree_discourse truth-helpers/addon //= require_tree_discourse discourse-common/addon //= require_tree_discourse select-kit/addon -//= require_tree_discourse wizard/lib -//= require_tree_discourse wizard/mixins //= require_tree_discourse discourse/app/lib //= require_tree_discourse discourse/app/mixins @@ -76,6 +74,7 @@ //= require_tree ./wizard/controllers //= require_tree ./wizard/helpers //= require_tree ./wizard/lib +//= require_tree ./wizard/mixins //= require_tree ./wizard/models //= require_tree ./wizard/routes //= require_tree ./wizard/templates diff --git a/assets/javascripts/wizard-shims.js b/assets/javascripts/wizard-shims.js new file mode 100644 index 00000000..b5063933 --- /dev/null +++ b/assets/javascripts/wizard-shims.js @@ -0,0 +1,47 @@ +define("@popperjs/core", ["exports"], function (__exports__) { + __exports__.default = window.Popper; + __exports__.createPopper = window.Popper.createPopper; + __exports__.defaultModifiers = window.Popper.defaultModifiers; + __exports__.popperGenerator = window.Popper.popperGenerator; +}); + +define("tippy.js", ["exports"], function (__exports__) { + __exports__.default = window.tippy; +}); + +define("@uppy/core", ["exports"], function (__exports__) { + __exports__.default = window.Uppy.Core; + __exports__.BasePlugin = window.Uppy.Core.BasePlugin; +}); + +define("@uppy/aws-s3", ["exports"], function (__exports__) { + __exports__.default = window.Uppy.AwsS3; +}); + +define("@uppy/aws-s3-multipart", ["exports"], function (__exports__) { + __exports__.default = window.Uppy.AwsS3Multipart; +}); + +define("@uppy/xhr-upload", ["exports"], function (__exports__) { + __exports__.default = window.Uppy.XHRUpload; +}); + +define("@uppy/drop-target", ["exports"], function (__exports__) { + __exports__.default = window.Uppy.DropTarget; +}); + +define("@uppy/utils/lib/delay", ["exports"], function (__exports__) { + __exports__.default = window.Uppy.Utils.delay; +}); + +define("@uppy/utils/lib/EventTracker", ["exports"], function (__exports__) { + __exports__.default = window.Uppy.Utils.EventTracker; +}); + +define("@uppy/utils/lib/AbortController", ["exports"], function (__exports__) { + __exports__.AbortController = + window.Uppy.Utils.AbortControllerLib.AbortController; + __exports__.AbortSignal = window.Uppy.Utils.AbortControllerLib.AbortSignal; + __exports__.createAbortError = + window.Uppy.Utils.AbortControllerLib.createAbortError; +}); diff --git a/assets/javascripts/wizard-vendor.js b/assets/javascripts/wizard-vendor.js new file mode 100644 index 00000000..5d175a6b --- /dev/null +++ b/assets/javascripts/wizard-vendor.js @@ -0,0 +1,10 @@ +//= require ember_jquery +//= require template_include.js +//= require uppy.js +//= require bootstrap-modal.js +//= require bootbox.js +//= require virtual-dom +//= require virtual-dom-amd +//= require popper.js +//= require tippy.umd.js +//= require wizard-shims diff --git a/assets/javascripts/wizard/components/validator.js.es6 b/assets/javascripts/wizard/components/validator.js.es6 index aa68660c..2e8498ef 100644 --- a/assets/javascripts/wizard/components/validator.js.es6 +++ b/assets/javascripts/wizard/components/validator.js.es6 @@ -1,7 +1,7 @@ import Component from "@ember/component"; import { equal } from "@ember/object/computed"; import { ajax } from "discourse/lib/ajax"; -import { getToken } from "wizard/lib/ajax"; +import { getToken } from "../lib/ajax"; export default Component.extend({ classNames: ["validator"], diff --git a/assets/javascripts/wizard/lib/ajax.js.es6 b/assets/javascripts/wizard/lib/ajax.js.es6 new file mode 100644 index 00000000..3889069f --- /dev/null +++ b/assets/javascripts/wizard/lib/ajax.js.es6 @@ -0,0 +1,33 @@ +import { Promise } from "rsvp"; +import getUrl from "discourse-common/lib/get-url"; +import jQuery from "jquery"; +import { run } from "@ember/runloop"; + +let token; + +export function getToken() { + if (!token) { + token = document.querySelector('meta[name="csrf-token"]')?.content; + } + + return token; +} + +export function ajax(args) { + let url; + + if (arguments.length === 2) { + url = arguments[0]; + args = arguments[1]; + } else { + url = args.url; + } + + return new Promise((resolve, reject) => { + args.headers = { "X-CSRF-Token": getToken() }; + args.success = (data) => run(null, resolve, data); + args.error = (xhr) => run(null, reject, xhr); + args.url = getUrl(url); + jQuery.ajax(args); + }); +} diff --git a/assets/javascripts/wizard/lib/initialize/patch-components.js.es6 b/assets/javascripts/wizard/lib/initialize/patch-components.js.es6 index 9d13160e..8cb5e4b3 100644 --- a/assets/javascripts/wizard/lib/initialize/patch-components.js.es6 +++ b/assets/javascripts/wizard/lib/initialize/patch-components.js.es6 @@ -1,6 +1,8 @@ export default { run(app, container) { - const getToken = requirejs("wizard/lib/ajax").getToken; + const getToken = requirejs( + "discourse/plugins/discourse-custom-wizard/wizard/lib/ajax" + ).getToken; const isTesting = requirejs("discourse-common/config/environment") .isTesting; diff --git a/assets/javascripts/wizard/lib/load-script.js.es6 b/assets/javascripts/wizard/lib/load-script.js.es6 index d0b07c26..aeabdf06 100644 --- a/assets/javascripts/wizard/lib/load-script.js.es6 +++ b/assets/javascripts/wizard/lib/load-script.js.es6 @@ -1,4 +1,4 @@ -import { ajax } from "wizard/lib/ajax"; +import { ajax } from "./ajax"; import getURL, { getURLWithCDN } from "discourse-common/lib/get-url"; import { run } from "@ember/runloop"; import { Promise } from "rsvp"; diff --git a/assets/javascripts/wizard/mixins/valid-state.js.es6 b/assets/javascripts/wizard/mixins/valid-state.js.es6 new file mode 100644 index 00000000..ca86d7e4 --- /dev/null +++ b/assets/javascripts/wizard/mixins/valid-state.js.es6 @@ -0,0 +1,36 @@ +import discourseComputed from "discourse-common/utils/decorators"; + +export const States = { + UNCHECKED: 0, + INVALID: 1, + VALID: 2, +}; + +export default { + _validState: null, + errorDescription: null, + + init() { + this._super(...arguments); + this.set("_validState", States.UNCHECKED); + }, + + @discourseComputed("_validState") + valid: (state) => state === States.VALID, + + @discourseComputed("_validState") + invalid: (state) => state === States.INVALID, + + @discourseComputed("_validState") + unchecked: (state) => state === States.UNCHECKED, + + setValid(valid, description) { + this.set("_validState", valid ? States.VALID : States.INVALID); + + if (!valid && description && description.length) { + this.set("errorDescription", description); + } else { + this.set("errorDescription", null); + } + }, +}; diff --git a/assets/javascripts/wizard/models/field.js.es6 b/assets/javascripts/wizard/models/field.js.es6 index 2b88140e..9d0be1ff 100644 --- a/assets/javascripts/wizard/models/field.js.es6 +++ b/assets/javascripts/wizard/models/field.js.es6 @@ -1,5 +1,5 @@ import EmberObject from "@ember/object"; -import ValidState from "wizard/mixins/valid-state"; +import ValidState from "discourse/plugins/discourse-custom-wizard/wizard/mixins/valid-state"; import discourseComputed from "discourse-common/utils/decorators"; import { translatedText } from "discourse/plugins/discourse-custom-wizard/wizard/lib/wizard-i18n"; diff --git a/assets/javascripts/wizard/models/step.js.es6 b/assets/javascripts/wizard/models/step.js.es6 index 36503276..87f2d4b6 100644 --- a/assets/javascripts/wizard/models/step.js.es6 +++ b/assets/javascripts/wizard/models/step.js.es6 @@ -1,6 +1,6 @@ import EmberObject from "@ember/object"; -import ValidState from "wizard/mixins/valid-state"; -import { ajax } from "wizard/lib/ajax"; +import ValidState from "discourse/plugins/discourse-custom-wizard/wizard/mixins/valid-state"; +import { ajax } from "../lib/ajax"; import discourseComputed from "discourse-common/utils/decorators"; import { translatedText } from "discourse/plugins/discourse-custom-wizard/wizard/lib/wizard-i18n"; import { later } from "@ember/runloop"; diff --git a/assets/javascripts/wizard/models/wizard.js.es6 b/assets/javascripts/wizard/models/wizard.js.es6 index 15bcbb8c..d742c244 100644 --- a/assets/javascripts/wizard/models/wizard.js.es6 +++ b/assets/javascripts/wizard/models/wizard.js.es6 @@ -1,7 +1,7 @@ import { default as computed } from "discourse-common/utils/decorators"; import getUrl from "discourse-common/lib/get-url"; import Field from "./field"; -import { ajax } from "wizard/lib/ajax"; +import { ajax } from "../lib/ajax"; import { popupAjaxError } from "discourse/lib/ajax-error"; import Step from "./step"; import EmberObject from "@ember/object"; diff --git a/plugin.rb b/plugin.rb index bdb86b64..a0e6dd7b 100644 --- a/plugin.rb +++ b/plugin.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true # name: discourse-custom-wizard # about: Create custom wizards -# version: 1.19.0 +# version: 1.20.0 # authors: Angus McLeod # url: https://github.com/paviliondev/discourse-custom-wizard # contact emails: angus@thepavilion.io