app/assets/build/coco/book.js in coveragebook_components-0.10.0 vs app/assets/build/coco/book.js in coveragebook_components-0.10.1.beta.0

- old
+ new

@@ -14777,10 +14777,173 @@ if (state.elements.arrow) { Object.assign(state.elements.arrow.style, initialStyles.arrow); } } }); + var createSingleton = function createSingleton2(tippyInstances, optionalProps) { + var _optionalProps$popper; + if (optionalProps === void 0) { + optionalProps = {}; + } + if (true) { + errorWhen(!Array.isArray(tippyInstances), ["The first argument passed to createSingleton() must be an array of", "tippy instances. The passed value was", String(tippyInstances)].join(" ")); + } + var individualInstances = tippyInstances; + var references = []; + var triggerTargets = []; + var currentTarget; + var overrides = optionalProps.overrides; + var interceptSetPropsCleanups = []; + var shownOnCreate = false; + function setTriggerTargets() { + triggerTargets = individualInstances.map(function(instance) { + return normalizeToArray(instance.props.triggerTarget || instance.reference); + }).reduce(function(acc, item) { + return acc.concat(item); + }, []); + } + function setReferences() { + references = individualInstances.map(function(instance) { + return instance.reference; + }); + } + function enableInstances(isEnabled) { + individualInstances.forEach(function(instance) { + if (isEnabled) { + instance.enable(); + } else { + instance.disable(); + } + }); + } + function interceptSetProps(singleton2) { + return individualInstances.map(function(instance) { + var originalSetProps2 = instance.setProps; + instance.setProps = function(props) { + originalSetProps2(props); + if (instance.reference === currentTarget) { + singleton2.setProps(props); + } + }; + return function() { + instance.setProps = originalSetProps2; + }; + }); + } + function prepareInstance(singleton2, target) { + var index = triggerTargets.indexOf(target); + if (target === currentTarget) { + return; + } + currentTarget = target; + var overrideProps = (overrides || []).concat("content").reduce(function(acc, prop) { + acc[prop] = individualInstances[index].props[prop]; + return acc; + }, {}); + singleton2.setProps(Object.assign({}, overrideProps, { + getReferenceClientRect: typeof overrideProps.getReferenceClientRect === "function" ? overrideProps.getReferenceClientRect : function() { + var _references$index; + return (_references$index = references[index]) == null ? void 0 : _references$index.getBoundingClientRect(); + } + })); + } + enableInstances(false); + setReferences(); + setTriggerTargets(); + var plugin2 = { + fn: function fn3() { + return { + onDestroy: function onDestroy2() { + enableInstances(true); + }, + onHidden: function onHidden2() { + currentTarget = null; + }, + onClickOutside: function onClickOutside2(instance) { + if (instance.props.showOnCreate && !shownOnCreate) { + shownOnCreate = true; + currentTarget = null; + } + }, + onShow: function onShow2(instance) { + if (instance.props.showOnCreate && !shownOnCreate) { + shownOnCreate = true; + prepareInstance(instance, references[0]); + } + }, + onTrigger: function onTrigger2(instance, event) { + prepareInstance(instance, event.currentTarget); + } + }; + } + }; + var singleton = tippy(div(), Object.assign({}, removeProperties(optionalProps, ["overrides"]), { + plugins: [plugin2].concat(optionalProps.plugins || []), + triggerTarget: triggerTargets, + popperOptions: Object.assign({}, optionalProps.popperOptions, { + modifiers: [].concat(((_optionalProps$popper = optionalProps.popperOptions) == null ? void 0 : _optionalProps$popper.modifiers) || [], [applyStylesModifier]) + }) + })); + var originalShow = singleton.show; + singleton.show = function(target) { + originalShow(); + if (!currentTarget && target == null) { + return prepareInstance(singleton, references[0]); + } + if (currentTarget && target == null) { + return; + } + if (typeof target === "number") { + return references[target] && prepareInstance(singleton, references[target]); + } + if (individualInstances.indexOf(target) >= 0) { + var ref = target.reference; + return prepareInstance(singleton, ref); + } + if (references.indexOf(target) >= 0) { + return prepareInstance(singleton, target); + } + }; + singleton.showNext = function() { + var first = references[0]; + if (!currentTarget) { + return singleton.show(0); + } + var index = references.indexOf(currentTarget); + singleton.show(references[index + 1] || first); + }; + singleton.showPrevious = function() { + var last = references[references.length - 1]; + if (!currentTarget) { + return singleton.show(last); + } + var index = references.indexOf(currentTarget); + var target = references[index - 1] || last; + singleton.show(target); + }; + var originalSetProps = singleton.setProps; + singleton.setProps = function(props) { + overrides = props.overrides || overrides; + originalSetProps(props); + }; + singleton.setInstances = function(nextInstances) { + enableInstances(true); + interceptSetPropsCleanups.forEach(function(fn3) { + return fn3(); + }); + individualInstances = nextInstances; + enableInstances(false); + setReferences(); + setTriggerTargets(); + interceptSetPropsCleanups = interceptSetProps(singleton); + singleton.setProps({ + triggerTarget: triggerTargets + }); + }; + interceptSetPropsCleanups = interceptSetProps(singleton); + return singleton; + }; var mouseCoords = { clientX: 0, clientY: 0 }; var activeInstances = []; @@ -15248,17 +15411,17 @@ module_default.plugin(dropdown_default); module_default.plugin(dimensions_default); module_default.plugin(notification_default); var alpine_default2 = module_default; - // ../../components/coco/base/button/button.js + // ../../components/coco/shared/button/button.js var button_exports = {}; __export(button_exports, { default: () => button_default }); - // coco.js + // shared/coco.js function CocoComponent(name, fn3) { const func = nameFunction(name, (...args) => { const data2 = fn3(...args); Object.defineProperties(data2, { $parent: { @@ -15272,11 +15435,11 @@ }); func.component = true; return func; } - // ../../components/coco/base/button/button.js + // ../../components/coco/shared/button/button.js var import_lodash2 = __toESM(require_lodash(), 1); var button_default = CocoComponent("button", (data2 = {}) => { return __spreadProps(__spreadValues({ options: ["state", "confirm", "size", "disabled", "collapsible"], isCollapsed: false, @@ -15406,21 +15569,22 @@ }, /* bindings */ root: { "x-options": "options", "x-tooltip": "tooltipText", - "x-effect": "setTooltipText" + "x-effect": "setTooltipText", + ":disabled": "disabled" } }); }); - // ../../components/coco/base/button/button_dropdown.js + // ../../components/coco/shared/button/button_dropdown.js var button_dropdown_exports = {}; __export(button_dropdown_exports, { default: () => button_dropdown_default }); - var button_dropdown_default = CocoComponent("buttonDropdown", (data2 = {}) => { + var button_dropdown_default = CocoComponent("buttonDropdown", () => { return { dropdown: null, button: null, init() { this.$nextTick(() => { @@ -15434,24 +15598,121 @@ }, showDropdown() { if (this.dropdown) { this.dropdown.show(); } + }, + /* bindings */ + root: { + "@dropdown:show": "button.setState('active')", + "@dropdown:hide": "button.resetState()", + "@confirmation:confirm": "button.approveAndRun($event)", + "@confirmation:cancel": "button.cancelConfirmation($event)" } }; }); - // ../../components/coco/base/dropdown/dropdown.js + // ../../components/coco/shared/button_group/button_group.js + var button_group_exports = {}; + __export(button_group_exports, { + default: () => button_group_default + }); + var button_group_default = CocoComponent("appButtonGroup", () => { + return { + options: ["collapsible"], + ready: false, + containerWidth: 0, + contentWidth: 0, + collapsed: false, + singletonTooltip: null, + tooltipInstances: [], + get collapsible() { + return this.$options.collapsible !== false; + }, + get buttons() { + const buttonElements = this.$el.querySelectorAll( + "[data-component='button']" + ); + return Array.from(buttonElements).map((el) => getComponent(el)); + }, + get parent() { + return this.$root.parentElement; + }, + init() { + if (this.collapsible) { + this.$nextTick(() => { + this.onResize(); + this.createSingletonTooltip(); + this.ready = true; + }); + } else { + this.ready = true; + } + this.$watch("collapsed", (value) => { + this.buttons.forEach((button) => { + button.isCollapsed = value; + }); + this.$nextTick(() => this.createSingletonTooltip()); + }); + }, + createSingletonTooltip() { + this.destroySingletonTooltip(); + this.tooltipInstances = this.buttons.map((button) => { + if (button.tippyInstance && button.shouldShowTooltip && button.shouldShowTooltip()) { + return button.tippyInstance; + } + }).filter((t2) => t2); + this.singletonTooltip = createSingleton(this.tooltipInstances, { + theme: "coco-tooltip", + delay: 100, + moveTransition: "transform 0.1s ease-out" + }); + }, + destroySingletonTooltip() { + if (this.singletonTooltip && this.singletonTooltip.destroy) { + this.singletonTooltip.destroy(); + this.singletonTooltip = null; + this.tooltipInstances.forEach((tooltip) => tooltip.destroy()); + this.tooltipInstances = []; + } + }, + onResize() { + if (!this.collapsible) + return; + this.containerWidth = Math.ceil(this.parent.offsetWidth); + if (this.collapsed) { + if (this.containerWidth > this.contentWidth) { + this.collapsed = false; + } + } else { + if (this.containerWidth < this.contentWidth) { + this.collapsed = true; + } else { + const contentWidth = Math.ceil(this.$refs.buttons.scrollWidth); + this.contentWidth = contentWidth; + } + } + }, + destroy() { + if (this.singletonTooltip) { + this.singletonTooltip.destroy(); + this.singletonTooltip = null; + } + } + }; + }); + + // ../../components/coco/shared/dropdown/dropdown.js var dropdown_exports = {}; __export(dropdown_exports, { default: () => dropdown_default2 }); var dropdown_default2 = CocoComponent("dropdown", () => { return {}; }); - // ../../components/coco/base/icon/icon.js + // ../../components/coco/shared/icon/icon.js var icon_exports = {}; __export(icon_exports, { default: () => icon_default }); var icon_default = CocoComponent("icon", () => { @@ -15473,11 +15734,11 @@ "x-options": "options" } }; }); - // ../../components/coco/base/image_uploader/image_uploader.js + // ../../components/coco/shared/image_uploader/image_uploader.js var image_uploader_exports = {}; __export(image_uploader_exports, { default: () => image_uploader_default }); var image_uploader_default = CocoComponent("imageUploader", ({ click, drop }) => { @@ -15546,11 +15807,11 @@ reader.readAsDataURL(file); } }; }); - // ../../components/coco/base/modal/modal.js + // ../../components/coco/shared/modal/modal.js var modal_exports = {}; __export(modal_exports, { default: () => modal_default }); @@ -15563,11 +15824,11 @@ } else { location.assign(url); } } - // ../../components/coco/base/modal/modal.js + // ../../components/coco/shared/modal/modal.js var modal_default = CocoComponent("modal", () => { return { open: false, frame: null, modal: null, @@ -15649,11 +15910,11 @@ "x-transition:leave-end": "container-leave-end" } }; }); - // ../../components/coco/base/modal_dialog/modal_dialog.js + // ../../components/coco/shared/modal_dialog/modal_dialog.js var modal_dialog_exports = {}; __export(modal_dialog_exports, { default: () => modal_dialog_default }); var modal_dialog_default = CocoComponent("modalDialog", () => { @@ -15683,11 +15944,11 @@ ); } }; }); - // ../../components/coco/base/modal_lightbox/modal_lightbox.js + // ../../components/coco/shared/modal_lightbox/modal_lightbox.js var modal_lightbox_exports = {}; __export(modal_lightbox_exports, { default: () => modal_lightbox_default }); var modal_lightbox_default = CocoComponent("modalLightbox", () => { @@ -15717,11 +15978,11 @@ ":class": "{loaded}" } }; }); - // ../../components/coco/base/poll_controller/poll_controller.js + // ../../components/coco/shared/poll_controller/poll_controller.js var poll_controller_exports = {}; __export(poll_controller_exports, { default: () => poll_controller_default }); var poll_controller_default = CocoComponent("pollController", () => { @@ -15781,14 +16042,14 @@ if (headers) { headers.Accept = ["text/vnd.turbo-stream.html", headers.Accept].join(", "); } } - // import-glob:/Users/mark/Code/coveragebook/coco/app/assets/js/base|@baseComponents/**/*.js - var modules = [button_exports, button_dropdown_exports, dropdown_exports, icon_exports, image_uploader_exports, modal_exports, modal_dialog_exports, modal_lightbox_exports, poll_controller_exports]; + // import-glob:/Users/mark/Code/coveragebook/coco/app/assets/js/shared|@sharedComponents/**/*.js + var modules = [button_exports, button_dropdown_exports, button_group_exports, dropdown_exports, icon_exports, image_uploader_exports, modal_exports, modal_dialog_exports, modal_lightbox_exports, poll_controller_exports]; var __default = modules; - // base/components.js + // shared/components.js var components_default = registerComponents(__default); // import-glob:/Users/mark/Code/coveragebook/coco/app/assets/js/book|@bookComponents/**/*.js var modules2 = []; var __default2 = modules2;